-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.go
37 lines (28 loc) · 1003 Bytes
/
Dockerfile.go
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
33
34
35
36
37
FROM golang@sha256:4d459123f9eae461060316b85091615a35684fe8a6d975e14aabbb12e9ddb528 AS builder
ENV TINI_VERSION=0.19.0
ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static /tini
RUN chmod +x /tini
RUN addgroup -g 10001 \
-S nonroot && \
adduser -u 10000 \
-G nonroot \
-h /home/nonroot \
-S nonroot
WORKDIR /home/nonroot
COPY ./go.* ./
RUN go mod graph | awk '$1 !~ /@/ { print $2 }' | xargs -r go get -v
USER nonroot:nonroot
COPY . .
RUN CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 go build -ldflags="-w -s" \
-gcflags=all="-l -B -C" \
-o ./app \
-v ./main.go
FROM gcr.io/distroless/static-debian12@sha256:22cda3953e236576e5d113fc6a9290b27e179fbe5937efb1fdc16d81ddfb6120
USER nonroot:nonroot
WORKDIR /home/nonroot
COPY --from=builder /tini /tini
ENTRYPOINT ["/tini", "--"]
COPY --from=builder /home/nonroot/app .
CMD ["./app"]