-
Notifications
You must be signed in to change notification settings - Fork 22
/
Dockerfile
44 lines (32 loc) · 896 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
42
43
44
# get golang container
FROM golang:1.23.3 AS builder
# get args
ARG apiVersion=unknown
# create and set workingfolder
WORKDIR /go/src/
# copy go mod files and sourcecode
COPY go.mod go.sum ./
COPY src/ .
# download go mods and compile the program
RUN go mod download && \
CGO_ENABLED=0 GOOS=linux go build \
-a -installsuffix cgo -ldflags="-w -s \
-X 'main.apiVersion=${apiVersion}' \
" -o app ./...
# get alpine container
FROM alpine:3.20.3 AS app
# create workdir
WORKDIR /opt/app
# add packages, create nonroot user and group
RUN apk --no-cache add ca-certificates tzdata && \
addgroup -S nonroot && \
adduser -S nonroot -G nonroot && \
chown -R nonroot:nonroot .
# set user to nonroot
USER nonroot:nonroot
# copy binary from builder
COPY --from=builder --chown=nonroot:nonroot --chmod=544 /go/src/app .
# expose port 8080
EXPOSE 8080
# run application
CMD ["./app"]