|
| 1 | +name: Docker Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master, main] |
| 6 | + tags: |
| 7 | + - 'v*' |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +env: |
| 11 | + IMAGE: devteammerit/graph-node |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + name: Build ${{ matrix.arch }} |
| 16 | + runs-on: ${{ matrix.runner }} |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + include: |
| 21 | + - platform: linux/amd64 |
| 22 | + runner: ubuntu-latest |
| 23 | + arch: amd64 |
| 24 | + - platform: linux/arm64 |
| 25 | + runner: ubuntu-24.04-arm |
| 26 | + arch: arm64 |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v5 |
| 29 | + |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + - name: Log in to Docker Hub |
| 34 | + uses: docker/login-action@v3 |
| 35 | + with: |
| 36 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 37 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 38 | + |
| 39 | + - name: Build and push by digest |
| 40 | + id: build |
| 41 | + uses: docker/build-push-action@v6 |
| 42 | + with: |
| 43 | + context: . |
| 44 | + file: docker/Dockerfile |
| 45 | + target: graph-node |
| 46 | + platforms: ${{ matrix.platform }} |
| 47 | + build-args: | |
| 48 | + COMMIT_SHA=${{ github.sha }} |
| 49 | + REPO_NAME=${{ github.repository }} |
| 50 | + BRANCH_NAME=${{ github.ref_name }} |
| 51 | + cache-from: type=gha,scope=${{ matrix.arch }} |
| 52 | + cache-to: type=gha,mode=max,scope=${{ matrix.arch }} |
| 53 | + outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 54 | + |
| 55 | + - name: Export digest |
| 56 | + run: | |
| 57 | + mkdir -p /tmp/digests |
| 58 | + digest="${{ steps.build.outputs.digest }}" |
| 59 | + touch "/tmp/digests/${digest#sha256:}" |
| 60 | +
|
| 61 | + - name: Upload digest |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: digests-${{ matrix.arch }} |
| 65 | + path: /tmp/digests/* |
| 66 | + if-no-files-found: error |
| 67 | + retention-days: 1 |
| 68 | + |
| 69 | + merge: |
| 70 | + name: Merge multi-arch manifest |
| 71 | + runs-on: ubuntu-latest |
| 72 | + needs: build |
| 73 | + steps: |
| 74 | + - name: Download digests |
| 75 | + uses: actions/download-artifact@v4 |
| 76 | + with: |
| 77 | + path: /tmp/digests |
| 78 | + pattern: digests-* |
| 79 | + merge-multiple: true |
| 80 | + |
| 81 | + - name: Set up Docker Buildx |
| 82 | + uses: docker/setup-buildx-action@v3 |
| 83 | + |
| 84 | + - name: Log in to Docker Hub |
| 85 | + uses: docker/login-action@v3 |
| 86 | + with: |
| 87 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 88 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 89 | + |
| 90 | + - name: Generate tags |
| 91 | + id: meta |
| 92 | + uses: docker/metadata-action@v5 |
| 93 | + with: |
| 94 | + images: ${{ env.IMAGE }} |
| 95 | + tags: | |
| 96 | + type=ref,event=branch |
| 97 | + type=ref,event=tag |
| 98 | + type=sha,format=short |
| 99 | + type=raw,value=latest,enable={{is_default_branch}} |
| 100 | +
|
| 101 | + - name: Create multi-arch manifest |
| 102 | + working-directory: /tmp/digests |
| 103 | + run: | |
| 104 | + docker buildx imagetools create \ |
| 105 | + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 106 | + $(printf "${IMAGE}@sha256:%s " *) |
| 107 | +
|
| 108 | + - name: Inspect |
| 109 | + run: | |
| 110 | + docker buildx imagetools inspect ${IMAGE}:${{ steps.meta.outputs.version }} |
0 commit comments