Skip to content

Commit

Permalink
refactor: ecr login retry (#4617)
Browse files Browse the repository at this point in the history
* Refactors the retry logic out of ecr_login and dockerhub_login in
favour of using our `retry` wrapper script.
* Makes our `bootstrap_docker.sh` script check if there are any aws
credentials first, before attempting to use ecr to skip build.

---------

Co-authored-by: ludamad <adam.domurad@gmail.com>
  • Loading branch information
charlielye and ludamad committed Feb 15, 2024
1 parent c9e6bb1 commit c3a784f
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build-system/scripts/build_local
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ for E in "${PROJECTS[@]}"; do
echo -e "${GREEN}Image exists locally. Tagging as $DEPLOY_IMAGE_URI${RESET}"
docker tag $CACHE_IMAGE_URI $DEPLOY_IMAGE_URI
else
if [ -z "$NO_CACHE" ] && ecr_login && image_exists $REPO $TAG ; then
if [ -z "$NO_CACHE" ] && [ -f ~/.aws/credentials ] && ecr_login && image_exists $REPO $TAG ; then
docker pull $CACHE_IMAGE_URI
else
docker build ${ADDITIONAL_ARGS:-} --build-arg ARG_COMMIT_HASH=$COMMIT_HASH -f $DOCKERFILE -t $CACHE_IMAGE_URI .
Expand Down
2 changes: 1 addition & 1 deletion build-system/scripts/cond_run_compose
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ echo "Success tag: $SUCCESS_TAG"

if ! check_rebuild $SUCCESS_TAG $REPOSITORY; then
# Login to pull our ecr images with docker.
ecr_login
retry ecr_login

# For each dependency and self, pull in the latest image and give it correct tag.
for REPO in $(query_manifest runDependencies $REPOSITORY $JOB_NAME); do
Expand Down
2 changes: 1 addition & 1 deletion build-system/scripts/cond_run_container
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "Success tag: $SUCCESS_TAG"
if ! check_rebuild $SUCCESS_TAG $REPOSITORY; then
IMAGE_URI=$(calculate_image_uri $REPOSITORY)
# Login to pull our ecr images with docker.
ecr_login
retry ecr_login
retry docker pull $IMAGE_URI
docker run --rm -t $IMAGE_URI $@
retry tag_remote_image $REPOSITORY $BASE_TAG $SUCCESS_TAG
Expand Down
2 changes: 1 addition & 1 deletion build-system/scripts/create_ecr_manifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -eu
REPOSITORY=$1
ARCH_LIST=$2

ecr_login
retry ecr_login

CONTENT_HASH=$(calculate_content_hash $REPOSITORY)
MULTIARCH_IMAGE_URI=$ECR_URL/$REPOSITORY:cache-$CONTENT_HASH
Expand Down
4 changes: 2 additions & 2 deletions build-system/scripts/deploy_dockerhub
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ else
fi

# Login to dockerhub and ecr
dockerhub_login
ecr_login
retry dockerhub_login
retry ecr_login

# Install skopeo, and immediately hack it to newer version.
sudo apt install -y skopeo
Expand Down
9 changes: 2 additions & 7 deletions build-system/scripts/dockerhub_login
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#!/usr/bin/env bash
set -eu
# Retries up to 3 times with 10 second intervals
for i in $(seq 1 3); do
echo "$DOCKERHUB_PASSWORD" | docker login -u $DOCKERHUB_USERNAME --password-stdin && exit || sleep 10
done
echo "$@ failed dockerhub_login after 3 attempts"
exit 1
set -euo pipefail
echo "$DOCKERHUB_PASSWORD" | docker login -u $DOCKERHUB_USERNAME --password-stdin
12 changes: 3 additions & 9 deletions build-system/scripts/ecr_login
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/usr/bin/env bash
set -eu
set -euo pipefail
REGION=${1:-$ECR_REGION}
# Retries up to 3 times with 10 second intervals
for i in $(seq 1 3); do
aws ecr get-login-password --region $REGION \
| docker login --username AWS --password-stdin $AWS_ACCOUNT.dkr.ecr.$REGION.amazonaws.com 2> /dev/null \
&& exit || sleep 10
done
echo "$@ failed ecr_login after 3 attempts"
exit 1
aws ecr get-login-password --region $REGION \
| docker login --username AWS --password-stdin $AWS_ACCOUNT.dkr.ecr.$REGION.amazonaws.com 2> /dev/null
2 changes: 1 addition & 1 deletion build-system/scripts/ensure_repo
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ REGION=$2
REFRESH_LIFECYCLE=${3:-}

# Login to ECR.
ecr_login $REGION
retry ecr_login $REGION

# Create the repository if it doesn't exist.
if ! aws ecr describe-repositories --region $REGION --repository-names $REPOSITORY > /dev/null 2>&1; then
Expand Down
6 changes: 3 additions & 3 deletions build-system/scripts/extract_repo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ shift

IMAGE_COMMIT_URI=$(calculate_image_uri $REPOSITORY)
echo "Pulling $IMAGE_COMMIT_URI..."
ecr_login
retry ecr_login
retry docker pull $IMAGE_COMMIT_URI
TEMP_CONTAINER=$(docker create $IMAGE_COMMIT_URI dummy_cmd)

Expand All @@ -23,9 +23,9 @@ function extract_from_temp_container {
}

# Default to extracting the entire /usr/src dir
if [ $# -eq 0 ]; then
if [ $# -eq 0 ]; then
extract_from_temp_container /usr/src ./
else
else
while [ $# -gt 0 ]; do
extract_from_temp_container $1 $2
shift 2
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ RUN forge install --no-commit \
RUN forge clean && forge fmt --check && forge build && forge test
RUN yarn && yarn lint
RUN git add . && yarn slither && yarn slither-has-diff
RUN forge build
RUN forge build
2 changes: 1 addition & 1 deletion l1-contracts/scripts/ci_deploy_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if check_rebuild "cache-$CONTENT_HASH-$DEPLOY_TAG-deployed" $REPOSITORY; then
fi

# Login to pull our ecr images with docker.
ecr_login
retry ecr_login

# Contract addresses will be saved in the serve directory
mkdir -p serve
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/scripts/run_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eu

export PATH="$PATH:$(git rev-parse --show-toplevel)/build-system/scripts"

ecr_login
retry ecr_login

REPO="yarn-project"
retry docker pull $(calculate_image_uri $REPO)
Expand Down

0 comments on commit c3a784f

Please sign in to comment.