|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euxo pipefail |
3 | 3 |
|
4 | | -IMAGES=("--image-name \"ghcr.io/eclipse-score/devcontainer:main\"") |
5 | | -if [ "$#" -gt 0 ]; then |
6 | | - IMAGES=() |
7 | | - for arg in "$@"; do |
8 | | - IMAGES+=("--image-name \"ghcr.io/eclipse-score/devcontainer:${arg}\"") |
| 4 | +# Define target architectures |
| 5 | +ARCHITECTURES=("amd64" "arm64") |
| 6 | + |
| 7 | +# Prepare manifest creation command |
| 8 | +MANIFEST_MAIN_CALL="docker manifest create ghcr.io/eclipse-score/devcontainer:main" |
| 9 | + |
| 10 | +for ARCH in "${ARCHITECTURES[@]}"; do |
| 11 | + echo "Building for architecture: ${ARCH}" |
| 12 | + |
| 13 | + # Prepare image names - they should include the architectures and also tags if provided |
| 14 | + IMAGES=("--image-name \"ghcr.io/eclipse-score/devcontainer:main-${ARCH}\"") |
| 15 | + # Handle additional tags if provided |
| 16 | + if [ "$#" -gt 0 ]; then |
| 17 | + IMAGES=() |
| 18 | + for arg in "$@"; do |
| 19 | + IMAGES+=("--image-name \"ghcr.io/eclipse-score/devcontainer:${arg}\"") |
| 20 | + done |
| 21 | + fi |
| 22 | + |
| 23 | + # Prepare devcontainer build command |
| 24 | + DEVCONTAINER_CALL="devcontainer build --push --workspace-folder src/s-core-devcontainer --cache-from ghcr.io/eclipse-score/devcontainer" |
| 25 | + |
| 26 | + # Append image names to the build command |
| 27 | + for IMAGE in "${IMAGES[@]}"; do |
| 28 | + DEVCONTAINER_CALL+=" $IMAGE" |
9 | 29 | done |
10 | | -fi |
11 | 30 |
|
12 | | -DEVCONTAINER_CALL="devcontainer build --push --workspace-folder src/s-core-devcontainer --cache-from ghcr.io/eclipse-score/devcontainer" |
| 31 | + # Execute the build for the specific architecture |
| 32 | + eval "$DEVCONTAINER_CALL --platform linux/${ARCH}" |
13 | 33 |
|
14 | | -for IMAGE in "${IMAGES[@]}"; do |
15 | | - DEVCONTAINER_CALL+=" $IMAGE" |
| 34 | + # Append the architecture-specific image to the manifest creation command (those need to be merged into *one* manifest) |
| 35 | + MANIFEST_MAIN_CALL+="ghcr.io/eclipse-score/devcontainer:main-${ARCH}" |
16 | 36 | done |
17 | 37 |
|
18 | | -eval "$DEVCONTAINER_CALL --platform linux/arm64" |
19 | | -eval "$DEVCONTAINER_CALL --platform linux/amd64" |
| 38 | +# Create and push the manifest for 'main' tag |
| 39 | +eval "$MANIFEST_MAIN_CALL" |
| 40 | +docker manifest push ghcr.io/eclipse-score/devcontainer:main |
| 41 | + |
| 42 | +# If additional tags are provided: merge metadata and push those as well |
| 43 | +if [ "$#" -gt 0 ]; then |
| 44 | + for arg in "$@"; do |
| 45 | + MANIFEST_TAG_CALL="docker manifest create ghcr.io/eclipse-score/devcontainer:${arg}" |
| 46 | + for ARCH in "${ARCHITECTURES[@]}"; do |
| 47 | + MANIFEST_TAG_CALL+=" ghcr.io/eclipse-score/devcontainer:${arg}-${ARCH}" |
| 48 | + done |
| 49 | + eval "$MANIFEST_TAG_CALL" |
| 50 | + docker manifest push ghcr.io/eclipse-score/devcontainer:${arg} |
| 51 | + done |
| 52 | +fi |
0 commit comments