-
Notifications
You must be signed in to change notification settings - Fork 27
/
Dockerfile
48 lines (36 loc) · 1.09 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
# get golang container
FROM golang:1.23.2 AS builder
# get args
ARG TibiaDataBuildBuilder=dockerfile
ARG TibiaDataBuildRelease=-
ARG TibiaDataBuildCommit=-
# create and set workingfolder
WORKDIR /go/src/
# copy go mod files and sourcecode
COPY go.mod go.sum ./
COPY src/ ./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.TibiaDataBuildBuilder=${TibiaDataBuildBuilder}' \
-X 'main.TibiaDataBuildRelease=${TibiaDataBuildRelease}' \
-X 'main.TibiaDataBuildCommit=${TibiaDataBuildCommit}' \
" -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"]