forked from gleez/leader-elector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
60 lines (46 loc) · 1.57 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
57
58
59
60
############################
# STEP 1 build executable binary
############################
FROM golang:1.13 as builder
ADD . /go/src/github.com/gleez/leader-elector
RUN cd /go/src/github.com/gleez/leader-elector \
&& COMMIT_SHA=$(git rev-parse --short HEAD) \
&& CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w \
-X main.Version=0.9 \
-X main.Revision=${COMMIT_SHA}" \
-a -tags netgo -installsuffix netgo -o leader-elector example/main.go
############################
# STEP 2 build a certs image
############################
# Alpine certs
FROM alpine:3.11 as alpine
RUN apk update && apk add --no-cache ca-certificates tzdata && update-ca-certificates
# Create appuser
ENV USER=appuser
ENV UID=10001
# See https://stackoverflow.com/a/55757473/12429735
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
############################
# STEP 3 build a release image
############################
FROM scratch
MAINTAINER Sandeep Sangamreddi <[email protected]>
# Import from builder.
COPY --from=alpine /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=alpine /etc/passwd /etc/passwd
COPY --from=alpine /etc/group /etc/group
# Add the binary
COPY --from=builder /go/src/github.com/gleez/leader-elector/leader-elector /usr/bin/
EXPOSE 4040
# Use an unprivileged user.
USER appuser:appuser
# ENTRYPOINT ["leader-elector", "--id=$(hostname)"]
ENTRYPOINT ["leader-elector"]