Skip to content

Commit

Permalink
fix(sandbox): build script for tagged commits (#2057)
Browse files Browse the repository at this point in the history
Fix build script for the cases where there is a `COMMIT_TAG` variable
present and pass it correctly to the Dockerfile

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [x] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [x] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [x] 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).
  • Loading branch information
spypsy authored Sep 6, 2023
1 parent fbd8b67 commit c9d9722
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 44 deletions.
75 changes: 37 additions & 38 deletions build-system/scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,37 @@ for PARENT in $PARENTS; do
docker tag $PARENT_IMAGE_URI $ECR_DEPLOY_URL/$PARENT
done


# Extract version from commit tag
# Check if there is a commit tag
if [[ -n "$COMMIT_TAG" ]]; then

# 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). Ignoring..."
COMMIT_TAG_VERSION=""
fi
else
COMMIT_TAG_VERSION=$COMMIT_TAG
fi

# We are building a tagged commit. Check it's a valid semver.
VERSION=$(npx semver $COMMIT_TAG_VERSION)
if [ -z "$VERSION" ]; then
COMMIT_TAG_VERSION=""
fi
else
COMMIT_TAG_VERSION=""
fi


# Pull, build and push each named stage to cache.
STAGE_CACHE_FROM=""
CACHE_FROM=""
Expand All @@ -115,48 +146,16 @@ for STAGE in $STAGES; do
STAGE_CACHE_FROM="--cache-from $STAGE_IMAGE_LAST_URI"
fi
fi

echo "Building stage: $STAGE"
STAGE_IMAGE_COMMIT_URI=$ECR_URL/$REPOSITORY:cache-$CONTENT_HASH-$STAGE
# Build our dockerfile, add timing information

# Check if there is a commit tag
if [[ -n "${COMMIT_TAG:-}" ]]; then

# 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). Ignoring..."
COMMIT_TAG_VERSION=""
fi
else
COMMIT_TAG_VERSION=$COMMIT_TAG
fi

# We are building a tagged commit. Check it's a valid semver.
VERSION=$(npx semver $COMMIT_TAG_VERSION)
if [ -z "$VERSION" ]; then
COMMIT_TAG_VERSION=""
fi

# Pass commit tag as build argument if it exists
docker build --target $STAGE $STAGE_CACHE_FROM -t $STAGE_IMAGE_COMMIT_URI -f $DOCKERFILE --build-arg ARG_CONTENT_HASH=$CONTENT_HASH --build-arg DOCKER_TAG=${COMMIT_TAG_VERSION#v} . \
| while read line ; do echo "$(date "+%H:%M:%S")| $line"; done
else
docker build --target $STAGE $STAGE_CACHE_FROM -t $STAGE_IMAGE_COMMIT_URI -f $DOCKERFILE --build-arg ARG_CONTENT_HASH=$CONTENT_HASH . \
| while read line ; do echo "$(date "+%H:%M:%S")| $line"; done

fi

docker build --target $STAGE $STAGE_CACHE_FROM -t $STAGE_IMAGE_COMMIT_URI -f $DOCKERFILE --build-arg COMMIT_TAG=$COMMIT_TAG_VERSION --build-arg ARG_CONTENT_HASH=$CONTENT_HASH . \
| while read line ; do echo "$(date "+%H:%M:%S")| $line"; done

# We don't want to have redo this stages work when building the final image. Use it as a layer cache.
CACHE_FROM="--cache-from $STAGE_IMAGE_COMMIT_URI $CACHE_FROM"

echo "Pushing stage: $STAGE"
docker push $STAGE_IMAGE_COMMIT_URI > /dev/null 2>&1
echo
Expand All @@ -175,7 +174,7 @@ fi
IMAGE_COMMIT_URI=$ECR_URL/$REPOSITORY:cache-$CONTENT_HASH
echo "Building image: $IMAGE_COMMIT_URI"
# Build our dockerfile, add timing information
docker build -t $IMAGE_COMMIT_URI -f $DOCKERFILE $CACHE_FROM --build-arg COMMIT_TAG=$COMMIT_TAG --build-arg ARG_CONTENT_HASH=$CONTENT_HASH . \
docker build -t $IMAGE_COMMIT_URI -f $DOCKERFILE $CACHE_FROM --build-arg COMMIT_TAG=$COMMIT_TAG_VERSION --build-arg ARG_CONTENT_HASH=$CONTENT_HASH . \
| while read line ; do echo "$(date "+%H:%M:%S")| $line"; done
echo "Pushing image: $IMAGE_COMMIT_URI"
docker push $IMAGE_COMMIT_URI > /dev/null 2>&1
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/aztec-sandbox/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder

ARG DOCKER_TAG
ARG COMMIT_TAG=""

# Remove SRS files (currently not producing proofs)
RUN rm -rf /usr/src/circuits/cpp/barretenberg/cpp/srs_db/ignition/monomial
COPY . .

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

WORKDIR /usr/src/yarn-project/aztec-sandbox
RUN ls
RUN if [[ -n "${DOCKER_TAG}" ]]; then \
jq --arg v ${DOCKER_TAG} '.version = $v' package.json > _temp && mv _temp package.json; \
RUN if [[ -n "${COMMIT_TAG}" ]]; then \
jq --arg v ${COMMIT_TAG} '.version = $v' package.json > _temp && mv _temp package.json; \
fi

RUN yarn build && yarn formatting && yarn test
Expand Down

0 comments on commit c9d9722

Please sign in to comment.