This repository has been archived by the owner on Nov 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile
56 lines (40 loc) · 1.54 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
50
51
52
53
54
55
56
FROM golang:1.12-alpine AS go-builder
# Create the user and group files that will be used in the running container to
# run the process as an unprivileged user.
RUN mkdir /user && \
echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
echo 'nobody:x:65534:' > /user/group
RUN apk add --no-cache ca-certificates git
# Set the environment variables for the go command
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on
WORKDIR /e2d
# Copy Go source code files, and built static assets from previous stages
# Start with vendor since it doesn't change often, to utilize caching
COPY ./go.mod ./go.sum ./
COPY pkg ./pkg
COPY cmd ./cmd
# Put these right before the go build since they will change with each commit,
# which reduces docker caching
ARG VERSION=dev
RUN go build \
-ldflags "-s -w -X main.Version=$VERSION" \
-o bin/e2d \
./cmd/e2d
RUN chown nobody:nobody bin/e2d
############################
# Final stage: Just the executable and bare minimum other files
FROM scratch AS final
LABEL MAINTAINER="Critical Stack <[email protected]>"
# Import the user and group files from the first stage.
COPY --from=go-builder /user/group /user/passwd /etc/
# Import the Certificate-Authority certificates for enabling HTTPS.
COPY --from=go-builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Perform any further action as an unprivileged user.
USER nobody:nobody
# e2d runs on port 2379,2380,7980
EXPOSE 2379
EXPOSE 2380
EXPOSE 7980
# Add e2d bin
COPY --from=go-builder --chown=nobody:nobody /e2d/bin/e2d /
ENTRYPOINT ["/e2d"]