Skip to content

Commit 7fecb89

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

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
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: 9 additions & 3 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
@@ -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,linux/ppc64le,linux/s390x,${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

templates/config/manifests/bases/clusterserviceversion.yaml.tpl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ metadata:
1212
createdAt: {{.CreatedAt}}
1313
support: {{.Annotations.Support}}
1414
certified: {{.Annotations.IsCertified}}
15+
labels:
16+
operatorframework.io/arch.s390x: supported
17+
operatorframework.io/arch.amd64: supported
18+
operatorframework.io/arch.ppc64le: supported
19+
operatorframework.io/arch.arm64: supported
20+
operatorframework.io/os.linux: supported
21+
operatorframework.io/os.zos: supported
1522
name: ack-{{.ServicePackageName }}-controller.v0.0.0
1623
namespace: placeholder
1724
spec:
1825
apiservicedefinitions: {}
1926
customresourcedefinitions:
20-
owned:
27+
owned:
2128
{{- range .CRDs}}
2229
- kind: {{ .Kind}}
2330
name: {{ ToLower .Plural }}.{{$.APIGroup}}
@@ -67,4 +74,4 @@ spec:
6774
provider:
6875
name: {{ .Provider.Name }}
6976
url: {{ .Provider.URL }}
70-
version: 0.0.0
77+
version: 0.0.0

0 commit comments

Comments
 (0)