-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.crawld
64 lines (49 loc) · 2.17 KB
/
Dockerfile.crawld
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
# Accept the Go version for the image to be set as a build argument.
# Default to Go 1.16
ARG GO_VERSION=1.16
# First stage: build the executable.
FROM golang:${GO_VERSION}-alpine AS 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
# Install the Certificate-Authority certificates for the app to be able to make
# calls to HTTPS endpoints.
# Git is required for fetching the dependencies.
RUN apk add --no-cache ca-certificates git
# 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 ./ ./
# Build the executable. Mark the build as statically linked.
RUN cd ./cmd/crawld && \
CGO_ENABLED=0 go build -installsuffix 'static' -o /crawld . && \
chmod +x /crawld
# Final stage: the running container.
FROM scratch AS final
LABEL AUTHOR Cian Johnston <public@cianjohnston.ie>
# Import the user and group files from the first stage.
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 first stage.
COPY --from=builder /crawld /crawld
# Declare the port on which the webserver will be exposed.
# As we're going to run the executable as an unprivileged user, we can't bind
# to ports below 1024.
EXPOSE 8001
# Perform any further action as an unprivileged user.
USER nobody:nobody
ENV FRESHCOMICS_CRAWLER_HOST 0.0.0.0
ENV FRESHCOMICS_CRAWLER_PORT 8001
ENV FRESHCOMICS_CRAWLER_DSN "host=db user=freshcomics password=freshcomics_password dbname=freshcomicsdb sslmode=disable"
ENV FRESHCOMICS_CRAWLER_CHECKINTERVALSECS 60
ENV FRESHCOMICS_CRAWLER_CRAWLDISPATCHSECS 1
ENV FRESHCOMICS_CRAWLER_BACKOFF "1,1"
# Run the compiled binary.
ENTRYPOINT ["/crawld"]