-
Notifications
You must be signed in to change notification settings - Fork 14
/
Dockerfile
43 lines (32 loc) · 984 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
33
34
35
36
37
38
39
40
41
42
43
ARG VERSION=nonroot
############################
# STEP 1 build executable Orchestrate binary
############################
FROM golang:1.16.9 AS builder
ARG TARGETOS
ARG TARGETARCH
RUN apt-get update && \
apt-get install --no-install-recommends -y \
ca-certificates upx-ucl
RUN useradd appuser && mkdir /app
WORKDIR /app
# Use go mod with go 1.15
ENV GO111MODULE=on
COPY go.mod go.sum ./
COPY LICENSE ./
RUN go mod download
COPY . .
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /bin/main -a -tags netgo -ldflags '-w -s -extldflags "-static"' .
RUN upx /bin/main
############################
# STEP 2 build a small image
############################
FROM gcr.io/distroless/static:$VERSION
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /bin/main /go/bin/main
COPY --from=builder /app/LICENSE /
# Use an unprivileged user.
USER appuser
EXPOSE 8080
ENTRYPOINT ["/go/bin/main"]