diff --git a/Dockerfile b/Dockerfile index 6bd20ea..9db5450 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,13 @@ -FROM golang:1.16-alpine as builder +ARG XX_VERSION=1.0.0-rc.2 + +FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx + +FROM --platform=$BUILDPLATFORM golang:1.16-alpine as builder + +# Copy the build utilities. +COPY --from=xx / / + +ARG TARGETPLATFORM WORKDIR /workspace @@ -18,7 +27,8 @@ COPY controllers/ controllers/ COPY internal/ internal/ # build -RUN CGO_ENABLED=0 go build -a -o kustomize-controller main.go +ENV CGO_ENABLED=0 +RUN xx-go build -a -o kustomize-controller main.go FROM alpine:3.14 diff --git a/Makefile b/Makefile index 09107ce..5dd3300 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,11 @@ else GOBIN=$(shell go env GOBIN) endif +# Allows for defining additional Docker buildx arguments, e.g. '--push'. +BUILD_ARGS ?= +# Architectures to build images for. +BUILD_PLATFORMS ?= linux/amd64,linux/arm64,linux/arm/v7 + all: manager # Download the envtest binaries to testbin @@ -94,7 +99,10 @@ generate: controller-gen # Build the docker image docker-build: - docker build . -t ${IMG} + docker buildx build \ + --platform=$(BUILD_PLATFORMS) \ + -t ${IMG} \ + ${BUILD_ARGS} . # Push the docker image docker-push: