From 798017c65e3e396b14f2c0470b47510a8f4eeb70 Mon Sep 17 00:00:00 2001 From: Lam Tran Date: Tue, 12 Mar 2024 22:41:02 +0700 Subject: [PATCH] refactor(checkoutservice): refactor checkoutservice dockerfile --- src/checkoutservice/Dockerfile | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/checkoutservice/Dockerfile b/src/checkoutservice/Dockerfile index fdeb7b0ed9..be8d777952 100644 --- a/src/checkoutservice/Dockerfile +++ b/src/checkoutservice/Dockerfile @@ -2,20 +2,26 @@ # SPDX-License-Identifier: Apache-2.0 -FROM golang:1.22.0-alpine AS builder -RUN apk update && apk add --no-cache make protobuf-dev -RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest -RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest +FROM golang:1.22-alpine AS builder WORKDIR /usr/src/app/ -COPY ./src/checkoutservice/ ./ -COPY ./pb/ ./pb - -RUN protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./ -RUN go build -o /go/bin/checkoutservice/ - -# ----------------------------------------------------------------------------- +RUN apk update \ + && apk add --no-cache make protobuf-dev + +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,source=./src/checkoutservice/go.sum,target=go.sum \ + --mount=type=bind,source=./src/checkoutservice/go.mod,target=go.mod \ + --mount=type=bind,source=./src/checkoutservice/tools.go,target=tools.go \ + go mod download \ + && go list -e -f '{{range .Imports}}{{.}} {{end}}' tools.go | CGO_ENABLED=0 xargs go install -mod=readonly + +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=bind,rw,source=./src/checkoutservice,target=. \ + --mount=type=bind,rw,source=./pb,target=./pb \ + protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./ \ + && go build -ldflags "-s -w" -o /go/bin/checkoutservice/ ./ FROM alpine