Skip to content

Commit

Permalink
chore: Remove sandbox base image and force_deploy_build. Generalise i…
Browse files Browse the repository at this point in the history
…n check_rebuild. (#2645)

Base image not really needed as build happens in yarn-project and we're
just stripping dev deps.
force_deploy_build was workaround for ensuring version number is baked
into image. We should probably just find a way to correctly invalidate
the content hash, but in meantime i've generalised in check_rebuild by
checking if the commit tag is set (i.e. deploying) and the dockerfile
has an `ARG COMMIT_TAG=` in it, which we know will carry this new
version number.
  • Loading branch information
charlielye authored and Maddiaa0 committed Oct 5, 2023
1 parent ddc154a commit 3b7b36c
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 164 deletions.
134 changes: 59 additions & 75 deletions .circleci/config.yml

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions build-system/scripts/calculate_image_uri
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
set -eu

REPOSITORY=$1
# Assume we might be calling this directly without build system in path
export ROOT_PATH=$(git rev-parse --show-toplevel)
export PATH="$PATH:$ROOT_PATH/build-system/scripts:$ROOT_PATH/build-system/bin"
CONTENT_HASH=$(calculate_content_hash $REPOSITORY)
echo "278380418400.dkr.ecr.us-east-2.amazonaws.com/$REPOSITORY:cache-$CONTENT_HASH"
echo "$ECR_URL/$REPOSITORY:cache-$CONTENT_HASH"
14 changes: 12 additions & 2 deletions build-system/scripts/check_rebuild
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ REPOSITORY=$2
[[ "$COMMIT_MESSAGE" == *"[ci rebuild $REPOSITORY]"* ]] && exit 1
[[ "$COMMIT_MESSAGE" == *"[ci rebuild]"* ]] && exit 1

COMMIT_TAG_VERSION=$(extract_tag_version $REPOSITORY)
DOCKERFILE=$(query_manifest dockerfile $REPOSITORY)

# If we are deploying, and our Dockerfile uses the COMMIT_TAG arg, we need to rebuild to ensure the latest version
# number is baked into the image.
# TODO: This should probably be properly handled by e.g. release-please bumping the version number as part of its PR
# which would invalidate the content hash, rather than us using Dockerfile ARGS.
if [ -n "$COMMIT_TAG_VERSION" ] && grep -qE "^ARG COMMIT_TAG=" $DOCKERFILE; then
exit 1
fi

# If the image doesn't exist, we need to rebuild.
if ! image_exists $REPOSITORY $TAG; then
exit 1
else
exit 0
fi
24 changes: 10 additions & 14 deletions build-system/scripts/create_ecr_manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,33 @@
# 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
# 4. Pushes the manifest list

[ -n "${BUILD_SYSTEM_DEBUG:-}" ] && set -x # conditionally trace
set -e
set -eu

REPOSITORY=$1
FINAL_IMAGE_NAME=$2
ARCH_LIST=$3
ARCH_LIST=$2

# Ensure ECR repository exists.
retry ensure_repo $REPOSITORY $ECR_REGION refresh_lifecycle

CONTENT_HASH=$(calculate_content_hash $REPOSITORY)
echo "Content hash: $CONTENT_HASH"
IMAGE_URI=$(calculate_image_uri $REPOSITORY)
echo "Image URI: $IMAGE_URI"

FINAL=$ECR_URL/$FINAL_IMAGE_NAME:cache-$CONTENT_HASH

echo "Creating manifest list $FINAL..."
echo "Creating manifest list..."

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
ARCH_IMAGE=$IMAGE_URI-$A
echo "Adding image $ARCH_IMAGE to manifest list."
docker manifest create $IMAGE_URI --amend $ARCH_IMAGE
done
IFS=$OLD_IFS
unset OLD_IFS

docker manifest push --purge $FINAL
docker manifest push --purge $IMAGE_URI
29 changes: 0 additions & 29 deletions build-system/scripts/force_deploy_build

This file was deleted.

19 changes: 2 additions & 17 deletions build_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,17 @@ yarn-project:
- yarn-project-base
- noir-contracts-build

aztec-sandbox-base:
buildDir: yarn-project
projectDir: yarn-project/aztec-sandbox
dependencies:
- yarn-project

aztec-sandbox:
buildDir: yarn-project
projectDir: yarn-project/aztec-sandbox
dockerfile: Dockerfile.final
dependencies:
- aztec-sandbox-base

pxe-base:
buildDir: yarn-project
projectDir: yarn-project/pxe
dockerfile: Dockerfile
dependencies:
- yarn-project

pxe:
buildDir: yarn-project
projectDir: yarn-project/pxe
dockerfile: Dockerfile.final
dependencies:
- pxe-base
- yarn-project

boxes-blank-react:
buildDir: yarn-project
Expand Down Expand Up @@ -182,4 +167,4 @@ docs:
- ^.*/noir-version.json$
- ^.*.nr$
dependencies:
- yarn-project
- yarn-project
10 changes: 8 additions & 2 deletions yarn-project/aztec-sandbox/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project AS builder
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project AS yarn-project

ARG COMMIT_TAG=""

# Update pxe version if COMMIT_TAG has been used
# Start a new image as we need arch specific.
FROM node:18-alpine as builder
RUN apk add jq
COPY --from=yarn-project /usr/src/ /usr/src/

# Update pxe version if COMMIT_TAG has been used.
WORKDIR /usr/src/yarn-project/pxe
RUN if [[ -n "${COMMIT_TAG}" ]]; then \
jq --arg v ${COMMIT_TAG} '.version = $v' package.json > _temp && mv _temp package.json; \
fi

# Update sandbox version if COMMIT_TAG has been used.
WORKDIR /usr/src/yarn-project/aztec-sandbox
RUN if [[ -n "${COMMIT_TAG}" ]]; then \
jq --arg v ${COMMIT_TAG} '.version = $v' package.json > _temp && mv _temp package.json; \
Expand Down
10 changes: 0 additions & 10 deletions yarn-project/aztec-sandbox/Dockerfile.final

This file was deleted.

7 changes: 6 additions & 1 deletion yarn-project/pxe/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project AS builder
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project AS yarn-project

ARG COMMIT_TAG=""

# Start a new image as we need arch specific.
FROM node:18-alpine as builder
RUN apk add jq
COPY --from=yarn-project /usr/src/ /usr/src/

# Update pxe version if COMMIT_TAG has been used
WORKDIR /usr/src/yarn-project/pxe
RUN if [[ -n "${COMMIT_TAG}" ]]; then \
Expand Down
10 changes: 0 additions & 10 deletions yarn-project/pxe/Dockerfile.final

This file was deleted.

0 comments on commit 3b7b36c

Please sign in to comment.