Skip to content

Commit b73b071

Browse files
committed
Introduce a separate dependency downloading step during docker build to cache dependencies for following runs
Signed-off-by: Christian König <[email protected]>
1 parent 5b261e2 commit b73b071

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Dockerfile

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
ARG alpine_version=3.20
33
ARG golang_version=1.22
44

5-
FROM golang:${golang_version}-alpine${alpine_version} as builder
5+
FROM golang:${golang_version}-alpine${alpine_version} AS builder
66
ARG GIT_COMMIT
77
ARG GIT_BRANCH
88
ARG GIT_VERSION
@@ -13,13 +13,17 @@ RUN apk add --no-cache \
1313
git \
1414
make
1515

16-
COPY /src /src
17-
WORKDIR /src
16+
# Download dependencies first to cache them
17+
WORKDIR /app
18+
COPY ./src/go.mod ./src/go.sum ./
19+
RUN go mod download
20+
21+
# Copy the source code and build
22+
COPY /src ./
1823
RUN make build
1924

20-
FROM scratch as deploy
21-
COPY --from=builder /src/docker-event-monitor docker-event-monitor
22-
# the tls certificates:
23-
# this pulls directly from the upstream image, which already has ca-certificates:
25+
FROM scratch AS deploy
26+
COPY --from=builder /app/docker-event-monitor docker-event-monitor
27+
# this pulls directly from the upstream image, which already has ca-certificates
2428
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2529
ENTRYPOINT ["/docker-event-monitor"]

0 commit comments

Comments
 (0)