-
Notifications
You must be signed in to change notification settings - Fork 11
/
Dockerfile
48 lines (38 loc) · 1.33 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
FROM --platform=${BUILDPLATFORM} golang:1.19-alpine AS builder
ARG TARGETOS
ARG TARGETARCH
# Git is required for getting the dependencies.
# hadolint ignore=DL3018
RUN apk add --no-cache git
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 to `/app`. Mark the build as statically linked.
# hadolint ignore=SC2155
RUN export TAG=$(git describe --tags "$(git rev-list --tags --max-count=1)") && \
export COMMIT=$(git rev-parse --short HEAD) && \
CGO_ENABLED=0 \
GOOS=${TARGETOS} \
GOARCH=${TARGETARCH} \
go build -installsuffix 'static' \
-ldflags="-X main.version=${TAG} -X main.commit=${COMMIT}" \
-o /app .
FROM alpine:3.12.1 AS final
# Set up non-root user and app directory
# * Non-root because of the principle of least privlege
# * App directory to allow mounting volumes
RUN addgroup -g 1000 bot && \
adduser -HD -u 1000 -G bot bot && \
mkdir -p /app/logs && \
chown -R bot:bot /app
USER bot
# Import the compiled executable from the first stage.
COPY --from=builder /app /app
# Port used for capture program to report back
EXPOSE 8123
# Run the compiled binary.
ENTRYPOINT ["/app/app"]