Skip to content

Commit 10fc944

Browse files
committed
feat: support build arm64 image
1 parent 296f999 commit 10fc944

File tree

1 file changed

+56
-18
lines changed

1 file changed

+56
-18
lines changed

server/scripts/push-to-ecr.sh

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ build_and_push_image() {
9797
local TAG=$2
9898
local DOCKERFILE_PATH=$3
9999
local REGION=$AWS_REGION
100-
local ARCH="amd64" # Single architecture for simplicity
100+
local ARCHS=("amd64" "arm64") # Build for both architectures
101101

102102
echo "Logging in to AWS Public ECR..."
103103
# Log in to AWS Public ECR for pulling base images
@@ -106,13 +106,21 @@ build_and_push_image() {
106106
exit 1
107107
fi
108108

109-
echo "Building $IMAGE_NAME:$TAG..."
109+
echo "Building multi-architecture images (amd64 and arm64)..."
110+
echo "This may take several minutes..."
111+
echo ""
110112

111-
# Build Docker image
112-
if ! docker buildx build --platform linux/$ARCH -t $IMAGE_NAME:$TAG -f $DOCKERFILE_PATH --load ../src/; then
113-
echo "❌ ERROR: Failed to build Docker image."
114-
exit 1
115-
fi
113+
# Build Docker image for each architecture
114+
for ARCH in "${ARCHS[@]}"
115+
do
116+
echo "Building for linux/$ARCH..."
117+
if ! docker buildx build --platform linux/$ARCH -t $IMAGE_NAME:$TAG-$ARCH -f $DOCKERFILE_PATH --load ../src/; then
118+
echo "❌ ERROR: Failed to build Docker image for $ARCH."
119+
exit 1
120+
fi
121+
echo "✅ Built $IMAGE_NAME:$TAG-$ARCH"
122+
done
123+
echo ""
116124

117125
echo "Getting AWS account ID..."
118126
# Get the account ID
@@ -135,21 +143,51 @@ build_and_push_image() {
135143
exit 1
136144
fi
137145

138-
echo "Tagging image for ECR..."
139-
# Tag the image for ECR
140-
if ! docker tag $IMAGE_NAME:$TAG $REPOSITORY_URI:$TAG; then
141-
echo "❌ ERROR: Failed to tag Docker image."
142-
exit 1
143-
fi
146+
echo "Pushing images to ECR..."
147+
# Push the image to ECR for each architecture
148+
for ARCH in "${ARCHS[@]}"
149+
do
150+
echo "Tagging and pushing $ARCH image..."
151+
# Tag the image for ECR
152+
if ! docker tag $IMAGE_NAME:$TAG-$ARCH $REPOSITORY_URI:$TAG-$ARCH; then
153+
echo "❌ ERROR: Failed to tag Docker image for $ARCH."
154+
exit 1
155+
fi
156+
157+
# Push the image to ECR
158+
if ! docker push $REPOSITORY_URI:$TAG-$ARCH; then
159+
echo "❌ ERROR: Failed to push image for $ARCH to ECR."
160+
exit 1
161+
fi
162+
echo "✅ Pushed $REPOSITORY_URI:$TAG-$ARCH"
163+
done
164+
echo ""
144165

145-
echo "Pushing image to ECR..."
146-
# Push the image to ECR
147-
if ! docker push $REPOSITORY_URI:$TAG; then
148-
echo "❌ ERROR: Failed to push image to ECR."
166+
echo "Creating multi-architecture manifest..."
167+
# Create a manifest for the multi-arch image
168+
for ARCH in "${ARCHS[@]}"
169+
do
170+
if ! docker manifest create $REPOSITORY_URI:$TAG $REPOSITORY_URI:$TAG-$ARCH --amend; then
171+
echo "❌ ERROR: Failed to create manifest for $ARCH."
172+
exit 1
173+
fi
174+
175+
# Annotate the manifest with architecture information
176+
if ! docker manifest annotate $REPOSITORY_URI:$TAG "$REPOSITORY_URI:$TAG-$ARCH" --os linux --arch $ARCH; then
177+
echo "❌ ERROR: Failed to annotate manifest for $ARCH."
178+
exit 1
179+
fi
180+
done
181+
182+
echo "Pushing manifest to ECR..."
183+
# Push the manifest to ECR
184+
if ! docker manifest push $REPOSITORY_URI:$TAG; then
185+
echo "❌ ERROR: Failed to push manifest to ECR."
149186
exit 1
150187
fi
151188

152-
echo "✅ Successfully pushed $IMAGE_NAME:$TAG to $REPOSITORY_URI"
189+
echo "✅ Successfully pushed multi-architecture $IMAGE_NAME:$TAG to ECR"
190+
echo " Supported architectures: amd64 (x86_64), arm64"
153191
echo ""
154192

155193
# Return the image URI for later use

0 commit comments

Comments
 (0)