Skip to content

Commit 1b3a6c5

Browse files
committed
chore: Support multi platform architecture for container image
Signed-off-by: kahirokunn <[email protected]>
1 parent 5e27da3 commit 1b3a6c5

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Base image to use at runtime
22
ARG base_image=public.ecr.aws/eks-distro-build-tooling/eks-distro-minimal-base-nonroot:2021-12-01-1638322424
33

4+
ARG TARGETARCH
5+
46
# Golang image to use for compiling the manager
57
ARG builder_image=public.ecr.aws/docker/library/golang
68

7-
# Version of Golang
9+
# Version of Golang
810
ARG golang_version
911

1012
# Build the manager binary
@@ -15,14 +17,13 @@ ARG service_alias
1517
ARG service_controller_git_version
1618
ARG service_controller_git_commit
1719
ARG build_date
18-
ARG go_arch=amd64
1920
# The directory within the builder container into which we will copy our
2021
# service controller code.
2122
ARG work_dir=/github.com/aws-controllers-k8s/$service_alias-controller
2223
WORKDIR $work_dir
2324
ENV GOPROXY=https://proxy.golang.org|direct
2425
ENV GO111MODULE=on
25-
ENV GOARCH=$go_arch
26+
ENV GOARCH=$TARGETARCH
2627
ENV GOOS=linux
2728
ENV CGO_ENABLED=0
2829
ENV VERSION_PKG=github.com/aws-controllers-k8s/$service_alias-controller/pkg/version

scripts/build-controller-image.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ DOCKERFILE=${DOCKERFILE:-"$DOCKERFILE_PATH"}
1111
LOCAL_MODULES=${LOCAL_MODULES:-"false"}
1212
BUILD_DATE=$(date +%Y-%m-%dT%H:%M)
1313
QUIET=${QUIET:-"false"}
14+
CONTAINER_OS=${CONTAINER_OS:-"$(go env GOOS)"}
15+
16+
if [ "$CONTAINER_OS" == "darwin" ]; then
17+
CONTAINER_OS="linux"
18+
fi
1419

1520
GOARCH=${GOARCH:-"$(go env GOARCH)"}
1621

@@ -33,7 +38,7 @@ USAGE="
3338
Usage:
3439
$(basename "$0") <aws_service>
3540
36-
Builds the Docker image for an ACK service controller.
41+
Builds the Docker image for an ACK service controller.
3742
3843
Example: $(basename "$0") ecr
3944
@@ -83,10 +88,10 @@ if [[ $QUIET = "false" ]]; then
8388
echo " git commit: $SERVICE_CONTROLLER_GIT_COMMIT"
8489
fi
8590

86-
if ! is_public_ecr_logged_in; then
87-
# Log into ECR public to access base images
88-
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
89-
fi
91+
# if ! is_public_ecr_logged_in; then
92+
# # Log into ECR public to access base images
93+
# aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
94+
# fi
9095

9196
pushd "$ROOT_DIR" 1>/dev/null
9297
# Get the golang version from the code-generator
@@ -100,16 +105,17 @@ if [[ "$LOCAL_MODULES" = "true" ]]; then
100105
DOCKERFILE="${ROOT_DIR}"/Dockerfile.local
101106
fi
102107

103-
if ! docker build \
108+
if ! docker buildx build \
104109
--quiet="${QUIET}" \
105110
-t "${AWS_SERVICE_DOCKER_IMG}" \
106111
-f "${DOCKERFILE}" \
112+
--platform linux/amd64,linux/arm64,${CONTAINER_OS}/${GOARCH} \
113+
--output=type=image \
107114
--build-arg service_alias="${AWS_SERVICE}" \
108115
--build-arg service_controller_git_version="$SERVICE_CONTROLLER_GIT_VERSION" \
109116
--build-arg service_controller_git_commit="$SERVICE_CONTROLLER_GIT_COMMIT" \
110117
--build-arg build_date="$BUILD_DATE" \
111118
--build-arg golang_version="${GOLANG_VERSION}" \
112-
--build-arg go_arch="$GOARCH" \
113119
"${DOCKER_BUILD_CONTEXT}"; then
114120
exit 2
115121
fi

0 commit comments

Comments
 (0)