|
| 1 | +name: Docker Build Images |
| 2 | + |
| 3 | +# Based on https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners |
| 4 | + |
| 5 | +on: |
| 6 | + schedule: |
| 7 | + # Once every Wednesday at 00:00 |
| 8 | + - cron: '0 0 * * 3' |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - master |
| 12 | + paths: |
| 13 | + - 'docker/**' |
| 14 | + - '.github/workflows/vcpkg_docker.yml' |
| 15 | + pull_request: |
| 16 | + paths: |
| 17 | + - 'docker/**' |
| 18 | + - '.github/workflows/vcpkg_docker.yml' |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +jobs: |
| 25 | + build: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + env: |
| 28 | + # This needs to be the same as in the `merge` job |
| 29 | + # Also remember to change the 'docker/build.sh' script |
| 30 | + REGISTRY_IMAGE: ghcr.io/lifting-bits/cxx-common/vcpkg-builder-ubuntu-v2 |
| 31 | + strategy: |
| 32 | + fail-fast: false |
| 33 | + matrix: |
| 34 | + platform: |
| 35 | + - linux/amd64 |
| 36 | + - linux/arm64 |
| 37 | + ubuntu_version: |
| 38 | + - 22.04 |
| 39 | + - 24.04 |
| 40 | + steps: |
| 41 | + - name: Prepare |
| 42 | + run: | |
| 43 | + platform="${{ matrix.platform }}" |
| 44 | + echo "PLATFORM_PAIR=${platform//\//-}" >> "${GITHUB_ENV}" |
| 45 | +
|
| 46 | + - name: Checkout |
| 47 | + uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Set up QEMU |
| 50 | + uses: docker/setup-qemu-action@v3 |
| 51 | + |
| 52 | + - name: Set up Docker Buildx |
| 53 | + uses: docker/setup-buildx-action@v3 |
| 54 | + |
| 55 | + - name: Login to GHCR |
| 56 | + uses: docker/login-action@v3 |
| 57 | + with: |
| 58 | + registry: ghcr.io |
| 59 | + username: ${{ github.repository_owner }} |
| 60 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + |
| 62 | + # BEGIN Copied to the next job |
| 63 | + - name: Generate Tag |
| 64 | + env: |
| 65 | + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} |
| 66 | + run: | |
| 67 | + test_tag="" |
| 68 | + if [[ "${GITHUB_REF}" != "refs/heads/${{ github.event.repository.default_branch }}" ]] ; then |
| 69 | + test_tag="test-${BRANCH_NAME////_}-" |
| 70 | + fi |
| 71 | + echo "TEST_TAG=${test_tag}" >> "${GITHUB_ENV}" |
| 72 | +
|
| 73 | + - name: Docker meta |
| 74 | + id: meta |
| 75 | + uses: docker/metadata-action@v5 |
| 76 | + with: |
| 77 | + images: ${{ env.REGISTERY_IMAGE }} |
| 78 | + flavor: | |
| 79 | + latest=false |
| 80 | + tags: | |
| 81 | + type=raw,value=${{ env.TEST_TAG }}${{ matrix.ubuntu_version }} |
| 82 | + # END Copied to the next job |
| 83 | + |
| 84 | + - name: Build and push by digest |
| 85 | + id: build |
| 86 | + uses: docker/build-push-action@v5 |
| 87 | + with: |
| 88 | + context: docker |
| 89 | + file: docker/Dockerfile.ubuntu.vcpkg |
| 90 | + platforms: ${{ matrix.platform }} |
| 91 | + labels: ${{ steps.meta.outputs.labels }} |
| 92 | + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 93 | + |
| 94 | + - name: Export digest |
| 95 | + run: | |
| 96 | + mkdir -p /tmp/digests |
| 97 | + digest="${{ steps.build.outputs.digest }}" |
| 98 | + touch "/tmp/digests/${digest#sha256:}" |
| 99 | +
|
| 100 | + - name: Upload digest |
| 101 | + uses: actions/upload-artifact@v4 |
| 102 | + with: |
| 103 | + name: digests-${{ matrix.ubuntu_version }}-${{ env.PLATFORM_PAIR }} |
| 104 | + path: /tmp/digests/* |
| 105 | + if-no-files-found: error |
| 106 | + retention-days: 1 |
| 107 | + |
| 108 | + merge: |
| 109 | + runs-on: ubuntu-latest |
| 110 | + needs: |
| 111 | + - build |
| 112 | + env: |
| 113 | + # This needs to be the same as in the `build` job |
| 114 | + REGISTRY_IMAGE: ghcr.io/lifting-bits/cxx-common/vcpkg-builder-ubuntu-v2 |
| 115 | + strategy: |
| 116 | + fail-fast: false |
| 117 | + matrix: |
| 118 | + ubuntu_version: |
| 119 | + - 22.04 |
| 120 | + - 24.04 |
| 121 | + steps: |
| 122 | + - name: Download digests |
| 123 | + uses: actions/download-artifact@v4 |
| 124 | + with: |
| 125 | + path: /tmp/digests |
| 126 | + pattern: digests-${{ matrix.ubuntu_version }}-* |
| 127 | + merge-multiple: true |
| 128 | + |
| 129 | + - name: Set up Docker Buildx |
| 130 | + uses: docker/setup-buildx-action@v3 |
| 131 | + |
| 132 | + - name: Login to GHCR |
| 133 | + uses: docker/login-action@v3 |
| 134 | + with: |
| 135 | + registry: ghcr.io |
| 136 | + username: ${{ github.repository_owner }} |
| 137 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 138 | + |
| 139 | + # BEGIN Copied to the previous job |
| 140 | + - name: Generate Tag |
| 141 | + env: |
| 142 | + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} |
| 143 | + run: | |
| 144 | + test_tag="" |
| 145 | + if [[ "${GITHUB_REF}" != "refs/heads/${{ github.event.repository.default_branch }}" ]] ; then |
| 146 | + test_tag="test-${BRANCH_NAME////_}-" |
| 147 | + fi |
| 148 | + echo "TEST_TAG=${test_tag}" >> "${GITHUB_ENV}" |
| 149 | +
|
| 150 | + - name: Docker meta |
| 151 | + id: meta |
| 152 | + uses: docker/metadata-action@v5 |
| 153 | + with: |
| 154 | + images: ${{ env.REGISTRY_IMAGE }} |
| 155 | + flavor: | |
| 156 | + latest=false |
| 157 | + tags: | |
| 158 | + type=raw,value=${{ env.TEST_TAG }}${{ matrix.ubuntu_version }} |
| 159 | + # END Copied from the previous job |
| 160 | + |
| 161 | + - name: Create manifest list and push |
| 162 | + working-directory: /tmp/digests |
| 163 | + run: | |
| 164 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 165 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 166 | +
|
| 167 | + - name: Inspect image |
| 168 | + run: | |
| 169 | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
0 commit comments