generated from pikachu0310/go-backend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
32 lines (22 loc) · 648 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# syntax=docker/dockerfile:1
FROM golang:latest as builder
WORKDIR /app
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
ENV GOCACHE=/root/.cache/go-build
ENV GOMODCACHE=/go/pkg/mod
COPY go.mod go.sum ./
RUN --mount=type=cache,target=${GOCACHE} \
--mount=type=cache,target=${GOMODCACHE} \
go mod download
COPY ./ ./
# RUN --mount=type=cache,target=${GOMODCACHE} go build -o /app/main
RUN --mount=type=cache,target=${GOCACHE} \
--mount=type=cache,target=${GOMODCACHE} \
go build -o /app/main
FROM gcr.io/distroless/static-debian11:latest
WORKDIR /app
COPY --from=builder /app/main /app/main
USER nonroot:nonroot
CMD ["/app/main"]