-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
94 lines (70 loc) · 2.51 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Go image tag
ARG GOLANG_TAG=1.22-bullseye
FROM golang:$GOLANG_TAG as builder
ENV TWITCH_BOT_PREFIX=""
ENV TWITCH_BOT_CHANNEL=""
ENV TWITCH_BOT_CHANNEL_ID=""
ENV TWITCH_BOT_USERNAME=""
ENV TWITCH_BOT_OAUTH=""
ENV TWITCH_HELIX_CLIENT_ID=""
ENV TWITCH_HELIX_CLIENT_SECRET=""
ENV HTTP_ADDRESS=""
ENV HTTP_PORTS_REST=""
ENV API_KEYS_LASTFM=""
# Package path for ldflags
ARG PACKAGE=""
# Version of the REST build
ARG VERSION=""
# Commit hash
ARG COMMIT=""
# Github user required for downloading private Go modules
ARG ACCESS_TOKEN_USR=""
# Github user access token required for downloading private Go modules
ARG ACCESS_TOKEN_PWD=""
# Install required dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
git \
build-essential \
gcc
# 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
# Create a netrc file using the credentials specified using --build-arg
RUN printf "machine github.com\n\
login ${ACCESS_TOKEN_USR}\n\
password ${ACCESS_TOKEN_PWD}\n\
\n\
machine api.github.com\n\
login ${ACCESS_TOKEN_USR}\n\
password ${ACCESS_TOKEN_PWD}\n"\
>> /root/.netrc
RUN chmod 600 /root/.netrc
# Disable terminal prompts for Git
ENV GIT_TERMINAL_PROMPT=0
# Set the working directory outside $GOPATH to enable the support for modules.
WORKDIR /src
# Import code from context.
COPY . .
# Import the vendor directory into the Docker build.
COPY ./vendor ./vendor
COPY ./config /app/config
# Build the executable to `/app`. Mark the build as statically linked.
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor -o /app/server -ldflags="-X 'main.Version=${VERSION}' -X 'main.CommitHash=${COMMIT}'" ./cmd/app/main.go
# Use a more complete base image for the final stage
FROM debian:buster-slim AS final
# 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/server /app/server
COPY --from=builder /app/config /config
# Create a writable tmp directory
RUN mkdir -p /tmp && chmod 1777 /tmp
# Perform any further action as an unprivileged user.
USER nobody:nobody
# Run the compiled binary.
ENTRYPOINT ["/app/server"]