Skip to content

Commit

Permalink
Updated Dockerfile to support multi-arch (#535)
Browse files Browse the repository at this point in the history
* Updated Dockerfile to support multi-arch
Updated Makefile to use docker buildx

* Remove GOPROXY

* Added TARGETOS and TARGETARCH as ARG

* minor change
  • Loading branch information
cgchinmay authored Nov 19, 2021
1 parent 4805591 commit 15258a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# syntax=docker/dockerfile:experimental

# Build the controller binary
FROM golang:1.14 as builder
FROM --platform=${TARGETPLATFORM} golang:1.16 as builder

WORKDIR /workspace

Expand All @@ -8,12 +10,15 @@ COPY . ./
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

ARG TARGETOS
ARG TARGETARCH

# Build
ENV VERSION_PKG=github.com/aws/aws-app-mesh-controller-for-k8s/pkg/version
RUN GIT_VERSION=$(git describe --tags --dirty --always) && \
GIT_COMMIT=$(git rev-parse HEAD) && \
BUILD_DATE=$(date +%Y-%m-%dT%H:%M:%S%z) && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GO111MODULE=on go build \
-ldflags="-X ${VERSION_PKG}.GitVersion=${GIT_VERSION} -X ${VERSION_PKG}.GitCommit=${GIT_COMMIT} -X ${VERSION_PKG}.BuildDate=${BUILD_DATE}" -a -o controller main.go

# Build the container image
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

# Build the docker image
# Requires buildx to be installed: https://docs.docker.com/buildx/working-with-buildx/
# By default the TARGETPLATFORM is set to linux/amd64, change the value if you are building for linux/arm64
docker-build: check-env test
docker build . -t $(IMAGE)
docker buildx build --platform linux/amd64 -t $(IMAGE) . --load

docker-push: check-env
docker push $(IMAGE)
Expand Down Expand Up @@ -132,7 +134,7 @@ endif
check-env:
@:$(call check_var, AWS_ACCOUNT, AWS account ID for publishing docker images)
@:$(call check_var, AWS_REGION, AWS region for publishing docker images)

check_var = \
$(strip $(foreach 1,$1, \
$(call __check_var,$1,$(strip $(value 2)))))
Expand Down

0 comments on commit 15258a1

Please sign in to comment.