Skip to content

Commit 6775060

Browse files
refactor(accountingservice): refactor accountingservice dockerfile (#1439)
Co-authored-by: Austin Parker <austin@ap2.io>
1 parent 78a5078 commit 6775060

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/accountingservice/Dockerfile

+20-14
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
FROM golang:1.22.0-alpine AS builder
6-
RUN apk update && apk add --no-cache make protobuf-dev
7-
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
8-
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
9-
10-
WORKDIR /usr/src/app/
11-
12-
COPY ./src/accountingservice/ ./
13-
COPY ./pb/ ./pb
14-
15-
RUN protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./
16-
RUN go build -o /go/bin/accountingservice/
17-
18-
# -----------------------------------------------------------------------------
5+
FROM golang:1.22-alpine AS builder
6+
7+
WORKDIR /usr/src/app
8+
9+
RUN apk update \
10+
&& apk add --no-cache make protobuf-dev
11+
12+
RUN --mount=type=cache,target=/go/pkg/mod/ \
13+
--mount=type=bind,source=./src/accountingservice/go.sum,target=go.sum \
14+
--mount=type=bind,source=./src/accountingservice/go.mod,target=go.mod \
15+
--mount=type=bind,source=./src/accountingservice/tools.go,target=tools.go \
16+
go mod download \
17+
&& go list -e -f '{{range .Imports}}{{.}} {{end}}' tools.go | CGO_ENABLED=0 xargs go install -mod=readonly
18+
19+
RUN --mount=type=cache,target=/go/pkg/mod/ \
20+
--mount=type=cache,target=/root/.cache/go-build \
21+
--mount=type=bind,rw,source=./src/accountingservice,target=. \
22+
--mount=type=bind,rw,source=./pb,target=./pb \
23+
protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./ \
24+
&& go build -ldflags "-s -w" -o /go/bin/accountingservice/ ./
1925

2026
FROM alpine
2127

0 commit comments

Comments
 (0)