-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathDockerfile
49 lines (36 loc) · 1.09 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
43
44
45
46
47
48
49
###
# Step 1 - Compile
###
FROM golang:1.14-alpine AS builder
RUN apk add --no-cache upx=3.96-r0
ARG component=${component:-key-retrieval}
ARG branch
ARG revision
ENV GO111MODULE=on
ENV USER=covidshield
ENV UID=10001
ENV GOLDFLAGS="-s -w -X github.com/CovidShield/server/pkg/server.branch=${branch} -X github.com/CovidShield/server/pkg/server.revision=${revision}"
WORKDIR /go/src/github.com/CovidShield/server
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="${GOLDFLAGS}" -o server ./cmd/${component} && upx server
###
# Step 2 - Build
###
FROM scratch
ENV USER=covidshield
WORKDIR /usr/local/bin
# Import the user and group files from step 1
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder --chown=${USER}:${USER} /go/src/github.com/CovidShield/server/server /usr/local/bin/server
USER ${USER}:${USER}
# hadolint ignore=DL3025
ENTRYPOINT ["server"]