-
Notifications
You must be signed in to change notification settings - Fork 236
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
feat(build): Build multi-architecture docker images for aztec-sandbox #2305
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/bin/bash | ||
# This script: | ||
# 1. Logs into DockerHub | ||
# 2. Creates 2 manifest lists, the first is version tagged, the second is 'latest' tagged | ||
# 3. Adds the arch specific tagged image to each list | ||
# 4. Pushes the 2 lists | ||
|
||
set -eu | ||
|
||
if [ -z "$COMMIT_TAG" ]; then | ||
echo "Will only push tagged builds to dockerhub. Skipping." | ||
exit 0 | ||
fi | ||
|
||
REPOSITORY=$1 | ||
ARCH_LIST=$2 | ||
|
||
echo "Repo: $REPOSITORY" | ||
echo "Arch list: $ARCH_LIST" | ||
|
||
ACCOUNT="aztecprotocol" | ||
USERNAME="aztecprotocolci" | ||
|
||
COMMIT_TAG_VERSION=$COMMIT_TAG # default unless repo-specific | ||
# Check if it's a repo-specific tag | ||
if [[ "$COMMIT_TAG" == *"/"* ]]; then | ||
REPO_NAME="${COMMIT_TAG%%/*}" | ||
COMMIT_TAG_VERSION="${COMMIT_TAG#*/}" | ||
echo "Tag was made for: $REPO_NAME" | ||
echo "Version: $COMMIT_TAG_VERSION" | ||
|
||
# Check if REPO_NAME is equal to REPOSITORY | ||
if [ "$REPO_NAME" != "$REPOSITORY" ]; then | ||
echo "REPO_NAME ($REPO_NAME) does not match REPOSITORY ($REPOSITORY). Exiting..." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# Check it's a valid semver. | ||
VERSION=$(npx semver $COMMIT_TAG_VERSION) | ||
if [ -z "$VERSION" ]; then | ||
echo "$COMMIT_TAG_VERSION is not a semantic version." | ||
exit 1 | ||
fi | ||
|
||
# We now have the tage for each image | ||
IMAGE_TAG=$COMMIT_TAG_VERSION | ||
|
||
MANIFEST_DEPLOY_URI=$ACCOUNT/$REPOSITORY:$IMAGE_TAG | ||
MANIFEST_LATEST_URI=$ACCOUNT/$REPOSITORY:latest | ||
|
||
# Login to dockerhub. | ||
echo "$DOCKERHUB_PASSWORD" | docker login -u $USERNAME --password-stdin | ||
|
||
export DOCKER_CLI_EXPERIMENTAL=enabled | ||
|
||
OLD_IFS=$IFS | ||
IFS=',' | ||
|
||
# For each arch, add the tagged image to 2 manifest lists. One tagged with the version, the other with 'latest' | ||
for A in $ARCH_LIST | ||
do | ||
IMAGE_DEPLOY_URI=$ACCOUNT/$REPOSITORY:$IMAGE_TAG-$A | ||
echo "Adding image $IMAGE_DEPLOY_URI to manifest list $MANIFEST_DEPLOY_URI" | ||
docker manifest create $MANIFEST_DEPLOY_URI \ | ||
--amend $IMAGE_DEPLOY_URI | ||
|
||
echo "Adding image $IMAGE_DEPLOY_URI to manifest list $MANIFEST_LATEST_URI" | ||
docker manifest create $MANIFEST_LATEST_URI \ | ||
--amend $IMAGE_DEPLOY_URI | ||
done | ||
|
||
IFS=$OLD_IFS | ||
unset OLD_IFS | ||
|
||
echo "Pushing manifest list $MANIFEST_DEPLOY_URI..." | ||
# Push the version tagged list | ||
docker manifest push --purge $MANIFEST_DEPLOY_URI | ||
|
||
echo "Pushing manifest list $MANIFEST_LATEST_URI..." | ||
# Push the latest tagged list | ||
docker manifest push --purge $MANIFEST_LATEST_URI |
This file contains 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
# This script: | ||
# 1. Logs into ECR and ensures we have the given repository | ||
# 2. Computes the image uri of the cached images for the given repository given the list of architectures | ||
# 3. Creates a manifest list using a platform agnositc image uri, adds each image to it | ||
# 4. Pushes the manifest list | ||
|
||
set -e | ||
|
||
REPOSITORY=$1 | ||
FINAL_IMAGE_NAME=$2 | ||
ARCH_LIST=$3 | ||
|
||
# Ensure ECR repository exists. | ||
retry ensure_repo $REPOSITORY $ECR_REGION refresh_lifecycle | ||
|
||
CONTENT_HASH=$(calculate_content_hash $REPOSITORY) | ||
echo "Content hash: $CONTENT_HASH" | ||
|
||
FINAL=$ECR_URL/$FINAL_IMAGE_NAME:cache-$CONTENT_HASH | ||
|
||
echo "Creating manifest list $FINAL..." | ||
|
||
export DOCKER_CLI_EXPERIMENTAL=enabled | ||
|
||
OLD_IFS=$IFS | ||
IFS=',' | ||
for A in $ARCH_LIST | ||
do | ||
IMAGE=$ECR_URL/$FINAL_IMAGE_NAME:cache-$CONTENT_HASH-$A | ||
echo "Adding image $IMAGE to manifest list" | ||
docker manifest create $FINAL \ | ||
--amend $IMAGE | ||
done | ||
IFS=$OLD_IFS | ||
unset OLD_IFS | ||
|
||
docker manifest push --purge $FINAL |
This file contains 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious, why are we starting to use
shift
for positional args in our scripts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's when you want to pass arguments past a certain point through to child scripts. So in this script, the first 2 args are consumed by this script and then any remaining args are passed to the
build
script via $@ (meaning all the current args).