|
19 | 19 | docker: |
20 | 20 | needs: test |
21 | 21 | runs-on: ubuntu-latest |
| 22 | + strategy: |
| 23 | + fail-fast: false |
| 24 | + matrix: |
| 25 | + platform: |
| 26 | + - linux/amd64 |
| 27 | + - linux/arm64 |
| 28 | + outputs: |
| 29 | + version: ${{ steps.package-version.outputs.current-version }} |
22 | 30 | steps: |
23 | 31 | - name: Checkout |
24 | 32 | uses: actions/checkout@v4 |
@@ -49,42 +57,88 @@ jobs: |
49 | 57 | username: phalcode |
50 | 58 | password: ${{ secrets.GITHUB_TOKEN }} |
51 | 59 |
|
52 | | - - name: Determine Docker tags |
53 | | - id: tags |
| 60 | + - name: Build and Push by digest |
| 61 | + id: build |
| 62 | + uses: docker/build-push-action@v6 |
| 63 | + with: |
| 64 | + platforms: ${{ matrix.platform }} |
| 65 | + outputs: type=image,push-by-digest=true,name-canonical=true,push=true |
| 66 | + cache-from: type=gha |
| 67 | + cache-to: type=gha,mode=max |
| 68 | + |
| 69 | + - name: Export digest |
| 70 | + run: | |
| 71 | + mkdir -p /tmp/digests |
| 72 | + digest="${{ steps.build.outputs.digest }}" |
| 73 | + touch "/tmp/digests/${digest#sha256:}" |
| 74 | +
|
| 75 | + - name: Upload digest |
| 76 | + uses: actions/upload-artifact@v4 |
| 77 | + with: |
| 78 | + name: digests-${{ strategy.job-index }} |
| 79 | + path: /tmp/digests/* |
| 80 | + if-no-files-found: error |
| 81 | + retention-days: 1 |
| 82 | + |
| 83 | + manifest: |
| 84 | + needs: docker |
| 85 | + runs-on: ubuntu-latest |
| 86 | + steps: |
| 87 | + - name: Download digests |
| 88 | + uses: actions/download-artifact@v4 |
| 89 | + with: |
| 90 | + path: /tmp/digests |
| 91 | + pattern: digests-* |
| 92 | + merge-multiple: true |
| 93 | + |
| 94 | + - name: Set up Docker Buildx |
| 95 | + uses: docker/setup-buildx-action@v3 |
| 96 | + |
| 97 | + - name: Login to Docker Hub |
| 98 | + uses: docker/login-action@v3 |
| 99 | + with: |
| 100 | + username: phalcode |
| 101 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 102 | + |
| 103 | + - name: Login to GitHub Container Registry |
| 104 | + uses: docker/login-action@v3 |
| 105 | + with: |
| 106 | + registry: ghcr.io |
| 107 | + username: phalcode |
| 108 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 109 | + |
| 110 | + - name: Create manifest list and push |
54 | 111 | run: | |
55 | 112 | BRANCH="${GITHUB_REF#refs/heads/}" |
| 113 | + VERSION="${{ needs.docker.outputs.version }}" |
| 114 | +
|
| 115 | + push_manifest() { |
| 116 | + local REPO=$1 |
| 117 | + local TAGS=$2 |
| 118 | + local ARGS="" |
| 119 | + for tag in $TAGS; do |
| 120 | + ARGS="$ARGS -t $REPO:$tag" |
| 121 | + done |
| 122 | + |
| 123 | + docker buildx imagetools create $ARGS \ |
| 124 | + $(printf "$REPO@sha256:%s " $(ls /tmp/digests)) |
| 125 | + } |
| 126 | +
|
56 | 127 | case "$BRANCH" in |
57 | 128 | master|hotfix) |
58 | | - echo "tags<<EOF" >> $GITHUB_OUTPUT |
59 | | - echo "phalcode/gamevault-backend:latest" >> $GITHUB_OUTPUT |
60 | | - echo "phalcode/gamevault-backend:${{ steps.package-version.outputs.current-version }}" >> $GITHUB_OUTPUT |
61 | | - echo "ghcr.io/phalcode/gamevault-backend:latest" >> $GITHUB_OUTPUT |
62 | | - echo "ghcr.io/phalcode/gamevault-backend:${{ steps.package-version.outputs.current-version }}" >> $GITHUB_OUTPUT |
63 | | - echo "EOF" >> $GITHUB_OUTPUT |
| 129 | + push_manifest "phalcode/gamevault-backend" "latest $VERSION" |
| 130 | + push_manifest "ghcr.io/phalcode/gamevault-backend" "latest $VERSION" |
64 | 131 | ;; |
65 | 132 | develop) |
66 | | - echo "tags<<EOF" >> $GITHUB_OUTPUT |
67 | | - echo "phalcode/gamevault-backend:unstable" >> $GITHUB_OUTPUT |
68 | | - echo "ghcr.io/phalcode/gamevault-backend:unstable" >> $GITHUB_OUTPUT |
69 | | - echo "EOF" >> $GITHUB_OUTPUT |
| 133 | + push_manifest "phalcode/gamevault-backend" "unstable" |
| 134 | + push_manifest "ghcr.io/phalcode/gamevault-backend" "unstable" |
70 | 135 | ;; |
71 | 136 | early-access) |
72 | | - echo "tags<<EOF" >> $GITHUB_OUTPUT |
73 | | - echo "phalcode/gamevault-backend:early-access" >> $GITHUB_OUTPUT |
74 | | - echo "ghcr.io/phalcode/gamevault-backend:early-access" >> $GITHUB_OUTPUT |
75 | | - echo "EOF" >> $GITHUB_OUTPUT |
| 137 | + push_manifest "phalcode/gamevault-backend" "early-access" |
| 138 | + push_manifest "ghcr.io/phalcode/gamevault-backend" "early-access" |
76 | 139 | ;; |
77 | 140 | esac |
78 | 141 |
|
79 | | - - name: Build and Push |
80 | | - uses: docker/build-push-action@v6 |
81 | | - with: |
82 | | - platforms: linux/amd64,linux/arm64 |
83 | | - push: true |
84 | | - tags: ${{ steps.tags.outputs.tags }} |
85 | | - cache-from: type=gha |
86 | | - cache-to: type=gha,mode=max |
87 | | - |
88 | 142 | - name: Create Github Tag & Release |
89 | 143 | if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' |
90 | 144 | id: release |
|
98 | 152 | env: |
99 | 153 | DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_BOT_WEBHOOK }} |
100 | 154 | with: |
101 | | - args: "<@&1128857090090340382> New Release: {{ EVENT_PAYLOAD.repository.full_name }} v${{ steps.package-version.outputs.current-version }} has been deployed. Here are the changes: https://github.com/{{ EVENT_PAYLOAD.repository.full_name }}/releases/tag/${{ steps.package-version.outputs.current-version }}" |
| 155 | + args: "<@&1128857090090340382> New Release: {{ EVENT_PAYLOAD.repository.full_name }} v$VERSION has been deployed. Here are the changes: https://github.com/{{ EVENT_PAYLOAD.repository.full_name }}/releases/tag/$VERSION" |
102 | 156 |
|
103 | 157 | sonarcloud: |
104 | 158 | needs: test |
|
0 commit comments