|
| 1 | +name: build-image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +env: |
| 9 | + REGISTRY_IMAGE: jacobbednarz/go-csp-collector |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + platform: |
| 18 | + - linux/amd64 |
| 19 | + - linux/arm64 |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + - name: Docker meta |
| 24 | + id: meta |
| 25 | + uses: docker/metadata-action@v5 |
| 26 | + with: |
| 27 | + images: ${{ env.REGISTRY_IMAGE }} |
| 28 | + - name: Set up QEMU |
| 29 | + uses: docker/setup-qemu-action@v3 |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + - name: Login to Docker Hub |
| 33 | + uses: docker/login-action@v3 |
| 34 | + with: |
| 35 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 36 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 37 | + - name: Build and push by digest |
| 38 | + id: build |
| 39 | + uses: docker/build-push-action@v5 |
| 40 | + with: |
| 41 | + context: . |
| 42 | + platforms: ${{ matrix.platform }} |
| 43 | + labels: ${{ steps.meta.outputs.labels }} |
| 44 | + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 45 | + - name: Export digest |
| 46 | + run: | |
| 47 | + mkdir -p /tmp/digests |
| 48 | + digest="${{ steps.build.outputs.digest }}" |
| 49 | + touch "/tmp/digests/${digest#sha256:}" |
| 50 | + - name: Upload digest |
| 51 | + uses: actions/upload-artifact@v3 |
| 52 | + with: |
| 53 | + name: digests |
| 54 | + path: /tmp/digests/* |
| 55 | + if-no-files-found: error |
| 56 | + retention-days: 1 |
| 57 | + |
| 58 | + merge: |
| 59 | + runs-on: ubuntu-latest |
| 60 | + needs: |
| 61 | + - build |
| 62 | + steps: |
| 63 | + - name: Download digests |
| 64 | + uses: actions/download-artifact@v3 |
| 65 | + with: |
| 66 | + name: digests |
| 67 | + path: /tmp/digests |
| 68 | + - name: Set up Docker Buildx |
| 69 | + uses: docker/setup-buildx-action@v3 |
| 70 | + - name: Docker meta |
| 71 | + id: meta |
| 72 | + uses: docker/metadata-action@v5 |
| 73 | + with: |
| 74 | + images: ${{ env.REGISTRY_IMAGE }} |
| 75 | + - name: Login to Docker Hub |
| 76 | + uses: docker/login-action@v3 |
| 77 | + with: |
| 78 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 79 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 80 | + - name: Create manifest list and push |
| 81 | + working-directory: /tmp/digests |
| 82 | + run: | |
| 83 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 84 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 85 | + - name: Inspect image |
| 86 | + run: | |
| 87 | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
0 commit comments