generated from cmilhench/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
42 lines (32 loc) · 1.08 KB
/
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
33
34
35
36
37
38
39
40
41
42
############################
# STEP 1 build executable binary
############################
FROM golang:alpine AS builder
RUN apk update && apk add --no-cache ca-certificates tzdata && update-ca-certificates
WORKDIR /src
# Download the dependencies
COPY ./go.mod ./go.sum ./
RUN go mod download
# Import the source files
COPY . .
# Build the binary for the application
RUN go generate ./... && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-installsuffix 'static' \
-ldflags '-w -s' \
-o /go/bin/main ./cmd/
############################
# STEP 2 build a small image
############################
FROM scratch
# Import the tls certificates and timezone data from the builder.
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Import the user and group files from the builder.
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
# Import the application binaries
COPY --from=builder /go/bin/main /main
# Use an unprivileged user.
USER nobody:nobody
ENTRYPOINT ["/main"]