|
| 1 | +name: Build and push Docker images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '[0-9]*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + prepare: |
| 10 | + name: Determine base tag |
| 11 | + runs-on: ubuntu-24.04 |
| 12 | + outputs: |
| 13 | + tag_suffix: ${{ steps.tags.outputs.tag_suffix }} |
| 14 | + steps: |
| 15 | + - name: Determine base tag |
| 16 | + id: tags |
| 17 | + run: | |
| 18 | + ref="${GITHUB_REF_NAME}" |
| 19 | + if [[ "$ref" =~ ^([0-9]+\.[0-9]+)$ ]]; then |
| 20 | + minor="${BASH_REMATCH[1]}" |
| 21 | + tag="$minor" |
| 22 | + else |
| 23 | + tag="latest" |
| 24 | + fi |
| 25 | + if [[ "$tag" == "latest" ]]; then |
| 26 | + suffix="" |
| 27 | + else |
| 28 | + suffix="-$tag" |
| 29 | + fi |
| 30 | + echo "tag_suffix=$suffix" >> "$GITHUB_OUTPUT" |
| 31 | +
|
| 32 | + build-base: |
| 33 | + name: Build base image (${{ matrix.platform }}) |
| 34 | + runs-on: ${{ matrix.runner }} |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + include: |
| 39 | + - platform: linux/amd64 |
| 40 | + runner: ubuntu-24.04 |
| 41 | + - platform: linux/arm64 |
| 42 | + runner: ubuntu-24.04-arm |
| 43 | + |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Log in to Docker Hub |
| 48 | + uses: docker/login-action@v3 |
| 49 | + with: |
| 50 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 51 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 52 | + |
| 53 | + - name: Set up Docker Buildx |
| 54 | + uses: docker/setup-buildx-action@v3 |
| 55 | + |
| 56 | + # Build and push platform-specific digest (no manifest tag yet) |
| 57 | + - name: Build and push by digest |
| 58 | + id: build |
| 59 | + uses: docker/build-push-action@v6 |
| 60 | + with: |
| 61 | + context: base |
| 62 | + file: base/Dockerfile |
| 63 | + platforms: ${{ matrix.platform }} |
| 64 | + push: true |
| 65 | + outputs: type=image,name=apluslms/service-base,push-by-digest=true,name-canonical=true |
| 66 | + |
| 67 | + - name: Export digest |
| 68 | + run: | |
| 69 | + mkdir -p /tmp/digests |
| 70 | + digest="${{ steps.build.outputs.digest }}" |
| 71 | + touch "/tmp/digests/${digest#sha256:}" |
| 72 | +
|
| 73 | + - name: Upload digest artifact |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + with: |
| 76 | + name: digest-base-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} |
| 77 | + path: /tmp/digests/* |
| 78 | + retention-days: 1 |
| 79 | + |
| 80 | + merge-base: |
| 81 | + name: Merge base manifests |
| 82 | + runs-on: ubuntu-24.04 |
| 83 | + needs: build-base |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: Download digests |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + path: /tmp/digests |
| 90 | + pattern: digest-base-* |
| 91 | + merge-multiple: true |
| 92 | + |
| 93 | + - name: Log in to Docker Hub |
| 94 | + uses: docker/login-action@v3 |
| 95 | + with: |
| 96 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 97 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 98 | + |
| 99 | + - name: Set up Docker Buildx |
| 100 | + uses: docker/setup-buildx-action@v3 |
| 101 | + |
| 102 | + - name: Determine tags |
| 103 | + id: meta |
| 104 | + uses: docker/metadata-action@v5 |
| 105 | + with: |
| 106 | + images: apluslms/service-base |
| 107 | + flavor: | |
| 108 | + latest=false |
| 109 | + tags: | |
| 110 | + type=raw,value=base |
| 111 | + type=raw,value=base-latest |
| 112 | + type=match,pattern=(\d+\.\d+)$,group=1,prefix=base- |
| 113 | +
|
| 114 | + - name: Create and push multi-arch manifest |
| 115 | + working-directory: /tmp/digests |
| 116 | + run: | |
| 117 | + docker buildx imagetools create \ |
| 118 | + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 119 | + $(printf 'apluslms/service-base@sha256:%s ' *) |
| 120 | +
|
| 121 | + build-dbipc: |
| 122 | + name: Build dbipc image (${{ matrix.platform }}) |
| 123 | + runs-on: ${{ matrix.runner }} |
| 124 | + needs: |
| 125 | + - prepare |
| 126 | + - merge-base |
| 127 | + strategy: |
| 128 | + fail-fast: false |
| 129 | + matrix: |
| 130 | + include: |
| 131 | + - platform: linux/amd64 |
| 132 | + runner: ubuntu-24.04 |
| 133 | + - platform: linux/arm64 |
| 134 | + runner: ubuntu-24.04-arm |
| 135 | + |
| 136 | + steps: |
| 137 | + - uses: actions/checkout@v4 |
| 138 | + |
| 139 | + - name: Log in to Docker Hub |
| 140 | + uses: docker/login-action@v3 |
| 141 | + with: |
| 142 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 143 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 144 | + |
| 145 | + - name: Set up Docker Buildx |
| 146 | + uses: docker/setup-buildx-action@v3 |
| 147 | + |
| 148 | + - name: Build and push by digest |
| 149 | + id: build |
| 150 | + uses: docker/build-push-action@v6 |
| 151 | + with: |
| 152 | + context: dbipc |
| 153 | + file: dbipc/Dockerfile |
| 154 | + platforms: ${{ matrix.platform }} |
| 155 | + push: true |
| 156 | + build-args: | |
| 157 | + TAGVER=${{ needs.prepare.outputs.tag_suffix }} |
| 158 | + outputs: type=image,name=apluslms/service-base,push-by-digest=true,name-canonical=true |
| 159 | + |
| 160 | + - name: Export digest |
| 161 | + run: | |
| 162 | + mkdir -p /tmp/digests |
| 163 | + digest="${{ steps.build.outputs.digest }}" |
| 164 | + touch "/tmp/digests/${digest#sha256:}" |
| 165 | +
|
| 166 | + - name: Upload digest artifact |
| 167 | + uses: actions/upload-artifact@v4 |
| 168 | + with: |
| 169 | + name: digest-dbipc-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} |
| 170 | + path: /tmp/digests/* |
| 171 | + retention-days: 1 |
| 172 | + |
| 173 | + merge-dbipc: |
| 174 | + name: Merge dbipc manifests |
| 175 | + runs-on: ubuntu-24.04 |
| 176 | + needs: build-dbipc |
| 177 | + |
| 178 | + steps: |
| 179 | + - name: Download digests |
| 180 | + uses: actions/download-artifact@v4 |
| 181 | + with: |
| 182 | + path: /tmp/digests |
| 183 | + pattern: digest-dbipc-* |
| 184 | + merge-multiple: true |
| 185 | + |
| 186 | + - name: Log in to Docker Hub |
| 187 | + uses: docker/login-action@v3 |
| 188 | + with: |
| 189 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 190 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 191 | + |
| 192 | + - name: Set up Docker Buildx |
| 193 | + uses: docker/setup-buildx-action@v3 |
| 194 | + |
| 195 | + - name: Determine tags |
| 196 | + id: meta |
| 197 | + uses: docker/metadata-action@v5 |
| 198 | + with: |
| 199 | + images: apluslms/service-base |
| 200 | + flavor: | |
| 201 | + latest=false |
| 202 | + tags: | |
| 203 | + type=raw,value=dbipc |
| 204 | + type=raw,value=dbipc-latest |
| 205 | + type=match,pattern=(\d+\.\d+)$,group=1,prefix=dbipc- |
| 206 | +
|
| 207 | + - name: Create and push multi-arch manifest |
| 208 | + working-directory: /tmp/digests |
| 209 | + run: | |
| 210 | + docker buildx imagetools create \ |
| 211 | + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 212 | + $(printf 'apluslms/service-base@sha256:%s ' *) |
| 213 | +
|
| 214 | + build-python3: |
| 215 | + name: Build python3 image (${{ matrix.platform }}) |
| 216 | + runs-on: ${{ matrix.runner }} |
| 217 | + needs: |
| 218 | + - prepare |
| 219 | + - merge-dbipc |
| 220 | + strategy: |
| 221 | + fail-fast: false |
| 222 | + matrix: |
| 223 | + include: |
| 224 | + - platform: linux/amd64 |
| 225 | + runner: ubuntu-24.04 |
| 226 | + - platform: linux/arm64 |
| 227 | + runner: ubuntu-24.04-arm |
| 228 | + |
| 229 | + steps: |
| 230 | + - uses: actions/checkout@v4 |
| 231 | + |
| 232 | + - name: Log in to Docker Hub |
| 233 | + uses: docker/login-action@v3 |
| 234 | + with: |
| 235 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 236 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 237 | + |
| 238 | + - name: Set up Docker Buildx |
| 239 | + uses: docker/setup-buildx-action@v3 |
| 240 | + |
| 241 | + - name: Build and push by digest |
| 242 | + id: build |
| 243 | + uses: docker/build-push-action@v6 |
| 244 | + with: |
| 245 | + context: python3 |
| 246 | + file: python3/Dockerfile |
| 247 | + platforms: ${{ matrix.platform }} |
| 248 | + push: true |
| 249 | + build-args: | |
| 250 | + TAGVER=${{ needs.prepare.outputs.tag_suffix }} |
| 251 | + outputs: type=image,name=apluslms/service-base,push-by-digest=true,name-canonical=true |
| 252 | + |
| 253 | + - name: Export digest |
| 254 | + run: | |
| 255 | + mkdir -p /tmp/digests |
| 256 | + digest="${{ steps.build.outputs.digest }}" |
| 257 | + touch "/tmp/digests/${digest#sha256:}" |
| 258 | +
|
| 259 | + - name: Upload digest artifact |
| 260 | + uses: actions/upload-artifact@v4 |
| 261 | + with: |
| 262 | + name: digest-python3-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} |
| 263 | + path: /tmp/digests/* |
| 264 | + retention-days: 1 |
| 265 | + |
| 266 | + merge-python3: |
| 267 | + name: Merge python3 manifests |
| 268 | + runs-on: ubuntu-24.04 |
| 269 | + needs: build-python3 |
| 270 | + |
| 271 | + steps: |
| 272 | + - name: Download digests |
| 273 | + uses: actions/download-artifact@v4 |
| 274 | + with: |
| 275 | + path: /tmp/digests |
| 276 | + pattern: digest-python3-* |
| 277 | + merge-multiple: true |
| 278 | + |
| 279 | + - name: Log in to Docker Hub |
| 280 | + uses: docker/login-action@v3 |
| 281 | + with: |
| 282 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 283 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 284 | + |
| 285 | + - name: Set up Docker Buildx |
| 286 | + uses: docker/setup-buildx-action@v3 |
| 287 | + |
| 288 | + - name: Determine tags |
| 289 | + id: meta |
| 290 | + uses: docker/metadata-action@v5 |
| 291 | + with: |
| 292 | + images: apluslms/service-base |
| 293 | + flavor: | |
| 294 | + latest=false |
| 295 | + tags: | |
| 296 | + type=raw,value=python3 |
| 297 | + type=raw,value=python3-latest |
| 298 | + type=match,pattern=(\d+\.\d+)$,group=1,prefix=python3- |
| 299 | +
|
| 300 | + - name: Create and push multi-arch manifest |
| 301 | + working-directory: /tmp/digests |
| 302 | + run: | |
| 303 | + docker buildx imagetools create \ |
| 304 | + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 305 | + $(printf 'apluslms/service-base@sha256:%s ' *) |
| 306 | +
|
| 307 | + build-django: |
| 308 | + name: Build django image (${{ matrix.platform }}) |
| 309 | + runs-on: ${{ matrix.runner }} |
| 310 | + needs: |
| 311 | + - prepare |
| 312 | + - merge-python3 |
| 313 | + strategy: |
| 314 | + fail-fast: false |
| 315 | + matrix: |
| 316 | + include: |
| 317 | + - platform: linux/amd64 |
| 318 | + runner: ubuntu-24.04 |
| 319 | + - platform: linux/arm64 |
| 320 | + runner: ubuntu-24.04-arm |
| 321 | + |
| 322 | + steps: |
| 323 | + - uses: actions/checkout@v4 |
| 324 | + |
| 325 | + - name: Log in to Docker Hub |
| 326 | + uses: docker/login-action@v3 |
| 327 | + with: |
| 328 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 329 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 330 | + |
| 331 | + - name: Set up Docker Buildx |
| 332 | + uses: docker/setup-buildx-action@v3 |
| 333 | + |
| 334 | + - name: Build and push by digest |
| 335 | + id: build |
| 336 | + uses: docker/build-push-action@v6 |
| 337 | + with: |
| 338 | + context: django |
| 339 | + file: django/Dockerfile |
| 340 | + platforms: ${{ matrix.platform }} |
| 341 | + push: true |
| 342 | + build-args: | |
| 343 | + TAGVER=${{ needs.prepare.outputs.tag_suffix }} |
| 344 | + outputs: type=image,name=apluslms/service-base,push-by-digest=true,name-canonical=true |
| 345 | + |
| 346 | + - name: Export digest |
| 347 | + run: | |
| 348 | + mkdir -p /tmp/digests |
| 349 | + digest="${{ steps.build.outputs.digest }}" |
| 350 | + touch "/tmp/digests/${digest#sha256:}" |
| 351 | +
|
| 352 | + - name: Upload digest artifact |
| 353 | + uses: actions/upload-artifact@v4 |
| 354 | + with: |
| 355 | + name: digest-django-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} |
| 356 | + path: /tmp/digests/* |
| 357 | + retention-days: 1 |
| 358 | + |
| 359 | + merge-django: |
| 360 | + name: Merge django manifests |
| 361 | + runs-on: ubuntu-24.04 |
| 362 | + needs: build-django |
| 363 | + |
| 364 | + steps: |
| 365 | + - name: Download digests |
| 366 | + uses: actions/download-artifact@v4 |
| 367 | + with: |
| 368 | + path: /tmp/digests |
| 369 | + pattern: digest-django-* |
| 370 | + merge-multiple: true |
| 371 | + |
| 372 | + - name: Log in to Docker Hub |
| 373 | + uses: docker/login-action@v3 |
| 374 | + with: |
| 375 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 376 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 377 | + |
| 378 | + - name: Set up Docker Buildx |
| 379 | + uses: docker/setup-buildx-action@v3 |
| 380 | + |
| 381 | + - name: Determine tags |
| 382 | + id: meta |
| 383 | + uses: docker/metadata-action@v5 |
| 384 | + with: |
| 385 | + images: apluslms/service-base |
| 386 | + flavor: | |
| 387 | + latest=false |
| 388 | + tags: | |
| 389 | + type=raw,value=django |
| 390 | + type=raw,value=django-latest |
| 391 | + type=match,pattern=(\d+\.\d+)$,group=1,prefix=django- |
| 392 | +
|
| 393 | + - name: Create and push multi-arch manifest |
| 394 | + working-directory: /tmp/digests |
| 395 | + run: | |
| 396 | + docker buildx imagetools create \ |
| 397 | + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 398 | + $(printf 'apluslms/service-base@sha256:%s ' *) |
0 commit comments