Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Moved ECR pruning to after all build services have succeeded.
Browse files Browse the repository at this point in the history
Prior behavior was to prune images for a service after that
service had built successfully. This still had holes in the
logic of which ones to remove, and sometimes several builds
that had e.g. a failing client build would prune still-in-use
api images, leading to the cluster being in a state where it
had to run an older version of the code but the images with
that code were gone.

Now, prune_ecr_images is only run if every build has succeeded,
which should prevent any pruning of images that need to still
be used.

Resolves IR-3455
  • Loading branch information
barankyle committed Aug 17, 2024
1 parent 64f7afd commit 6353e4a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
6 changes: 0 additions & 6 deletions scripts/build_and_publish_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,5 @@ else
--build-arg VITE_ZENDESK_AUTHENTICATION_ENABLED=$VITE_ZENDESK_AUTHENTICATION_ENABLED .
fi

if [ $PRIVATE_REPO == "true" ]; then
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-$PACKAGE --region $REGION --service $PACKAGE --releaseName $STAGE
else
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-$PACKAGE --region us-east-1 --service $PACKAGE --releaseName $STAGE --public
fi

BUILD_END_TIME=$(date +"%d-%m-%yT%H-%M-%S")
echo "${PACKAGE} build started at ${BUILD_START_TIME}, ended at ${BUILD_END_TIME}"
52 changes: 52 additions & 0 deletions scripts/run-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ then
npm run record-build-error -- --service=instanceserver --isDocker=true
npm run record-build-error -- --service=taskserver --isDocker=true
#npm run record-build-error -- --service=testbot --isDocker=true

if [ $DESTINATION_REPO_PROVIDER == "aws" ]
then
echo "SHOULD PRUNE ECR IMAGES"
if [ $PRIVATE_REPO == "true" ]
then
echo "PRUNING PRIVATE REPOS"
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-api --region $AWS_REGION --service api --releaseName $RELEASE_NAME
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-client --region $AWS_REGION --service client --releaseName $RELEASE_NAME
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-instanceserver --region $AWS_REGION --service instanceserver --releaseName $RELEASE_NAME
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-taskserver --region $AWS_REGION --service taskserver --releaseName $RELEASE_NAME
else
echo "PRUNING PUBLIC REPOS"
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-api --region us-east-1 --service api --releaseName $RELEASE_NAME --public
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-client --region us-east-1 --service client --releaseName $RELEASE_NAME --public
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-instanceserver --region us-east-1 --service instancserver --releaseName $RELEASE_NAME --public
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-taskserver --region us-east-1 --service taskserver --releaseName $RELEASE_NAME --public
fi
fi
elif [ "$SERVE_CLIENT_FROM_API" = "true" ]
then
bash ./scripts/build_and_publish_package.sh $RELEASE_NAME api api-client $START_TIME $AWS_REGION $NODE_ENV $DESTINATION_REPO_PROVIDER $PRIVATE_REPO >api-build-logs.txt 2>api-build-error.txt &
Expand All @@ -78,6 +97,23 @@ then
npm run record-build-error -- --service=instanceserver --isDocker=true
npm run record-build-error -- --service=taskserver --isDocker=true
#npm run record-build-error -- --service=testbot --isDocker=true

if [ $DESTINATION_REPO_PROVIDER == "aws" ]
then
echo "SHOULD PRUNE ECR IMAGES"
if [ $PRIVATE_REPO == "true" ]
then
echo "PRUNING PRIVATE REPOS"
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-api --region $AWS_REGION --service api --releaseName $RELEASE_NAME
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-instanceserver --region $AWS_REGION --service instanceserver --releaseName $RELEASE_NAME
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-taskserver --region $AWS_REGION --service taskserver --releaseName $RELEASE_NAME
else
echo "PRUNING PUBLIC REPOS"
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-api --region us-east-1 --service api --releaseName $RELEASE_NAME --public
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-instanceserver --region us-east-1 --service instancserver --releaseName $RELEASE_NAME --public
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-taskserver --region us-east-1 --service taskserver --releaseName $RELEASE_NAME --public
fi
fi
else
bash ./scripts/build_and_publish_package.sh $RELEASE_NAME api api $START_TIME $AWS_REGION $NODE_ENV $DESTINATION_REPO_PROVIDER $PRIVATE_REPO >api-build-logs.txt 2>api-build-error.txt &
bash ./scripts/build_and_publish_package.sh $RELEASE_NAME client client $START_TIME $AWS_REGION $NODE_ENV $DESTINATION_REPO_PROVIDER $PRIVATE_REPO >client-build-logs.txt 2>client-build-error.txt &
Expand All @@ -92,6 +128,22 @@ else
npm run record-build-error -- --service=instanceserver --isDocker=true
npm run record-build-error -- --service=taskserver --isDocker=true
#npm run record-build-error -- --service=testbot --isDocker=true

if [ $DESTINATION_REPO_PROVIDER == "aws" ]
then
if [ $PRIVATE_REPO == "true" ]
then
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-api --region $AWS_REGION --service api --releaseName $RELEASE_NAME
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-client --region $AWS_REGION --service client --releaseName $RELEASE_NAME
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-instanceserver --region $AWS_REGION --service instanceserver --releaseName $RELEASE_NAME
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-taskserver --region $AWS_REGION --service taskserver --releaseName $RELEASE_NAME
else
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-api --region us-east-1 --service api --releaseName $RELEASE_NAME --public
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-client --region us-east-1 --service client --releaseName $RELEASE_NAME --public
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-instanceserver --region us-east-1 --service instancserver --releaseName $RELEASE_NAME --public
npx ts-node ./scripts/prune_ecr_images.ts --repoName $DESTINATION_REPO_NAME_STEM-taskserver --region us-east-1 --service taskserver --releaseName $RELEASE_NAME --public
fi
fi
fi

bash ./scripts/deploy.sh $RELEASE_NAME ${TAG}__${START_TIME}
Expand Down

0 comments on commit 6353e4a

Please sign in to comment.