-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
41 lines (30 loc) · 891 Bytes
/
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
# Download the dependencies (mod)
FROM golang:1.22 as modules
## Linux dependencies.
RUN apt-get update && apt-get install -y git
ADD go.mod go.sum /mod/
RUN cd /mod && go mod download
# Build the application (app)
FROM golang:1.22 as builder
COPY --from=modules /go/pkg /go/pkg
## Add a non-privileged user
RUN useradd -u 10001 goup
## Copy sources
RUN mkdir -p /app
ADD . /app
WORKDIR /app
## Build the binary
ARG APP_VERSION=v0.0.1-noop
RUN GOOS=linux GOARCH=amd64 GO111MODULE=on CGO_ENABLED=0 go build \
-ldflags "-X main.buildVersion=${APP_VERSION}" \
-o bin/goup .
# Run the binary
FROM scratch
## Certificates and privileges
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
USER goup
## Finally exposes the command line tool
COPY --from=builder /app/bin/goup /bin/goup
WORKDIR /pkg
CMD ["/bin/goup"]