chore: use arm64 architecture image for lambda

This commit is contained in:
Mengxin Zhu
2024-10-09 23:15:10 +08:00
parent c1ee1b4244
commit 326e566105

View File

@@ -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() { build_and_push_images() {
local IMAGE_NAME=$1 local IMAGE_NAME=$1
local TAG=$2 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 # Build Docker image for each architecture
for ARCH in "${ARCHS[@]}" if [ "$ENABLE_MULTI_ARCH" == "true" ]; then
do for ARCH in "${ARCHS[@]}"
docker buildx build --platform linux/$ARCH -t $IMAGE_NAME:$TAG-$ARCH -f ../src/Dockerfile_ecs --load ../src/ do
done 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 # Push Docker image to ECR for each architecture in each AWS region
for REGION in "${AWS_REGIONS[@]}" 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 aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $REPOSITORY_URI
# Push the image to ECR for each architecture # Push the image to ECR for each architecture
for ARCH in "${ARCHS[@]}" if [ "$ENABLE_MULTI_ARCH" == "true" ]; then
do for ARCH in "${ARCHS[@]}"
# Tag the image for the current region do
docker tag $IMAGE_NAME:$TAG-$ARCH $REPOSITORY_URI:$TAG-$ARCH # Tag the image for the current region
# Push the image to ECR docker tag $IMAGE_NAME:$TAG-$ARCH $REPOSITORY_URI:$TAG-$ARCH
docker push $REPOSITORY_URI:$TAG-$ARCH # Push the image to ECR
# Create a manifest for the image docker push $REPOSITORY_URI:$TAG-$ARCH
docker manifest create $REPOSITORY_URI:$TAG $REPOSITORY_URI:$TAG-$ARCH --amend # Create a manifest for the image
# Annotate the manifest with architecture information docker manifest create $REPOSITORY_URI:$TAG $REPOSITORY_URI:$TAG-$ARCH --amend
docker manifest annotate $REPOSITORY_URI:$TAG "$REPOSITORY_URI:$TAG-$ARCH" --os linux --arch $ARCH # Annotate the manifest with architecture information
done docker manifest annotate $REPOSITORY_URI:$TAG "$REPOSITORY_URI:$TAG-$ARCH" --os linux --arch $ARCH
done
# Push the manifest to ECR # Push the manifest to ECR
docker manifest push $REPOSITORY_URI:$TAG 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" echo "Pushed $IMAGE_NAME:$TAG to $REPOSITORY_URI"
done 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" build_and_push_images "bedrock-proxy-api-ecs" "$TAG"