-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (40 loc) · 1.68 KB
/
Copy pathDockerfile
File metadata and controls
55 lines (40 loc) · 1.68 KB
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
# Accept the Go version for the image to be set as a build argument.
# Default to Go 1.12
ARG GO_VERSION=1.12
# 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
RUN echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd
RUN echo 'nobody:x:65534:' > /user/group
# Install the Certificate-Authority certificates for the app to be able to make
# calls to HTTPS endpoints.
RUN apk add --no-cache ca-certificates
# Set the environment variables for the go command:
# * CGO_ENABLED=0 to build a statically-linked executable
# * GOFLAGS=-mod=vendor to force `go build` to look into the `/vendor` folder.
ENV CGO_ENABLED=0 GOFLAGS=-mod=vendor
# Define app sources path
ENV APP_PATH=/go/src/github.com/rozag/rss-tg-chan
# Assuming the source code is collocated to this Dockerfile
COPY ./config.ini /
COPY . ${APP_PATH}
# Jump to sources
WORKDIR ${APP_PATH}
# Build the executable to `/app`. Mark the build as statically linked.
RUN go build -installsuffix 'static' -o /app .
# The second and final stage
FROM scratch
# 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 /app /app
# Import the config file from the first stage
COPY --from=builder /config.ini /config.ini
# Perform any further action as an unprivileged user
USER nobody:nobody
# Run the compiled binary
ENTRYPOINT ["/app"]