|
| 1 | +name: Docker Build Images |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Once every Wednesday at 00:00 |
| 6 | + - cron: '0 0 * * 3' |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + paths: |
| 11 | + - 'docker/**' |
| 12 | + - '.github/workflows/vcpkg_docker_amd64.yml' |
| 13 | + pull_request: |
| 14 | + paths: |
| 15 | + - 'docker/**' |
| 16 | + - '.github/workflows/vcpkg_docker_amd64.yml' |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +env: |
| 23 | + # Also remember to change the 'docker/build.sh' script |
| 24 | + REGISTRY_IMAGE: "ghcr.io/lifting-bits/cxx-common/vcpkg-builder-ubuntu-22.04-v2" |
| 25 | + |
| 26 | +jobs: |
| 27 | + build: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + strategy: |
| 30 | + fail-fast: false |
| 31 | + matrix: |
| 32 | + container: |
| 33 | + - { version: '22.04', codename: 'jammy' } |
| 34 | + platform: |
| 35 | + - linux/amd64 |
| 36 | + - linux/arm64 |
| 37 | + steps: |
| 38 | + - name: Prepare |
| 39 | + run: | |
| 40 | + platform=${{ matrix.platform }} |
| 41 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 42 | +
|
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Set up QEMU |
| 47 | + uses: docker/setup-qemu-action@v3 |
| 48 | + |
| 49 | + - name: Set up Docker Buildx |
| 50 | + uses: docker/setup-buildx-action@v3 |
| 51 | + |
| 52 | + - name: Log in to GitHub registry |
| 53 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
| 54 | + |
| 55 | + - name: Generate Image Name |
| 56 | + env: |
| 57 | + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} |
| 58 | + run: | |
| 59 | + test_name="" |
| 60 | + if [[ "${GITHUB_REF}" != "refs/heads/master" ]] ; then |
| 61 | + test_name="test-${BRANCH_NAME////_}-" |
| 62 | + fi |
| 63 | + echo "REGISTRY_IMAGE=" >> ${GITHUB_ENV} |
| 64 | +
|
| 65 | + - name: Docker meta |
| 66 | + id: meta |
| 67 | + uses: docker/metadata-action@v5 |
| 68 | + with: |
| 69 | + images: ${{ env.REGISTERY_IMAGE }} |
| 70 | + |
| 71 | + - name: Build and push by digest |
| 72 | + id: build |
| 73 | + uses: docker/build-push-action@v5 |
| 74 | + with: |
| 75 | + context: . |
| 76 | + platforms: ${{ matrix.platform }} |
| 77 | + labels: ${{ steps.meta.outputs.labels }} |
| 78 | + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 79 | + - |
| 80 | + name: Export digest |
| 81 | + run: | |
| 82 | + mkdir -p /tmp/digests |
| 83 | + digest="${{ steps.build.outputs.digest }}" |
| 84 | + touch "/tmp/digests/${digest#sha256:}" |
| 85 | + - |
| 86 | + name: Upload digest |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 90 | + path: /tmp/digests/* |
| 91 | + if-no-files-found: error |
| 92 | + retention-days: 1 |
| 93 | + |
| 94 | + merge: |
| 95 | + runs-on: ubuntu-latest |
| 96 | + needs: |
| 97 | + - build |
| 98 | + steps: |
| 99 | + - name: Download digests |
| 100 | + uses: actions/download-artifact@v4 |
| 101 | + with: |
| 102 | + path: /tmp/digests |
| 103 | + pattern: digests-* |
| 104 | + merge-multiple: true |
| 105 | + |
| 106 | + - name: Set up Docker Buildx |
| 107 | + uses: docker/setup-buildx-action@v3 |
| 108 | + |
| 109 | + - name: Docker meta |
| 110 | + id: meta |
| 111 | + uses: docker/metadata-action@v5 |
| 112 | + with: |
| 113 | + images: ${{ env.REGISTRY_IMAGE }} |
| 114 | + |
| 115 | + - name: Log in to registry |
| 116 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
| 117 | + |
| 118 | + - name: Create manifest list and push |
| 119 | + working-directory: /tmp/digests |
| 120 | + run: | |
| 121 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 122 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 123 | +
|
| 124 | + - name: Inspect image |
| 125 | + run: | |
| 126 | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
0 commit comments