Use tonistiigi/xx for cross-platform builds
Update the Dockerfile to use tonistiigi/xx to cross-compile the manager binaries natively and speed up the multi-arch image build time. Signed-off-by: Sunny <darkowlzz@protonmail.com>
This commit is contained in:
parent
7eac4bd1dc
commit
d97127efd1
14
Dockerfile
14
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 notification-controller main.go
|
||||
ENV CGO_ENABLED=0
|
||||
RUN xx-go build -a -o notification-controller main.go
|
||||
|
||||
FROM alpine:3.13
|
||||
|
||||
|
|
|
|||
11
Makefile
11
Makefile
|
|
@ -10,6 +10,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
|
||||
|
||||
all: manager
|
||||
|
||||
# Run tests
|
||||
|
|
@ -82,7 +87,11 @@ generate: controller-gen
|
|||
|
||||
# Build the docker image
|
||||
docker-build: test
|
||||
docker build . -t ${IMG}
|
||||
docker buildx build \
|
||||
--platform=$(BUILD_PLATFORMS) \
|
||||
-t ${IMG} \
|
||||
--load \
|
||||
${BUILD_ARGS} .
|
||||
|
||||
# Push the docker image
|
||||
docker-push:
|
||||
|
|
|
|||
Loading…
Reference in New Issue