Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:

- name: Merge images
run: |
./tools/merge-docker-images.sh $GITHUB_SHA
./tools/merge-docker-images.sh clockworklabs/spacetimedb "commit-${GITHUB_SHA:0:7}" "${GITHUB_SHA:0:7}-full"

# This ugly bit is necessary if you don't want your cache to grow forever
# until it hits GitHub's limit of 5GB.
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:

- name: Merge images
run: |
./tools/merge-docker-images.sh $GITHUB_SHA
./tools/merge-docker-images.sh clockworklabs/spacetimedb "commit-${GITHUB_SHA:0:7}" "${GITHUB_SHA:0:7}-full"

# This ugly bit is necessary if you don't want your cache to grow forever
# until it hits GitHub's limit of 5GB.
Expand Down
55 changes: 33 additions & 22 deletions tools/merge-docker-images.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
#!/bin/bash
set -e
set -u

# Shorten the first argument (commit sha) to 7 chars
SHORT_SHA=${1:0:7}
TAG="commit-$SHORT_SHA"
sanitize_docker_ref() {
echo "$1" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-z0-9._-]/-/g' -e 's/^[.-]//g' -e 's/[.-]$//g'
}

IMAGE_NAME="$1"
# Docker tag to use for platform-specific images
TAG="$2"
# Docker tag to use for the "universal" image
FULL_TAG="$3"

# Check if images for both amd64 and arm64 exist
if docker pull clockworklabs/spacetimedb:$TAG-amd64 --platform amd64 >/dev/null 2>&1 && docker pull clockworklabs/spacetimedb:$TAG-arm64 --platform arm64 >/dev/null 2>&1; then
if docker pull "${IMAGE_NAME}":$TAG-amd64 --platform amd64 >/dev/null 2>&1 && docker pull "${IMAGE_NAME}":$TAG-arm64 --platform arm64 >/dev/null 2>&1; then
echo "Both images exist, preparing the merged manifest"
else
echo "One or both images do not exist. Exiting"
exit 0
fi

# Extract digests
AMD64_DIGEST=$(docker manifest inspect clockworklabs/spacetimedb:$TAG-amd64 | jq -r '.manifests[0].digest')
ARM64_DIGEST=$(docker manifest inspect clockworklabs/spacetimedb:$TAG-arm64 | jq -r '.manifests[0].digest')

FULL_TAG="$SHORT_SHA-full"
AMD64_DIGEST=$(docker manifest inspect "${IMAGE_NAME}":$TAG-amd64 | jq -r '.manifests[0].digest')
ARM64_DIGEST=$(docker manifest inspect "${IMAGE_NAME}":$TAG-arm64 | jq -r '.manifests[0].digest')

# Create a new manifest using extracted digests
docker manifest create clockworklabs/spacetimedb:$FULL_TAG \
clockworklabs/spacetimedb@$AMD64_DIGEST \
clockworklabs/spacetimedb@$ARM64_DIGEST
docker manifest create "${IMAGE_NAME}":$FULL_TAG \
"${IMAGE_NAME}"@$AMD64_DIGEST \
"${IMAGE_NAME}"@$ARM64_DIGEST

# Annotate the manifest with with proper platforms
docker manifest annotate clockworklabs/spacetimedb:$FULL_TAG \
clockworklabs/spacetimedb@$ARM64_DIGEST --os linux --arch arm64
docker manifest annotate clockworklabs/spacetimedb:$FULL_TAG \
clockworklabs/spacetimedb@$AMD64_DIGEST --os linux --arch amd64

# Push the manifest
docker manifest push clockworklabs/spacetimedb:$FULL_TAG

# re-tag the manifeast with a tag
VERSION=${GITHUB_REF#refs/*/}
docker buildx imagetools create clockworklabs/spacetimedb:$FULL_TAG --tag clockworklabs/spacetimedb:$VERSION
docker manifest annotate "${IMAGE_NAME}":$FULL_TAG \
"${IMAGE_NAME}"@$ARM64_DIGEST --os linux --arch arm64
docker manifest annotate "${IMAGE_NAME}":$FULL_TAG \
"${IMAGE_NAME}"@$AMD64_DIGEST --os linux --arch amd64

docker manifest push "${IMAGE_NAME}":$FULL_TAG

# if undefined, use the empty string
GITHUB_REF="${GITHUB_REF-}"
# re-tag the manifest with the GitHub ref
echo "GITHUB_REF is ${GITHUB_REF}"
ORIGINAL_VERSION=${GITHUB_REF#refs/*/}
VERSION=$(sanitize_docker_ref "$ORIGINAL_VERSION")
echo "Tagging image with sanitized GITHUB_REF: $VERSION (original: $ORIGINAL_VERSION)"
docker buildx imagetools create "${IMAGE_NAME}":$FULL_TAG --tag "${IMAGE_NAME}":$VERSION

echo "Image merging and tagging completed successfully."
Loading