Skip to content

Commit a3e0048

Browse files
committed
improve docker build caching
1 parent c50a010 commit a3e0048

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/checkoutservice/Dockerfile

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@
55
FROM golang:1.22-alpine AS base-build
66

77
WORKDIR /build
8-
RUN go env -w GOMODCACHE=/root/.cache/go-build
98

9+
RUN apk add --no-cache protobuf-dev
10+
11+
RUN go env -w GOMODCACHE=/root/.cache/go-build
1012
COPY ./src/checkoutservice/go.mod ./src/checkoutservice/go.sum ./
1113
RUN --mount=type=cache,target=/root/.cache/go-build go mod download
1214

1315
COPY ./src/checkoutservice/tools.go ./
1416
RUN --mount=type=cache,target=/root/.cache/go-build \
1517
go list -e -f '{{range .Imports}}{{.}} {{end}}' tools.go | CGO_ENABLED=0 xargs go install -mod=readonly
1618

17-
RUN apk add --no-cache protobuf-dev
19+
COPY ./pb ./pb
20+
RUN --mount=type=cache,target=/root/.cache/go-build \
21+
protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./
1822

1923
COPY ./src/checkoutservice ./
20-
COPY ./pb ./pb
2124
RUN --mount=type=cache,target=/root/.cache/go-build \
22-
protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./ \
23-
&& go build -ldflags "-s -w" -o /go/bin/checkoutservice/ ./
25+
go build -ldflags "-s -w" -o /go/bin/checkoutservice/ ./
2426

2527
FROM alpine
2628

0 commit comments

Comments
 (0)