Skip to content

Commit 2ac6474

Browse files
authored
Fix arm64 build and publish (#46)
1 parent 689a015 commit 2ac6474

File tree

4 files changed

+79
-56
lines changed

4 files changed

+79
-56
lines changed

.github/workflows/ci.yaml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
password: ${{ secrets.GITHUB_TOKEN }}
3232

3333
# Use .devcontainer from THIS repo for building and testing
34-
- name: Check, Build, Test
34+
- name: Check, Build, Test, Publish
3535
uses: devcontainers/ci@v0.3
3636
with:
3737
# The .devcontainer is never published as pre-built container.
@@ -50,15 +50,11 @@ jobs:
5050
# Test
5151
./scripts/test.sh
5252
53-
# Upload devcontainer from src/s-core-devcontainer
54-
- name: Publish
55-
uses: devcontainers/ci@v0.3
56-
if: github.ref == 'refs/heads/main'
57-
with:
58-
# We do not use the push feature of devcontainers/ci here, since that would push the wrong container.
59-
# Instead, we use the publish script which pushes the correct container (residing in src/s-core-devcontainer).
60-
push: "never"
61-
runCmd: |
62-
# manually login to ghcr.io for publishing
63-
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
64-
./scripts/publish.sh "main"
53+
# Optionally: Publish
54+
# We do not use the push feature of devcontainers/ci here, since that would push the wrong container.
55+
# Instead, we use the publish script which pushes the correct container (residing in src/s-core-devcontainer).
56+
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
57+
# manually login to ghcr.io for publishing
58+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
59+
./scripts/publish.sh "main"
60+
fi

.github/workflows/release.yaml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
password: ${{ secrets.GITHUB_TOKEN }}
2727

2828
# Use .devcontainer from THIS repo for building and testing
29-
- name: Check, Build, Test
29+
- name: Check, Build, Test, Publish
3030
uses: devcontainers/ci@v0.3
3131
with:
3232
# The .devcontainer is never published as pre-built container.
@@ -45,15 +45,12 @@ jobs:
4545
# Test
4646
./scripts/test.sh
4747
48-
# Upload devcontainer from src/s-core-devcontainer
49-
- name: Publish
50-
uses: devcontainers/ci@v0.3
51-
with:
52-
# We do not use the push feature of devcontainers/ci here, since that would push the wrong container.
53-
# Instead, we use the publish script which pushes the correct container (residing in src/s-core-devcontainer).
54-
push: "never"
55-
runCmd: |
48+
# Publish
49+
# We do not use the push feature of devcontainers/ci here, since that would push the wrong container.
50+
# Instead, we use the publish script which pushes the correct container (residing in src/s-core-devcontainer).
51+
5652
# manually login to ghcr.io for publishing
5753
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
54+
5855
# Note: "${{ github.ref_name }}" will be the tag name, e.g., "1.0.0"
5956
./scripts/publish.sh "${{ github.ref_name }}" "latest"

scripts/build.sh

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

4-
devcontainer build --platform linux/arm64 --workspace-folder src/s-core-devcontainer --image-name ghcr.io/eclipse-score/devcontainer --cache-from ghcr.io/eclipse-score/devcontainer
5-
devcontainer build --platform linux/amd64 --workspace-folder src/s-core-devcontainer --image-name ghcr.io/eclipse-score/devcontainer --cache-from ghcr.io/eclipse-score/devcontainer
4+
if [ "$#" -eq 0 ]; then
5+
echo "Error: At least one parameter (label) must be provided."
6+
exit 1
7+
fi
8+
9+
LABELS=()
10+
for LABEL in "$@"; do
11+
LABELS+=("${LABEL}")
12+
done
13+
14+
# Define target architectures
15+
ARCHITECTURES=("amd64" "arm64")
16+
17+
# Build for each architecture, creating all requested tags
18+
for ARCH in "${ARCHITECTURES[@]}"; do
19+
echo "Building all labels (${LABELS[@]}) for architecture: ${ARCH}"
20+
21+
# Prepare image names with tags (each tag includes a label and an architecture)
22+
IMAGES=()
23+
for LABEL in "${LABELS[@]}"; do
24+
IMAGES+=("--image-name \"ghcr.io/eclipse-score/devcontainer:${LABEL}-${ARCH}\"")
25+
done
26+
27+
# Prepare devcontainer build command
28+
DEVCONTAINER_CALL="devcontainer build --workspace-folder src/s-core-devcontainer --cache-from ghcr.io/eclipse-score/devcontainer"
29+
30+
# Append image names to the build command
31+
for IMAGE in "${IMAGES[@]}"; do
32+
DEVCONTAINER_CALL+=" $IMAGE"
33+
done
34+
35+
# Execute the build for the specific architecture
36+
eval "$DEVCONTAINER_CALL --platform linux/${ARCH}"
37+
done

scripts/publish.sh

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

4+
if [ "$#" -eq 0 ]; then
5+
echo "Error: At least one parameter (label) must be provided."
6+
exit 1
7+
fi
8+
9+
LABELS=()
10+
for LABEL in "$@"; do
11+
LABELS+=("${LABEL}")
12+
done
13+
414
# Define target architectures
515
ARCHITECTURES=("amd64" "arm64")
616

7-
# Prepare manifest creation command
8-
MANIFEST_MAIN_CALL="docker manifest create ghcr.io/eclipse-score/devcontainer:main"
9-
17+
# Build and push for each architecture, creating all requested tags
1018
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
19+
echo "Building all tags (${LABELS[@]}) for architecture: ${ARCH}"
20+
21+
# Prepare image names with tags (each tag includes a label and an architecture)
22+
IMAGES=()
23+
for LABEL in "${LABELS[@]}"; do
24+
IMAGES+=("--image-name \"ghcr.io/eclipse-score/devcontainer:${LABEL}-${ARCH}\"")
25+
done
2226

2327
# Prepare devcontainer build command
2428
DEVCONTAINER_CALL="devcontainer build --push --workspace-folder src/s-core-devcontainer --cache-from ghcr.io/eclipse-score/devcontainer"
@@ -28,25 +32,19 @@ for ARCH in "${ARCHITECTURES[@]}"; do
2832
DEVCONTAINER_CALL+=" $IMAGE"
2933
done
3034

31-
# Execute the build for the specific architecture
35+
# Execute the build and push all tags for the specific architecture
3236
eval "$DEVCONTAINER_CALL --platform linux/${ARCH}"
33-
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}"
3637
done
3738

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}
39+
# Create and push the merged multiarch manifest for each tag; each tag combines all architecture-specific tags into one tag
40+
for LABEL in "${LABELS[@]}"; do
41+
echo "Merging all architectures (${ARCHITECTURES[@]}) into single tag: ${LABEL}"
42+
43+
MANIFEST_MERGE_CALL="docker buildx imagetools create -t ghcr.io/eclipse-score/devcontainer:${LABEL}"
44+
45+
for ARCH in "${ARCHITECTURES[@]}"; do
46+
MANIFEST_MERGE_CALL+=" ghcr.io/eclipse-score/devcontainer:${LABEL}-${ARCH}"
5147
done
52-
fi
48+
49+
eval "$MANIFEST_MERGE_CALL"
50+
done

0 commit comments

Comments
 (0)