|
68 | 68 | # push: true |
69 | 69 | # tags: ${{ steps.set-tags.outputs.tags }} |
70 | 70 | # target: ${{ inputs.target }} |
| 71 | +# |
| 72 | +#name: Docker Publish |
| 73 | +# |
| 74 | +#on: |
| 75 | +# workflow_call: |
| 76 | +# inputs: |
| 77 | +# image_name: |
| 78 | +# required: false |
| 79 | +# type: string |
| 80 | +# default: 'portabase/agent' |
| 81 | +# add_latest: |
| 82 | +# required: false |
| 83 | +# type: boolean |
| 84 | +# default: false |
| 85 | +# target: |
| 86 | +# required: false |
| 87 | +# type: string |
| 88 | +# default: 'prod' |
| 89 | +# dockerfile: |
| 90 | +# required: false |
| 91 | +# type: string |
| 92 | +# default: './docker/Dockerfile' |
| 93 | +# secrets: |
| 94 | +# DOCKER_USERNAME: |
| 95 | +# required: true |
| 96 | +# DOCKER_PASSWORD: |
| 97 | +# required: true |
| 98 | +# |
| 99 | +#jobs: |
| 100 | +# build-amd64: |
| 101 | +# name: Build AMD64 Image |
| 102 | +# runs-on: ubuntu-latest |
| 103 | +# outputs: |
| 104 | +# image: ${{ steps.set-job-output.outputs.image }} |
| 105 | +# steps: |
| 106 | +# - uses: actions/checkout@v4 |
| 107 | +# |
| 108 | +# - uses: docker/setup-buildx-action@v3 |
| 109 | +# |
| 110 | +# - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a |
| 111 | +# with: |
| 112 | +# username: ${{ secrets.DOCKER_USERNAME }} |
| 113 | +# password: ${{ secrets.DOCKER_PASSWORD }} |
| 114 | +# |
| 115 | +# - name: Set AMD64 image tag |
| 116 | +# id: set-tags |
| 117 | +# run: | |
| 118 | +# REF_NAME=${GITHUB_REF#refs/tags/} |
| 119 | +# AMD64_IMAGE="${{ inputs.image_name }}:$REF_NAME-amd64" |
| 120 | +# echo "amd64_image=$AMD64_IMAGE" >> $GITHUB_OUTPUT |
| 121 | +# |
| 122 | +# - name: Build and push AMD64 |
| 123 | +# uses: docker/build-push-action@v6 |
| 124 | +# with: |
| 125 | +# context: . |
| 126 | +# file: ${{ inputs.dockerfile }} |
| 127 | +# platforms: linux/amd64 |
| 128 | +# push: true |
| 129 | +# tags: ${{ steps.set-tags.outputs.amd64_image }} |
| 130 | +# target: ${{ inputs.target }} |
| 131 | +# |
| 132 | +# build-arm64: |
| 133 | +# name: Build ARM64 Image |
| 134 | +# runs-on: ubuntu-24.04-arm |
| 135 | +# outputs: |
| 136 | +# image: ${{ steps.set-job-output.outputs.image }} |
| 137 | +# steps: |
| 138 | +# - uses: actions/checkout@v4 |
| 139 | +# |
| 140 | +# - uses: docker/setup-buildx-action@v3 |
| 141 | +# |
| 142 | +# - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a |
| 143 | +# with: |
| 144 | +# username: ${{ secrets.DOCKER_USERNAME }} |
| 145 | +# password: ${{ secrets.DOCKER_PASSWORD }} |
| 146 | +# |
| 147 | +# - name: Set ARM64 image tag |
| 148 | +# id: set-tags |
| 149 | +# run: | |
| 150 | +# REF_NAME=${GITHUB_REF#refs/tags/} |
| 151 | +# ARM64_IMAGE="${{ inputs.image_name }}:$REF_NAME-arm64" |
| 152 | +# echo "arm64_image=$ARM64_IMAGE" >> $GITHUB_OUTPUT |
| 153 | +# |
| 154 | +# - name: Build and push ARM64 |
| 155 | +# uses: docker/build-push-action@v6 |
| 156 | +# with: |
| 157 | +# context: . |
| 158 | +# file: ${{ inputs.dockerfile }} |
| 159 | +# platforms: linux/arm64 |
| 160 | +# push: true |
| 161 | +# tags: ${{ steps.set-tags.outputs.arm64_image }} |
| 162 | +# target: ${{ inputs.target }} |
| 163 | +# |
| 164 | +# |
| 165 | +# create-manifest: |
| 166 | +# name: Create Multi-Arch Manifest |
| 167 | +# runs-on: ubuntu-latest |
| 168 | +# needs: |
| 169 | +# - build-amd64 |
| 170 | +# - build-arm64 |
| 171 | +# steps: |
| 172 | +# - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a |
| 173 | +# with: |
| 174 | +# username: ${{ secrets.DOCKER_USERNAME }} |
| 175 | +# password: ${{ secrets.DOCKER_PASSWORD }} |
| 176 | +# |
| 177 | +# - name: Create Docker manifest |
| 178 | +# run: | |
| 179 | +# REF_NAME=${GITHUB_REF#refs/tags/} |
| 180 | +# |
| 181 | +# IMAGE="${{ inputs.image_name }}:$REF_NAME" |
| 182 | +# AMD64_IMAGE="$IMAGE-amd64" |
| 183 | +# ARM64_IMAGE="$IMAGE-arm64" |
| 184 | +# |
| 185 | +# echo "AMD64_IMAGE=$AMD64_IMAGE" |
| 186 | +# echo "ARM64_IMAGE=$ARM64_IMAGE" |
| 187 | +# |
| 188 | +# docker manifest create $IMAGE $AMD64_IMAGE $ARM64_IMAGE |
| 189 | +# docker manifest push $IMAGE |
| 190 | +# |
| 191 | +# if [ "${{ inputs.add_latest }}" = "true" ]; then |
| 192 | +# docker manifest create ${{ inputs.image_name }}:latest $AMD64_IMAGE $ARM64_IMAGE |
| 193 | +# docker manifest push ${{ inputs.image_name }}:latest |
| 194 | +# fi |
| 195 | + |
71 | 196 |
|
72 | 197 | name: Docker Publish |
73 | 198 |
|
|
97 | 222 | required: true |
98 | 223 |
|
99 | 224 | jobs: |
100 | | - build-amd64: |
101 | | - name: Build AMD64 Image |
102 | | - runs-on: ubuntu-latest |
103 | | - outputs: |
104 | | - image: ${{ steps.set-job-output.outputs.image }} |
| 225 | + build: |
| 226 | + name: Build and push Docker images |
| 227 | + runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-latest' || matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' }} |
| 228 | + strategy: |
| 229 | + fail-fast: false |
| 230 | + matrix: |
| 231 | + platform: [linux/amd64, linux/arm64] |
105 | 232 | steps: |
106 | | - - uses: actions/checkout@v4 |
107 | | - |
108 | | - - uses: docker/setup-buildx-action@v3 |
| 233 | + - name: Checkout |
| 234 | + uses: actions/checkout@v4 |
109 | 235 |
|
110 | | - - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a |
| 236 | + - name: Login to Docker |
| 237 | + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a |
111 | 238 | with: |
112 | 239 | username: ${{ secrets.DOCKER_USERNAME }} |
113 | 240 | password: ${{ secrets.DOCKER_PASSWORD }} |
114 | 241 |
|
115 | | - - name: Set AMD64 image tag |
| 242 | + - name: Set image tag |
116 | 243 | id: set-tags |
117 | 244 | run: | |
118 | 245 | REF_NAME=${GITHUB_REF#refs/tags/} |
119 | | - AMD64_IMAGE="${{ inputs.image_name }}:$REF_NAME-amd64" |
120 | | - echo "amd64_image=$AMD64_IMAGE" >> $GITHUB_OUTPUT |
| 246 | + if [ "${{ matrix.platform }}" = "linux/amd64" ]; then |
| 247 | + IMAGE="${{ inputs.image_name }}:$REF_NAME-amd64" |
| 248 | + else |
| 249 | + IMAGE="${{ inputs.image_name }}:$REF_NAME-arm64" |
| 250 | + fi |
| 251 | + echo "image=$IMAGE" >> $GITHUB_OUTPUT |
121 | 252 |
|
122 | | - - name: Build and push AMD64 |
| 253 | + - name: Build and push image |
123 | 254 | uses: docker/build-push-action@v6 |
124 | 255 | with: |
125 | 256 | context: . |
126 | 257 | file: ${{ inputs.dockerfile }} |
127 | | - platforms: linux/amd64 |
| 258 | + platforms: ${{ matrix.platform }} |
128 | 259 | push: true |
129 | | - tags: ${{ steps.set-tags.outputs.amd64_image }} |
| 260 | + tags: ${{ steps.set-tags.outputs.image }} |
130 | 261 | target: ${{ inputs.target }} |
131 | 262 |
|
132 | | - build-arm64: |
133 | | - name: Build ARM64 Image |
134 | | - runs-on: ubuntu-24.04-arm |
135 | | - outputs: |
136 | | - image: ${{ steps.set-job-output.outputs.image }} |
137 | | - steps: |
138 | | - - uses: actions/checkout@v4 |
139 | | - |
140 | | - - uses: docker/setup-buildx-action@v3 |
141 | | - |
142 | | - - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a |
143 | | - with: |
144 | | - username: ${{ secrets.DOCKER_USERNAME }} |
145 | | - password: ${{ secrets.DOCKER_PASSWORD }} |
146 | | - |
147 | | - - name: Set ARM64 image tag |
148 | | - id: set-tags |
149 | | - run: | |
150 | | - REF_NAME=${GITHUB_REF#refs/tags/} |
151 | | - ARM64_IMAGE="${{ inputs.image_name }}:$REF_NAME-arm64" |
152 | | - echo "arm64_image=$ARM64_IMAGE" >> $GITHUB_OUTPUT |
| 263 | + - name: Upload image tag for manifest |
| 264 | + id: upload |
| 265 | + run: echo "${{ steps.set-tags.outputs.image }}" > image.txt |
153 | 266 |
|
154 | | - - name: Build and push ARM64 |
155 | | - uses: docker/build-push-action@v6 |
| 267 | + - uses: actions/upload-artifact@v3 |
156 | 268 | with: |
157 | | - context: . |
158 | | - file: ${{ inputs.dockerfile }} |
159 | | - platforms: linux/arm64 |
160 | | - push: true |
161 | | - tags: ${{ steps.set-tags.outputs.arm64_image }} |
162 | | - target: ${{ inputs.target }} |
163 | | - |
| 269 | + name: image-${{ matrix.platform }} |
| 270 | + path: image.txt |
164 | 271 |
|
165 | 272 | create-manifest: |
166 | | - name: Create Multi-Arch Manifest |
| 273 | + name: Create multi-arch Docker manifest |
167 | 274 | runs-on: ubuntu-latest |
168 | | - needs: |
169 | | - - build-amd64 |
170 | | - - build-arm64 |
| 275 | + needs: build |
171 | 276 | steps: |
172 | | - - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a |
| 277 | + - uses: actions/download-artifact@v3 |
| 278 | + with: |
| 279 | + name: image-linux/amd64 |
| 280 | + path: /tmp/digests |
| 281 | + |
| 282 | + - uses: actions/download-artifact@v3 |
| 283 | + with: |
| 284 | + name: image-linux/arm64 |
| 285 | + path: /tmp/digests |
| 286 | + |
| 287 | + - name: Login to Docker |
| 288 | + uses: docker/login-action@v3 |
173 | 289 | with: |
174 | 290 | username: ${{ secrets.DOCKER_USERNAME }} |
175 | 291 | password: ${{ secrets.DOCKER_PASSWORD }} |
176 | 292 |
|
177 | | - - name: Create Docker manifest |
| 293 | + - name: Create and push manifest |
178 | 294 | run: | |
| 295 | + AMD64_IMAGE=$(cat /tmp/digests/image-linux/amd64/image.txt) |
| 296 | + ARM64_IMAGE=$(cat /tmp/digests/image-linux/arm64/image.txt) |
179 | 297 | REF_NAME=${GITHUB_REF#refs/tags/} |
180 | | - |
181 | | - IMAGE="${{ inputs.image_name }}:$REF_NAME" |
182 | | - AMD64_IMAGE="$IMAGE-amd64" |
183 | | - ARM64_IMAGE="$IMAGE-arm64" |
184 | | -
|
185 | | - echo "AMD64_IMAGE=$AMD64_IMAGE" |
186 | | - echo "ARM64_IMAGE=$ARM64_IMAGE" |
| 298 | + MANIFEST_IMAGE="${{ inputs.image_name }}:$REF_NAME" |
187 | 299 |
|
188 | | - docker manifest create $IMAGE $AMD64_IMAGE $ARM64_IMAGE |
189 | | - docker manifest push $IMAGE |
| 300 | + docker manifest create $MANIFEST_IMAGE $AMD64_IMAGE $ARM64_IMAGE |
| 301 | + docker manifest push $MANIFEST_IMAGE |
190 | 302 |
|
191 | 303 | if [ "${{ inputs.add_latest }}" = "true" ]; then |
192 | 304 | docker manifest create ${{ inputs.image_name }}:latest $AMD64_IMAGE $ARM64_IMAGE |
|
0 commit comments