From 7941de60ac7f3f18d28e2174daf4f7dba87a29c7 Mon Sep 17 00:00:00 2001 From: John Allberg Date: Sat, 15 Jan 2022 06:23:12 +0100 Subject: [PATCH 1/3] Enable setting builder and base image during build. --- Dockerfile | 7 +++++-- Makefile | 13 +++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d24f9833..1d868840 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ +ARG BUILDER_IMAGE +ARG BASE_IMAGE + # Build the manager binary -FROM --platform=${BUILDPLATFORM} golang:1.17.2 as builder +FROM --platform=${BUILDPLATFORM} ${BUILDER_IMAGE:-golang:1.17.2} as builder ARG TARGETOS ARG TARGETARCH @@ -23,7 +26,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GO111MODULE=on go build # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot +FROM ${BASE_IMAGE:-gcr.io/distroless/static:nonroot} WORKDIR / COPY --from=builder /workspace/manager . USER 65532:65532 diff --git a/Makefile b/Makefile index f8702f2e..9a209c3b 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,8 @@ OS ?= linux ARCH ?= ??? ALL_ARCH ?= arm64 arm amd64 -BUILDER ?= reloader-builder-${ARCH} +BUILDER_IMAGE ?= +BASE_IMAGE ?= BINARY ?= Reloader DOCKER_IMAGE ?= stakater/reloader @@ -33,7 +34,15 @@ build: "$(GOCMD)" build ${GOFLAGS} ${LDFLAGS} -o "${BINARY}" build-image: - docker buildx build --platform ${OS}/${ARCH} --build-arg GOARCH=$(ARCH) -t "${REPOSITORY_ARCH}" --load -f Dockerfile . + docker buildx build \ + --platform ${OS}/${ARCH} \ + --build-arg GOARCH=$(ARCH) \ + --build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \ + --build-arg BASE_IMAGE=${BASE_IMAGE} \ + -t "${REPOSITORY_ARCH}" \ + --load \ + -f Dockerfile \ + . push: docker push ${REPOSITORY_ARCH} From e85176b5a793d067188d32a0994b2a9a82e14f24 Mon Sep 17 00:00:00 2001 From: John Allberg Date: Sat, 15 Jan 2022 06:24:25 +0100 Subject: [PATCH 2/3] Make build command more readable. --- Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1d868840..fdf296af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,11 @@ COPY internal/ internal/ COPY pkg/ pkg/ # Build -RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GO111MODULE=on go build -mod=mod -a -o manager main.go +RUN CGO_ENABLED=0 \ + GOOS=${TARGETOS} \ + GOARCH=${TARGETARCH} \ + GO111MODULE=on \ + go build -mod=mod -a -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details From 3671d334471c972372efcf01594f41fdad7530c6 Mon Sep 17 00:00:00 2001 From: John Allberg Date: Sat, 15 Jan 2022 06:25:59 +0100 Subject: [PATCH 3/3] Enable setting GOPROXY and GOPRIVATE during build. --- Dockerfile | 4 ++++ Makefile | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Dockerfile b/Dockerfile index fdf296af..fcfb885d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,8 @@ FROM --platform=${BUILDPLATFORM} ${BUILDER_IMAGE:-golang:1.17.2} as builder ARG TARGETOS ARG TARGETARCH +ARG GOPROXY +ARG GOPRIVATE WORKDIR /workspace @@ -25,6 +27,8 @@ COPY pkg/ pkg/ RUN CGO_ENABLED=0 \ GOOS=${TARGETOS} \ GOARCH=${TARGETARCH} \ + GOPROXY=${GOPROXY} \ + GOPRIVATE=${GOPRIVATE} \ GO111MODULE=on \ go build -mod=mod -a -o manager main.go diff --git a/Makefile b/Makefile index 9a209c3b..ad810a14 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,8 @@ BUILD= GOCMD = go GOFLAGS ?= $(GOFLAGS:) LDFLAGS = +GOPROXY ?= +GOPRIVATE ?= default: build test @@ -39,6 +41,8 @@ build-image: --build-arg GOARCH=$(ARCH) \ --build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \ --build-arg BASE_IMAGE=${BASE_IMAGE} \ + --build-arg GOPROXY=${GOPROXY} \ + --build-arg GOPRIVATE=${GOPRIVATE} \ -t "${REPOSITORY_ARCH}" \ --load \ -f Dockerfile \