File tree Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -29,14 +29,18 @@ FROM ${builder_image} as builder
29
29
WORKDIR /workspace
30
30
31
31
# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy
32
- ARG goproxy=off
33
- # Run this with docker build --build-arg package=./controlplane/kubeadm or --build-arg package=./bootstrap/kubeadm
32
+ ARG goproxy=https://proxy.golang.org
34
33
ENV GOPROXY=$goproxy
35
34
36
35
# Copy the Go Modules manifests
37
36
COPY go.mod go.mod
38
37
COPY go.sum go.sum
39
38
39
+ # Cache deps before building and copying source so that we don't need to re-download as much
40
+ # and so that source changes don't invalidate our downloaded layer
41
+ RUN --mount=type=cache,target=/go/pkg/mod \
42
+ go mod download
43
+
40
44
# Copy the sources
41
45
COPY ./ ./
42
46
@@ -46,7 +50,9 @@ ARG ARCH
46
50
ARG ldflags
47
51
48
52
# Do not force rebuild of up-to-date packages (do not use -a) and use the compiler cache folder
49
- RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
53
+ RUN --mount=type=cache,target=/root/.cache/go-build \
54
+ --mount=type=cache,target=/go/pkg/mod \
55
+ CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
50
56
go build -trimpath -ldflags "${ldflags} -extldflags '-static'" \
51
57
-o manager ${package}
52
58
Original file line number Diff line number Diff line change @@ -25,13 +25,6 @@ GO_CONTAINER_IMAGE ?= docker.io/library/golang:$(GO_VERSION)
25
25
26
26
ARCH ?= $(shell go env GOARCH)
27
27
28
- # Use GOPROXY environment variable if set
29
- GOPROXY := $(shell go env GOPROXY)
30
- ifeq ($(GOPROXY ) ,)
31
- GOPROXY := https://proxy.golang.org
32
- endif
33
- export GOPROXY
34
-
35
28
# Active module mode, as we use go modules to manage dependencies
36
29
export GO111MODULE =on
37
30
@@ -231,7 +224,7 @@ generate-bootstrap-conversions: $(CONVERSION_GEN)
231
224
232
225
# Build the docker image
233
226
docker-build-bootstrap : manager-bootstrap # # Build bootstrap
234
- DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE ) --build-arg goproxy= $( GOPROXY ) --build-arg ARCH=$(ARCH ) --build-arg package=./bootstrap/main.go --build-arg ldflags=" $( LDFLAGS) " . -t ${BOOTSTRAP_IMG} :${BOOTSTRAP_IMG_TAG}
227
+ DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE ) --build-arg ARCH=$(ARCH ) --build-arg package=./bootstrap/main.go --build-arg ldflags=" $( LDFLAGS) " . -t ${BOOTSTRAP_IMG} :${BOOTSTRAP_IMG_TAG}
235
228
236
229
# Push the docker image
237
230
docker-push-bootstrap : # # Push bootstrap
@@ -303,7 +296,7 @@ generate-controlplane-conversions: $(CONVERSION_GEN)
303
296
--go-header-file=./hack/boilerplate.go.txt
304
297
305
298
docker-build-controlplane : manager-controlplane # # Build control-plane
306
- DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE ) --build-arg goproxy= $( GOPROXY ) --build-arg ARCH=$(ARCH ) --build-arg package=./controlplane/main.go --build-arg ldflags=" $( LDFLAGS) " . -t ${CONTROLPLANE_IMG} :$(CONTROLPLANE_IMG_TAG )
299
+ DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE ) --build-arg ARCH=$(ARCH ) --build-arg package=./controlplane/main.go --build-arg ldflags=" $( LDFLAGS) " . -t ${CONTROLPLANE_IMG} :$(CONTROLPLANE_IMG_TAG )
307
300
308
301
docker-push-controlplane : # # Push control-plane
309
302
docker push ${CONTROLPLANE_IMG} :$(CONTROLPLANE_IMG_TAG )
You can’t perform that action at this time.
0 commit comments