mirror of
				https://github.com/TheLartians/ModernCppStarter.git
				synced 2025-10-31 02:01:33 +01:00 
			
		
		
		
	add docker ci/cd
This commit is contained in:
		
							parent
							
								
									11319c5e0b
								
							
						
					
					
						commit
						4b6cac32a6
					
				
					 4 changed files with 158 additions and 2 deletions
				
			
		
							
								
								
									
										94
									
								
								.github/workflows/docker-cd.yml
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								.github/workflows/docker-cd.yml
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,94 @@ | ||||||
|  | name: run Docker CD | ||||||
|  | 
 | ||||||
|  | on: | ||||||
|  |   push: | ||||||
|  |     tags: | ||||||
|  |       - "v*.*.*" | ||||||
|  |   workflow_dispatch: | ||||||
|  |     inputs: | ||||||
|  |       tag: | ||||||
|  |         description: "Test scenario tag" | ||||||
|  |         required: true | ||||||
|  |         default: "test" | ||||||
|  |       set-latest-tag: | ||||||
|  |         description: "Also set the 'latest' tag with this run? (y/n)" | ||||||
|  |         required: true | ||||||
|  |         default: "n" | ||||||
|  | 
 | ||||||
|  | env: | ||||||
|  |   CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules | ||||||
|  | 
 | ||||||
|  | jobs: | ||||||
|  |   build: | ||||||
|  |     name: CD build docker and push to DockerHub | ||||||
|  |     runs-on: ubuntu-latest | ||||||
|  | 
 | ||||||
|  |     steps: | ||||||
|  |       - uses: actions/checkout@v2 | ||||||
|  | 
 | ||||||
|  |       - name: handle manual workflow start and prepare docker image tag(s) | ||||||
|  |         id: docker-tags | ||||||
|  |         shell: bash | ||||||
|  |         run: | | ||||||
|  |           if [[ "x${{ github.event.inputs.tag }}" != "x" ]]; then | ||||||
|  |             echo "Workflow started via workflow_dispatch! Parameters: tag=${{ github.event.inputs.tag }}, set-latest-tag=${{ github.event.inputs.set-latest-tag }}" | ||||||
|  |             tag="${{ github.event.inputs.tag }}" | ||||||
|  |           else | ||||||
|  |             echo "Workflow started via push with tag! Complete tag: ${GITHUB_REF:10}" | ||||||
|  |             tag="${GITHUB_REF:11}" | ||||||
|  |           fi | ||||||
|  | 
 | ||||||
|  |           if [[ "x${{ github.event.inputs.set-latest-tag }}" == "xy" || "x${{ github.event.inputs.tag }}" == "x" ]]; then | ||||||
|  |             tags="${{ secrets.DOCKERHUB_USERNAME }}/greeter-webapi:$tag, ${{ secrets.DOCKERHUB_USERNAME }}/greeter-webapi:latest" | ||||||
|  |             echo "Docker image release tags: $tags" | ||||||
|  |           else | ||||||
|  |             tags="${{ secrets.DOCKERHUB_USERNAME }}/greeter-webapi:$tag" | ||||||
|  |             echo "Docker image release tag: $tags" | ||||||
|  |           fi | ||||||
|  | 
 | ||||||
|  |           echo ::set-output name=tags::$tags | ||||||
|  | 
 | ||||||
|  |       # | ||||||
|  |       # configure and build in GitHub CI as smoke test | ||||||
|  | 
 | ||||||
|  |       # speed up configure step by installing boost as system lib, also use Ninja for faster builds | ||||||
|  |       - name: speed up configure and build | ||||||
|  |         shell: bash | ||||||
|  |         run: sudo apt-get update && sudo apt-get install -y libboost-all-dev ninja-build | ||||||
|  | 
 | ||||||
|  |       # use GitHub cache to cache dependencies | ||||||
|  |       - uses: actions/cache@v2 | ||||||
|  |         with: | ||||||
|  |           path: "**/cpm_modules" | ||||||
|  |           key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} | ||||||
|  | 
 | ||||||
|  |       - name: configure | ||||||
|  |         run: cmake -S standalone -B build -G Ninja -D CMAKE_BUILD_TYPE=Release | ||||||
|  | 
 | ||||||
|  |       - name: build | ||||||
|  |         run: cmake --build build | ||||||
|  | 
 | ||||||
|  |       # | ||||||
|  |       # end GitHub CI local build | ||||||
|  | 
 | ||||||
|  |       - name: set up Docker Buildx for multi-platform support | ||||||
|  |         uses: docker/setup-buildx-action@v1 | ||||||
|  | 
 | ||||||
|  |       - name: set up QEMU for multi-platform support | ||||||
|  |         uses: docker/setup-qemu-action@v1 | ||||||
|  | 
 | ||||||
|  |       - name: login to DockerHub | ||||||
|  |         uses: docker/login-action@v1 | ||||||
|  |         with: | ||||||
|  |           username: ${{ secrets.DOCKERHUB_USERNAME }} | ||||||
|  |           password: ${{ secrets.DOCKERHUB_TOKEN }} | ||||||
|  | 
 | ||||||
|  |       - name: build Docker image and push to DockerHub | ||||||
|  |         uses: docker/build-push-action@v2 | ||||||
|  |         with: | ||||||
|  |           file: ./standalone/Dockerfile | ||||||
|  |           platforms: linux/amd64,linux/arm64 | ||||||
|  |           push: true | ||||||
|  |           tags: ${{ steps.docker-tags.outputs.tags }} | ||||||
|  |           cache-from: type=gha | ||||||
|  |           cache-to: type=gha,mode=max | ||||||
							
								
								
									
										62
									
								
								.github/workflows/docker-ci.yml
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								.github/workflows/docker-ci.yml
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,62 @@ | ||||||
|  | name: run Docker CI | ||||||
|  | 
 | ||||||
|  | on: | ||||||
|  |   push: | ||||||
|  |     branches: | ||||||
|  |       - main | ||||||
|  |       - master | ||||||
|  |   pull_request: | ||||||
|  |     branches: | ||||||
|  |       - main | ||||||
|  |       - master | ||||||
|  | 
 | ||||||
|  | env: | ||||||
|  |   CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules | ||||||
|  | 
 | ||||||
|  | jobs: | ||||||
|  |   build: | ||||||
|  |     name: CI build docker | ||||||
|  |     runs-on: ubuntu-latest | ||||||
|  | 
 | ||||||
|  |     steps: | ||||||
|  |       - uses: actions/checkout@v2 | ||||||
|  | 
 | ||||||
|  |       # | ||||||
|  |       # configure and build in GitHub CI as smoke test | ||||||
|  | 
 | ||||||
|  |       # speed up configure step by installing boost as system lib, also use Ninja for faster builds | ||||||
|  |       - name: speed up configure and build | ||||||
|  |         shell: bash | ||||||
|  |         run: sudo apt-get update && sudo apt-get install -y libboost-all-dev ninja-build | ||||||
|  | 
 | ||||||
|  |       # use GitHub cache to cache dependencies | ||||||
|  |       - uses: actions/cache@v2 | ||||||
|  |         with: | ||||||
|  |           path: "**/cpm_modules" | ||||||
|  |           key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} | ||||||
|  | 
 | ||||||
|  |       - name: configure | ||||||
|  |         run: cmake -S standalone -B build -G Ninja -D CMAKE_BUILD_TYPE=Release | ||||||
|  | 
 | ||||||
|  |       - name: build | ||||||
|  |         run: cmake --build build | ||||||
|  | 
 | ||||||
|  |       # | ||||||
|  |       # end GitHub CI local build | ||||||
|  | 
 | ||||||
|  |       - name: set up Docker Buildx for multi-platform support | ||||||
|  |         uses: docker/setup-buildx-action@v1 | ||||||
|  | 
 | ||||||
|  |       - name: set up QEMU for multi-platform support | ||||||
|  |         uses: docker/setup-qemu-action@v1 | ||||||
|  | 
 | ||||||
|  |       # build image but do NOT push to DockerHub | ||||||
|  |       - name: build Docker image | ||||||
|  |         uses: docker/build-push-action@v2 | ||||||
|  |         with: | ||||||
|  |           file: ./standalone/Dockerfile | ||||||
|  |           platforms: linux/amd64,linux/arm64 | ||||||
|  |           push: false | ||||||
|  |           tags: ${{ secrets.DOCKERHUB_USERNAME }}/webapi:ci | ||||||
|  |           cache-from: type=gha | ||||||
|  |           cache-to: type=gha,mode=max | ||||||
|  | @ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14...3.22) | ||||||
| 
 | 
 | ||||||
| project( | project( | ||||||
|   GreeterStandalone |   GreeterStandalone | ||||||
|   DESCRIPTION "A standalone minimal webserver application using the Crow framework" |   DESCRIPTION "A standalone minimal webapi application using the Crow framework" | ||||||
|   LANGUAGES CXX |   LANGUAGES CXX | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ RUN set -eux; \ | ||||||
|     apt-get install -y --no-install-recommends \ |     apt-get install -y --no-install-recommends \ | ||||||
|     cmake \ |     cmake \ | ||||||
|     ninja-build \ |     ninja-build \ | ||||||
|     # build with Boost as system lib - this should be orders of magnitude faster to configure than |     # configure/build with Boost as system lib - this should be orders of magnitude faster to configure than | ||||||
|     # downloading via CPM.cmake while Boost's CMake support is still experimental |     # downloading via CPM.cmake while Boost's CMake support is still experimental | ||||||
|     libboost-all-dev \ |     libboost-all-dev \ | ||||||
|     ; |     ; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue