-
Notifications
You must be signed in to change notification settings - Fork 1
/
crawler.Dockerfile
37 lines (26 loc) · 1.09 KB
/
crawler.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
# Start from the latest golang base image
FROM golang:latest AS compiler
# Set the working directory inside the container
WORKDIR /app
# Copy dependencies prior to building so that this layer is cached unless
# specified dependencies change
COPY go.mod go.sum /app/
RUN go mod download
# Copy the source from the current directory to the Working Directory inside the container
COPY crawler /app
# Build the Go app, making sure it is a static binary with no debugging symbols
RUN GOOS=linux CGO_ENABLED=0 go build -a -ldflags="-w -s" -o app
# Create non-root user information
RUN echo "cchc:x:65534:65534:CCHC:/:" > /etc_passwd
# Start over with a completely empty image
FROM scratch
# Include the certificates since we have to access an HTTPS API
COPY --from=compiler /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
# Copy over just the static binary to root
COPY --from=compiler /app/app /cchc-crawler
# Copy over non-root user information
COPY --from=0 /etc_passwd /etc/passwd
# Run as non-root user in container
USER cchc
# Command to run the executable
CMD ["/cchc-crawler"]