-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
66 lines (49 loc) · 2.02 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
61
62
63
64
65
66
# \
# \\,
# \\\,^,.,,. Zero to Hero
# ,;7~((\))`;;,, <zerotohero.dev>
# ,(@') ;)`))\;;', stay up to date, be curious: learn
# ) . ),(( ))\;,
# /;`,,/7),)) )) )\,,
# (& )` (,((,((;( ))\,
FROM golang:1.16.4-alpine AS builder
# `git` is required to fetch go dependencies:
RUN apk add --no-cache ca-certificates git
# 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
# Copy the predefined `.netrc` file into the location that git depends on:
COPY ./.netrc /root/.netrc
RUN chmod 600 /root/.netrc
# Set the working directory outside `$GOPATH` to enable the support for modules:
WORKDIR /src
# Fetch dependencies first; they are less susceptible to change on every build
# and will therefore be cached for speeding up the next build:
COPY ./go.mod ./go.sum ./
RUN go mod download
# Import the code from the context:
COPY . .
COPY usr/local/share/fizz /usr/local/share/fizz
COPY web /web
# Build the executable to `/app`. Mark the build as statically linked:
RUN CGO_ENABLED=0 go build -installsuffix 'static' -o /app ./cmd/main.go
# This is the final “minimal” container image:
FROM scratch AS final
# Import the user and group files from the build container:
COPY --from=builder /user/group /user/passwd /etc/
# Import the Certificate-Authority certificates for enabling HTTPS:
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Import the compiled executable from the build container:
COPY --from=builder /app /app
# Copy the generated HTML files:
COPY --from=builder /usr/local/share /usr/local/share
# Only copy templates, not go source codes:
COPY --from=builder /web/template /web/template
# Perform any further action as an unprivileged user:
USER nobody:nobody
# Start listening (should match FIZZ_WEB_SVC_PORT):
EXPOSE 8888/tcp
# Run the compiled binary:
ENTRYPOINT ["/app"]