Skip to content

Commit

Permalink
support arch arg in dockerfile (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
haouc committed Apr 26, 2023
1 parent ecbd696 commit 0c6381a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ARG BASE_IMAGE
ARG BUILD_IMAGE
ARG ARCH=amd64
# Build the controller binary
FROM $BUILD_IMAGE as builder

Expand Down Expand Up @@ -27,7 +28,7 @@ ENV VERSION_PKG=github.com/aws/amazon-vpc-resource-controller-k8s/pkg/version
RUN GIT_VERSION=$(git describe --tags --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=linux GOARCH=${ARCH} 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

FROM $BASE_IMAGE
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ BASE_IMAGE ?= public.ecr.aws/eks-distro-build-tooling/eks-distro-minimal-base-no
BUILD_IMAGE ?= public.ecr.aws/bitnami/golang:1.20.1
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
GOARCH ?= amd64
PLATFORM ?= linux/amd64


# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
Expand Down Expand Up @@ -68,6 +70,10 @@ vet:
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="scripts/templates/boilerplate.go.txt" paths="./..."

# Build the docker image with buildx
docker-buildx: check-env test
docker buildx build --platform=$(PLATFORM) -t $(IMAGE)-$(GOARCH) --build-arg BASE_IMAGE=$(BASE_IMAGE) --build-arg BUILD_IMAGE=$(BUILD_IMAGE) --build-arg $(GOARCH) --load .

# Build the docker image
docker-build: check-env test
docker build --build-arg BASE_IMAGE=$(BASE_IMAGE) --build-arg BUILD_IMAGE=$(BUILD_IMAGE) . -t ${IMAGE}
Expand Down

0 comments on commit 0c6381a

Please sign in to comment.