Skip to content

Commit 8aead37

Browse files
committed
extend the publish script to multiarch
There are problems with creating multiarch devcontainers in one go via buildx and docker. One of the several solutions is to build and push per-architecture-tags, then create a merged metadata file with *all* architectures in one tag. Not perfect, but fits the current structure best (with docker-in-docker etc.)
1 parent e7aca50 commit 8aead37

1 file changed

Lines changed: 44 additions & 11 deletions

File tree

scripts/publish.sh

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,52 @@
11
#!/usr/bin/env bash
22
set -euxo pipefail
33

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"
929
done
10-
fi
1130

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}"
1333

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}"
1636
done
1737

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

Comments
 (0)