-
Notifications
You must be signed in to change notification settings - Fork 664
Make the tools/merge-docker-images.sh script more generic
#2334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0c3e82d
[bfops/no-docker-branch-tags]: add sanitize_docker_ref
bfops 1a0ba34
[bfops/no-docker-branch-tags]: add IMAGE_NAME param
bfops f6bcb63
[bfops/no-docker-branch-tags]: make TAG and FULL_TAG into params
bfops 333061c
[bfops/no-docker-branch-tags]: tweak output and comments
bfops d7979f0
[bfops/align-merge-script]: tweak
bfops 947d412
[bfops/align-merge-script]: [REVERT THIS] test the script
bfops 46eced7
[bfops/align-merge-script]: revert
bfops f1535d4
[bfops/align-merge-script]: output tweaks
bfops bd85d27
[bfops/align-merge-script]: add set -u
bfops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,49 @@ | ||
| #!/bin/bash | ||
| set -e | ||
| set -u | ||
bfops marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # 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-}" | ||
bfops marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # 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." | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.