Skip to content

Commit 2226e00

Browse files
committed
Cleanup Docker context and decrease build time
This is based off the work found in kubernetes-sigs#1307 that was never merged. It moves around the install and copy of certain conponents to take better advantage of the Docker cache ad well as drops running tests during the build of the image. The reason for dropping tests is to improve build time and as running tests within the build while they're already being run in CI seems like an unnecessary added tax. Signed-off-by: Danny Grove <[email protected]>
1 parent 4428821 commit 2226e00

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

.dockerignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Git Related Items
2+
.git
3+
.github
4+
.gitignore
5+
6+
# CI Related Items
7+
.travis.yml
8+
cloudbuild.yaml
9+
.golangci.yml
10+
.zappr.yaml
11+
12+
# Other
13+
docs
14+
OWNERS
15+
vendor

Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ ARG ARCH
1919

2020
WORKDIR /sigs.k8s.io/external-dns
2121

22+
COPY go.mod .
23+
COPY go.sum .
24+
RUN go mod download
25+
2226
COPY . .
23-
RUN make test && make build.$ARCH
27+
RUN make test build.$ARCH
2428

2529
# final image
2630
FROM $ARCH/alpine:3.12

Dockerfile.mini

+10-6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ FROM golang:1.15 as builder
1616

1717
WORKDIR /sigs.k8s.io/external-dns
1818

19+
RUN apt-get update \
20+
&& apt-get install \
21+
ca-certificates \
22+
&& update-ca-certificates
23+
24+
COPY go.mod .
25+
COPY go.sum .
26+
RUN go mod download
27+
1928
COPY . .
20-
RUN apt-get update && \
21-
apt-get install ca-certificates && \
22-
update-ca-certificates && \
23-
go mod vendor && \
24-
make test && \
25-
make build
29+
RUN make test build
2630

2731
FROM gcr.io/distroless/static
2832

0 commit comments

Comments
 (0)