-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile.drainer
56 lines (42 loc) · 1.29 KB
/
Dockerfile.drainer
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
###############################
# STAGE 1 test and build binary
###############################
FROM golang:1.13 AS builder
# Set Go build env vars
ARG GOOS=linux
ARG GOARCH=amd64
ENV GOOS=${GOOS} GOARCH=${GOARCH}
# Create a non-root user
ARG GOUSER=appuser
RUN adduser --gecos '' --disabled-password --no-create-home ${GOUSER}
WORKDIR /go/src/app
# Fetch dependencies
# Do this first for caching sake
ENV GO111MODULE=on
COPY v2/go.mod v2/go.sum ./
RUN go mod download
# Copy source
COPY v2/ .
# Install/Update packages (after src COPY so it always happens)
RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install -y ca-certificates tzdata \
&& update-ca-certificates
# Build the binary
RUN CGO_ENABLED=0 go build -ldflags='-w -s' -trimpath -o /go/bin/drainer ./cmd/drainer
##########################
# STAGE 2 deployment image
##########################
FROM scratch
# Import from the builder.
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy our static executable.
COPY --from=builder /go/bin/drainer /usr/bin/drainer
# Use an unprivileged user.
USER ${GOUSER}
# Expose healthcheck port.
ENV PORT=8080
EXPOSE $PORT
ENTRYPOINT ["/usr/bin/drainer"]