|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + dockerhub-repo: |
| 5 | + description: >- |
| 6 | + Docker Hub repository to push the image to. |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + dockerhub-username: |
| 10 | + description: >- |
| 11 | + Username for authenticating to Docker Hub. |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + quay-repo: |
| 15 | + description: >- |
| 16 | + Quay repository to push the image to. |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + quay-username: |
| 20 | + description: >- |
| 21 | + Username for authenticating to Quay. |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + build-context: |
| 25 | + description: >- |
| 26 | + Build's context is the set of files located in the specified PATH or URL. |
| 27 | + type: string |
| 28 | + required: false |
| 29 | + build-file: |
| 30 | + description: >- |
| 31 | + Path to the Dockerfile. |
| 32 | + type: string |
| 33 | + required: false |
| 34 | + build-cache-key: |
| 35 | + description: >- |
| 36 | + An explicit key for a cache entry. |
| 37 | + required: false |
| 38 | + type: string |
| 39 | + default: coatl |
| 40 | + build-digest-key: |
| 41 | + description: >- |
| 42 | + Name of the build digest. |
| 43 | + required: false |
| 44 | + type: string |
| 45 | + default: coatl |
| 46 | + metadata-tags: |
| 47 | + description: >- |
| 48 | + List of tags as key-value pair attributes. |
| 49 | + required: false |
| 50 | + type: string |
| 51 | + latest-tag-flavor: |
| 52 | + description: >- |
| 53 | + Set the latest tag flavor. |
| 54 | + required: false |
| 55 | + type: string |
| 56 | + default: auto |
| 57 | + secrets: |
| 58 | + dockerhub-password: |
| 59 | + description: >- |
| 60 | + Password or personal access token for authenticating against Docker Hub. |
| 61 | + required: true |
| 62 | + quay-password: |
| 63 | + description: >- |
| 64 | + Password or personal access token for authenticating against Quay. |
| 65 | + required: true |
| 66 | + |
| 67 | +jobs: |
| 68 | + build: |
| 69 | + runs-on: ${{ matrix.builder.runner-image }} |
| 70 | + strategy: |
| 71 | + fail-fast: false |
| 72 | + matrix: |
| 73 | + builder: |
| 74 | + - runner-image: ubuntu-24.04 |
| 75 | + platform: linux/amd64 |
| 76 | + - runner-image: ubuntu-24.04-arm |
| 77 | + platform: linux/arm64 |
| 78 | + steps: |
| 79 | + - name: Prepare |
| 80 | + run: | |
| 81 | + platform=${{ matrix.builder.platform }} |
| 82 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 83 | +
|
| 84 | + - name: Docker meta |
| 85 | + id: meta |
| 86 | + uses: docker/metadata-action@v5 |
| 87 | + with: |
| 88 | + images: | |
| 89 | + ${{ inputs.dockerhub-repo }} |
| 90 | + ${{ inputs.quay-repo }} |
| 91 | +
|
| 92 | + - name: Login to Docker Hub |
| 93 | + uses: docker/login-action@v3 |
| 94 | + with: |
| 95 | + username: ${{ inputs.dockerhub-username }} |
| 96 | + password: ${{ secrets.dockerhub-password }} |
| 97 | + |
| 98 | + - name: Login to Quay |
| 99 | + uses: docker/login-action@v3 |
| 100 | + with: |
| 101 | + registry: quay.io |
| 102 | + username: ${{ inputs.quay-username }} |
| 103 | + password: ${{ secrets.quay-password }} |
| 104 | + |
| 105 | + - name: Set up Docker Buildx |
| 106 | + uses: docker/setup-buildx-action@v3 |
| 107 | + |
| 108 | + - name: Build and push by digest |
| 109 | + id: build |
| 110 | + uses: docker/build-push-action@v6 |
| 111 | + with: |
| 112 | + cache-from: type=gha,scope=${{ inputs.build-cache-key }}-${{ env.PLATFORM_PAIR }} |
| 113 | + cache-to: type=gha,scope=${{ inputs.build-cache-key }}-${{ env.PLATFORM_PAIR }},mode=max |
| 114 | + context: ${{ inputs.build-context }} |
| 115 | + file: ${{ inputs.build-file }} |
| 116 | + labels: ${{ steps.meta.outputs.labels }} |
| 117 | + outputs: type=image,"name=${{ inputs.dockerhub-repo }},${{ inputs.quay-repo }}",push-by-digest=true,name-canonical=true,push=true |
| 118 | + platforms: ${{ matrix.builder.platform }} |
| 119 | + provenance: false |
| 120 | + |
| 121 | + - name: Export digest |
| 122 | + run: | |
| 123 | + mkdir -p ${{ runner.temp }}/digests |
| 124 | + digest="${{ steps.build.outputs.digest }}" |
| 125 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 126 | +
|
| 127 | + - name: Upload digest |
| 128 | + uses: actions/upload-artifact@v4 |
| 129 | + with: |
| 130 | + name: digests-${{ inputs.build-digest-key }}-${{ env.PLATFORM_PAIR }} |
| 131 | + path: ${{ runner.temp }}/digests/* |
| 132 | + if-no-files-found: error |
| 133 | + retention-days: 1 |
| 134 | + |
| 135 | + merge: |
| 136 | + runs-on: ubuntu-latest |
| 137 | + needs: |
| 138 | + - build |
| 139 | + steps: |
| 140 | + - name: Download digests |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + path: ${{ runner.temp }}/digests |
| 144 | + pattern: digests-${{ inputs.build-digest-key }}-* |
| 145 | + merge-multiple: true |
| 146 | + |
| 147 | + - name: Login to Docker Hub |
| 148 | + uses: docker/login-action@v3 |
| 149 | + with: |
| 150 | + username: ${{ inputs.dockerhub-username }} |
| 151 | + password: ${{ secrets.dockerhub-password }} |
| 152 | + |
| 153 | + - name: Login to Quay |
| 154 | + uses: docker/login-action@v3 |
| 155 | + with: |
| 156 | + registry: quay.io |
| 157 | + username: ${{ inputs.quay-username }} |
| 158 | + password: ${{ secrets.quay-password }} |
| 159 | + |
| 160 | + - name: Set up Docker Buildx |
| 161 | + uses: docker/setup-buildx-action@v3 |
| 162 | + |
| 163 | + - name: Docker meta |
| 164 | + id: meta |
| 165 | + uses: docker/metadata-action@v5 |
| 166 | + with: |
| 167 | + images: | |
| 168 | + ${{ inputs.dockerhub-repo }} |
| 169 | + ${{ inputs.quay-repo }} |
| 170 | + tags: | |
| 171 | + ${{ inputs.metadata-tags }} |
| 172 | + flavor: | |
| 173 | + latest=${{ inputs.latest-tag-flavor }} |
| 174 | +
|
| 175 | + - name: Create manifest list and push |
| 176 | + working-directory: ${{ runner.temp }}/digests |
| 177 | + run: | |
| 178 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 179 | + $(printf '${{ inputs.dockerhub-repo }}@sha256:%s ' *) |
| 180 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 181 | + $(printf '${{ inputs.quay-repo }}@sha256:%s ' *) |
| 182 | +
|
| 183 | + - name: Inspect image |
| 184 | + run: | |
| 185 | + docker buildx imagetools inspect ${{ inputs.dockerhub-repo }}:${{ steps.meta.outputs.version }} |
| 186 | + docker buildx imagetools inspect ${{ inputs.quay-repo }}:${{ steps.meta.outputs.version }} |
0 commit comments