diff --git a/scripts/push-to-ecr.sh b/scripts/push-to-ecr.sh index 5d6fe9c..76c941c 100755 --- a/scripts/push-to-ecr.sh +++ b/scripts/push-to-ecr.sh @@ -16,12 +16,17 @@ AWS_REGIONS=("us-east-1") # List of AWS region, use below liest if you don't ena build_and_push_images() { local IMAGE_NAME=$1 local TAG=$2 + local ENABLE_MULTI_ARCH=${3:-true} # a parameter for enabling multi-arch build or not, the default is true # Build Docker image for each architecture - for ARCH in "${ARCHS[@]}" - do - docker buildx build --platform linux/$ARCH -t $IMAGE_NAME:$TAG-$ARCH -f ../src/Dockerfile_ecs --load ../src/ - done + if [ "$ENABLE_MULTI_ARCH" == "true" ]; then + for ARCH in "${ARCHS[@]}" + do + docker buildx build --platform linux/$ARCH -t $IMAGE_NAME:$TAG-$ARCH -f ../src/Dockerfile_ecs --load ../src/ + done + else + docker buildx build --platform linux/${ARCHS[0]} -t $IMAGE_NAME:$TAG -f ../src/Dockerfile_ecs --load ../src/ + fi # Push Docker image to ECR for each architecture in each AWS region for REGION in "${AWS_REGIONS[@]}" @@ -39,24 +44,31 @@ build_and_push_images() { aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $REPOSITORY_URI # Push the image to ECR for each architecture - for ARCH in "${ARCHS[@]}" - do - # Tag the image for the current region - docker tag $IMAGE_NAME:$TAG-$ARCH $REPOSITORY_URI:$TAG-$ARCH - # Push the image to ECR - docker push $REPOSITORY_URI:$TAG-$ARCH - # Create a manifest for the image - docker manifest create $REPOSITORY_URI:$TAG $REPOSITORY_URI:$TAG-$ARCH --amend - # Annotate the manifest with architecture information - docker manifest annotate $REPOSITORY_URI:$TAG "$REPOSITORY_URI:$TAG-$ARCH" --os linux --arch $ARCH - done + if [ "$ENABLE_MULTI_ARCH" == "true" ]; then + for ARCH in "${ARCHS[@]}" + do + # Tag the image for the current region + docker tag $IMAGE_NAME:$TAG-$ARCH $REPOSITORY_URI:$TAG-$ARCH + # Push the image to ECR + docker push $REPOSITORY_URI:$TAG-$ARCH + # Create a manifest for the image + docker manifest create $REPOSITORY_URI:$TAG $REPOSITORY_URI:$TAG-$ARCH --amend + # Annotate the manifest with architecture information + docker manifest annotate $REPOSITORY_URI:$TAG "$REPOSITORY_URI:$TAG-$ARCH" --os linux --arch $ARCH + done - # Push the manifest to ECR - docker manifest push $REPOSITORY_URI:$TAG + # Push the manifest to ECR + docker manifest push $REPOSITORY_URI:$TAG + else + # Tag the image for the current region + docker tag $IMAGE_NAME:$TAG $REPOSITORY_URI:$TAG + # Push the image to ECR + docker push $REPOSITORY_URI:$TAG + fi echo "Pushed $IMAGE_NAME:$TAG to $REPOSITORY_URI" done } -build_and_push_images "bedrock-proxy-api" "$TAG" +build_and_push_images "bedrock-proxy-api" "$TAG" "false" build_and_push_images "bedrock-proxy-api-ecs" "$TAG"