Skip to content

Commit 8ee61b8

Browse files
authored
feat(build): Build multi-architecture docker images for aztec-sandbox (#2305)
This PR builds and deploys multi-architecture docker images for aztec-sandbox # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist).
1 parent 26ab88f commit 8ee61b8

File tree

9 files changed

+244
-21
lines changed

9 files changed

+244
-21
lines changed

.circleci/config.yml

+59-7
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ jobs:
572572
name: "Build and test"
573573
command: build aztec-rpc
574574

575-
aztec-sandbox:
575+
aztec-sandbox-base:
576576
machine:
577577
image: ubuntu-2004:202010-01
578578
resource_class: large
@@ -581,7 +581,40 @@ jobs:
581581
- *setup_env
582582
- run:
583583
name: "Build and test"
584-
command: force_deploy_build aztec-sandbox
584+
command: force_deploy_build aztec-sandbox-base false
585+
586+
aztec-sandbox-x86_64:
587+
machine:
588+
image: ubuntu-2004:202010-01
589+
resource_class: large
590+
steps:
591+
- *checkout
592+
- *setup_env
593+
- run:
594+
name: "Build and test"
595+
command: force_deploy_build aztec-sandbox false x86_64
596+
597+
aztec-sandbox-arm64:
598+
machine:
599+
image: ubuntu-2204:2023.07.1
600+
resource_class: arm.large
601+
steps:
602+
- *checkout
603+
- *setup_env
604+
- run:
605+
name: "Build and test"
606+
command: force_deploy_build aztec-sandbox false arm64
607+
608+
aztec-sandbox-ecr-manifest:
609+
machine:
610+
image: ubuntu-2004:202010-01
611+
resource_class: large
612+
steps:
613+
- *checkout
614+
- *setup_env
615+
- run:
616+
name: "Create ECR manifest"
617+
command: create_ecr_manifest aztec-sandbox-base aztec-sandbox x86_64,arm64
585618

586619
circuits-js:
587620
machine:
@@ -1146,6 +1179,7 @@ jobs:
11461179
command: |
11471180
deploy_ecr aztec-sandbox
11481181
deploy_npm aztec-sandbox
1182+
11491183
deploy-dockerhub:
11501184
machine:
11511185
image: ubuntu-2004:202010-01
@@ -1157,8 +1191,11 @@ jobs:
11571191
name: "deploy-sandbox"
11581192
working_directory: aztec-sandbox
11591193
command: |
1160-
deploy_ecr aztec-sandbox
1161-
deploy_dockerhub aztec-sandbox
1194+
deploy_ecr aztec-sandbox x86_64
1195+
deploy_ecr aztec-sandbox arm64
1196+
deploy_dockerhub aztec-sandbox x86_64
1197+
deploy_dockerhub aztec-sandbox arm64
1198+
create_dockerhub_manifest aztec-sandbox x86_64,arm64
11621199
11631200
deploy-end:
11641201
docker:
@@ -1373,9 +1410,24 @@ workflows:
13731410
- types: *yarn_project
13741411
- circuits-js: *yarn_project
13751412
- rollup-provider: *yarn_project
1376-
- aztec-sandbox: *yarn_project
1413+
- aztec-sandbox-base: *yarn_project
13771414
- canary: *yarn_project
13781415

1416+
- aztec-sandbox-x86_64:
1417+
requires:
1418+
- aztec-sandbox-base
1419+
<<: *defaults
1420+
- aztec-sandbox-arm64:
1421+
requires:
1422+
- aztec-sandbox-base
1423+
<<: *defaults
1424+
1425+
- aztec-sandbox-ecr-manifest:
1426+
requires:
1427+
- aztec-sandbox-x86_64
1428+
- aztec-sandbox-arm64
1429+
<<: *defaults
1430+
13791431
- e2e-join:
13801432
requires:
13811433
- aztec-js
@@ -1399,7 +1451,7 @@ workflows:
13991451
- types
14001452
- circuits-js
14011453
- rollup-provider
1402-
- aztec-sandbox
1454+
- aztec-sandbox-ecr-manifest
14031455
- canary
14041456
<<: *defaults
14051457

@@ -1472,7 +1524,7 @@ workflows:
14721524
- guides-sample-dapp
14731525
<<: *defaults
14741526

1475-
# Deployment and Canary tests
1527+
# Deployment and Canary tests
14761528
- deploy-dockerhub:
14771529
requires:
14781530
- e2e-end

build-system/scripts/build

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set -euo pipefail
2626

2727
REPOSITORY=$1
2828
FORCE_BUILD=${2:-"false"}
29+
ARCH=${3:-""}
2930
DOCKERFILE=$(query_manifest dockerfile $REPOSITORY)
3031
PROJECT_DIR=$(query_manifest projectDir $REPOSITORY)
3132
BUILD_DIR=$(query_manifest buildDir $REPOSITORY)
@@ -34,6 +35,7 @@ echo "Repository: $REPOSITORY"
3435
echo "Working directory: $PWD"
3536
echo "Dockerfile: $DOCKERFILE"
3637
echo "Build directory: $BUILD_DIR"
38+
echo "Arch: $ARCH"
3739

3840
# Fetch images with retries
3941
function fetch_image() {
@@ -112,7 +114,8 @@ for PARENT in $PARENTS; do
112114
echo "Pulling dependency $PARENT_REPO..."
113115
fetch_image $PARENT_IMAGE_URI
114116
# Tag it to look like an official release as that's what we use in Dockerfiles.
115-
retry docker tag $PARENT_IMAGE_URI $ECR_DEPLOY_URL/$PARENT
117+
TAG=$ECR_DEPLOY_URL/$PARENT
118+
retry docker tag $PARENT_IMAGE_URI $TAG
116119
done
117120

118121

@@ -183,6 +186,9 @@ fi
183186

184187
# Build the actual image and give it a commit tag.
185188
IMAGE_COMMIT_URI=$ECR_URL/$REPOSITORY:cache-$CONTENT_HASH
189+
if [[ -n "$ARCH" ]]; then
190+
IMAGE_COMMIT_URI=$IMAGE_COMMIT_URI-$ARCH
191+
fi
186192
echo "Building image: $IMAGE_COMMIT_URI"
187193
# Build our dockerfile, add timing information
188194
docker build -t $IMAGE_COMMIT_URI -f $DOCKERFILE $CACHE_FROM --build-arg COMMIT_TAG=$COMMIT_TAG_VERSION --build-arg ARG_CONTENT_HASH=$CONTENT_HASH . \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
# This script:
3+
# 1. Logs into DockerHub
4+
# 2. Creates 2 manifest lists, the first is version tagged, the second is 'latest' tagged
5+
# 3. Adds the arch specific tagged image to each list
6+
# 4. Pushes the 2 lists
7+
8+
set -eu
9+
10+
if [ -z "$COMMIT_TAG" ]; then
11+
echo "Will only push tagged builds to dockerhub. Skipping."
12+
exit 0
13+
fi
14+
15+
REPOSITORY=$1
16+
ARCH_LIST=$2
17+
18+
echo "Repo: $REPOSITORY"
19+
echo "Arch list: $ARCH_LIST"
20+
21+
ACCOUNT="aztecprotocol"
22+
USERNAME="aztecprotocolci"
23+
24+
COMMIT_TAG_VERSION=$COMMIT_TAG # default unless repo-specific
25+
# Check if it's a repo-specific tag
26+
if [[ "$COMMIT_TAG" == *"/"* ]]; then
27+
REPO_NAME="${COMMIT_TAG%%/*}"
28+
COMMIT_TAG_VERSION="${COMMIT_TAG#*/}"
29+
echo "Tag was made for: $REPO_NAME"
30+
echo "Version: $COMMIT_TAG_VERSION"
31+
32+
# Check if REPO_NAME is equal to REPOSITORY
33+
if [ "$REPO_NAME" != "$REPOSITORY" ]; then
34+
echo "REPO_NAME ($REPO_NAME) does not match REPOSITORY ($REPOSITORY). Exiting..."
35+
exit 1
36+
fi
37+
fi
38+
39+
# Check it's a valid semver.
40+
VERSION=$(npx semver $COMMIT_TAG_VERSION)
41+
if [ -z "$VERSION" ]; then
42+
echo "$COMMIT_TAG_VERSION is not a semantic version."
43+
exit 1
44+
fi
45+
46+
# We now have the tage for each image
47+
IMAGE_TAG=$COMMIT_TAG_VERSION
48+
49+
MANIFEST_DEPLOY_URI=$ACCOUNT/$REPOSITORY:$IMAGE_TAG
50+
MANIFEST_LATEST_URI=$ACCOUNT/$REPOSITORY:latest
51+
52+
# Login to dockerhub.
53+
echo "$DOCKERHUB_PASSWORD" | docker login -u $USERNAME --password-stdin
54+
55+
export DOCKER_CLI_EXPERIMENTAL=enabled
56+
57+
OLD_IFS=$IFS
58+
IFS=','
59+
60+
# For each arch, add the tagged image to 2 manifest lists. One tagged with the version, the other with 'latest'
61+
for A in $ARCH_LIST
62+
do
63+
IMAGE_DEPLOY_URI=$ACCOUNT/$REPOSITORY:$IMAGE_TAG-$A
64+
echo "Adding image $IMAGE_DEPLOY_URI to manifest list $MANIFEST_DEPLOY_URI"
65+
docker manifest create $MANIFEST_DEPLOY_URI \
66+
--amend $IMAGE_DEPLOY_URI
67+
68+
echo "Adding image $IMAGE_DEPLOY_URI to manifest list $MANIFEST_LATEST_URI"
69+
docker manifest create $MANIFEST_LATEST_URI \
70+
--amend $IMAGE_DEPLOY_URI
71+
done
72+
73+
IFS=$OLD_IFS
74+
unset OLD_IFS
75+
76+
echo "Pushing manifest list $MANIFEST_DEPLOY_URI..."
77+
# Push the version tagged list
78+
docker manifest push --purge $MANIFEST_DEPLOY_URI
79+
80+
echo "Pushing manifest list $MANIFEST_LATEST_URI..."
81+
# Push the latest tagged list
82+
docker manifest push --purge $MANIFEST_LATEST_URI
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# This script:
3+
# 1. Logs into ECR and ensures we have the given repository
4+
# 2. Computes the image uri of the cached images for the given repository given the list of architectures
5+
# 3. Creates a manifest list using a platform agnositc image uri, adds each image to it
6+
# 4. Pushes the manifest list
7+
8+
set -e
9+
10+
REPOSITORY=$1
11+
FINAL_IMAGE_NAME=$2
12+
ARCH_LIST=$3
13+
14+
# Ensure ECR repository exists.
15+
retry ensure_repo $REPOSITORY $ECR_REGION refresh_lifecycle
16+
17+
CONTENT_HASH=$(calculate_content_hash $REPOSITORY)
18+
echo "Content hash: $CONTENT_HASH"
19+
20+
FINAL=$ECR_URL/$FINAL_IMAGE_NAME:cache-$CONTENT_HASH
21+
22+
echo "Creating manifest list $FINAL..."
23+
24+
export DOCKER_CLI_EXPERIMENTAL=enabled
25+
26+
OLD_IFS=$IFS
27+
IFS=','
28+
for A in $ARCH_LIST
29+
do
30+
IMAGE=$ECR_URL/$FINAL_IMAGE_NAME:cache-$CONTENT_HASH-$A
31+
echo "Adding image $IMAGE to manifest list"
32+
docker manifest create $FINAL \
33+
--amend $IMAGE
34+
done
35+
IFS=$OLD_IFS
36+
unset OLD_IFS
37+
38+
docker manifest push --purge $FINAL

build-system/scripts/deploy_dockerhub

+24-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,22 @@ if [ -z "$COMMIT_TAG" ]; then
77
fi
88

99
REPOSITORY=$1
10+
ARCH=${2:-""}
11+
12+
echo "Repo: $REPOSITORY"
13+
echo "Arch: $ARCH"
14+
15+
ACCOUNT="aztecprotocol"
16+
USERNAME="aztecprotocolci"
17+
1018
IMAGE_COMMIT_URI=$ECR_DEPLOY_URL/$REPOSITORY:$COMMIT_HASH
11-
IMAGE_LATEST_URI=aztecprotocol/$REPOSITORY:latest
19+
20+
IMAGE_LATEST_URI=$ACCOUNT/$REPOSITORY:latest
21+
if [[ -n "$ARCH" ]]; then
22+
IMAGE_COMMIT_URI=$IMAGE_COMMIT_URI-$ARCH
23+
IMAGE_LATEST_URI=$IMAGE_LATEST_URI-$ARCH
24+
fi
25+
1226
COMMIT_TAG_VERSION=$COMMIT_TAG # default unless repo-specific
1327
# Check if it's a repo-specific tag
1428
if [[ "$COMMIT_TAG" == *"/"* ]]; then
@@ -24,7 +38,10 @@ if [[ "$COMMIT_TAG" == *"/"* ]]; then
2438
fi
2539
fi
2640
IMAGE_TAG=$COMMIT_TAG_VERSION
27-
IMAGE_DEPLOY_URI=aztecprotocol/$REPOSITORY:$IMAGE_TAG
41+
IMAGE_DEPLOY_URI=$ACCOUNT/$REPOSITORY:$IMAGE_TAG
42+
if [[ -n "$ARCH" ]]; then
43+
IMAGE_DEPLOY_URI=$IMAGE_DEPLOY_URI-$ARCH
44+
fi
2845

2946
# Check it's a valid semver.
3047
VERSION=$(npx semver $COMMIT_TAG_VERSION)
@@ -39,13 +56,17 @@ echo "Deploying to dockerhub: $IMAGE_DEPLOY_URI"
3956
retry ensure_repo $REPOSITORY $ECR_DEPLOY_REGION
4057

4158
# Login to dockerhub.
42-
echo "$DOCKERHUB_PASSWORD" | docker login -u aztecprotocolci --password-stdin
59+
echo "$DOCKERHUB_PASSWORD" | docker login -u $USERNAME --password-stdin
4360

61+
echo "Pulling $IMAGE_COMMIT_URI"
4462
# Pull image.
4563
retry docker pull $IMAGE_COMMIT_URI
4664

65+
echo "Tagging $IMAGE_COMMIT_URI as $IMAGE_DEPLOY_URI"
4766
# Tag with commit tag
4867
retry docker tag $IMAGE_COMMIT_URI $IMAGE_DEPLOY_URI
68+
69+
echo "Tagging $IMAGE_COMMIT_URI as $IMAGE_LATEST_URI"
4970
# Tag with :latest
5071
retry docker tag $IMAGE_COMMIT_URI $IMAGE_LATEST_URI
5172

build-system/scripts/deploy_ecr

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
set -eu
33

44
REPOSITORY=$1
5+
ARCH=${2:-""}
56
IMAGE_COMMIT_URI=$(calculate_image_uri $REPOSITORY)
7+
if [[ -n "$ARCH" ]]; then
8+
IMAGE_COMMIT_URI=$IMAGE_COMMIT_URI-$ARCH
9+
fi
610

711
# Login to build region and pull the build.
812
retry ensure_repo $REPOSITORY $ECR_REGION
@@ -11,9 +15,12 @@ retry docker pull $IMAGE_COMMIT_URI > /dev/null 2>&1
1115
# Ensure ECR repository exists in deployment region.
1216
retry ensure_repo $REPOSITORY $ECR_DEPLOY_REGION
1317

14-
# Push image to deployment repo with commit hash tag e.g:
15-
# falafel:deadbeefcafebabe1337c0de
18+
# Push image to deployment repo with commit hash tag and optional architecture e.g:
19+
# falafel:deadbeefcafebabe1337c0de-x86_64
1620
IMAGE_DEPLOY_COMMIT_URI=$ECR_DEPLOY_URL/$REPOSITORY:$COMMIT_HASH
21+
if [[ -n "$ARCH" ]]; then
22+
IMAGE_DEPLOY_COMMIT_URI=$IMAGE_DEPLOY_COMMIT_URI-$ARCH
23+
fi
1724
retry docker tag $IMAGE_COMMIT_URI $IMAGE_DEPLOY_COMMIT_URI
1825
retry docker push $IMAGE_DEPLOY_COMMIT_URI
1926

build-system/scripts/force_deploy_build

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
#
33
# This script forces a build if we're in a deployment run, otherwise runs `build` as usual
44
#
5-
# usage: ./deploy_force_build <repository>
6-
# example: ./deploy_force_build aztec-sandbox
5+
# usage: ./deploy_force_build <repository> <force-build>
6+
# example: ./deploy_force_build aztec-sandbox true
77
set -e
88

99
REPOSITORY=$1
10-
FORCE_BUILD=${2:-"false"}
10+
shift
11+
FORCE_BUILD=$1
12+
shift
1113

1214
# if FORCE_BUILD is already set, just continue with it
1315
if [[ $FORCE_BUILD == 'true' ]]; then
14-
build $REPOSITORY true
16+
build $REPOSITORY true $@
1517
exit 0
1618
fi
1719

@@ -37,12 +39,12 @@ if [[ -n "${COMMIT_TAG:-}" ]]; then
3739
VERSION=$(npx semver $COMMIT_TAG_VERSION)
3840
if [ -z "$VERSION" ]; then
3941
# Not a version tag, build normally
40-
build $REPOSITORY
42+
build $REPOSITORY false $@
4143
else
4244
# Force build
43-
build $REPOSITORY true
45+
build $REPOSITORY true $@
4446
fi
4547
else
4648
# Not a tagged commit, build normally
47-
build $REPOSITORY
49+
build $REPOSITORY false $@
4850
fi

0 commit comments

Comments
 (0)