-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
34 lines (32 loc) · 1.11 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
FROM golang:1.14-alpine as builder
# Force the go compiler to use modules
ENV GO111MODULE=on
# Create the user and group files to run unprivileged
RUN mkdir /user && \
echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
echo 'nobody:x:65534:' > /user/group
RUN apk update && apk add --no-cache git ca-certificates tzdata
RUN mkdir /build
# COPY . /build/
WORKDIR /build
# Get the deps - Do this separately for ease of iteration
COPY go.mod go.sum /build/
RUN go mod download
# Import the code
COPY ./ ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o yodel ./cmd/yodel
##############################
FROM busybox:1.32 AS final
# Import the time zone files
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
# Import the user and group files
COPY --from=builder /user/group /user/passwd /etc/
# Import the CA certs
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Import the compiled go executable
COPY --from=builder /build/yodel /bin/
# Run as unprivileged
USER nobody:nobody
ENV YODEL_CONFIG_PATH=/config
VOLUME /config
CMD ["/bin/yodel"]