This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
69 lines (50 loc) · 1.72 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
# Stage 1 - Build the Go application and download CLI
FROM golang:1.22.0-alpine3.19 AS builder
# Install necessary build dependencies
RUN apk --no-cache add --update gcc musl-dev
# Create the necessary directories
RUN mkdir -p /build /output /app
# Set the working directory
WORKDIR /build
# Copy all files from the cmd directory
COPY go.mod ./go.mod
COPY go.sum ./go.sum
COPY internal/routes ./internal/routes
COPY internal/config ./internal/config
COPY cmd/main.go ./main.go
# Download dependencies
RUN go mod download
# Build the Go application
RUN CGO_ENABLED=1 go build -ldflags "-w -s" -o /output/palworld-query-api .
# Stage 2 - Create the final image
FROM alpine:3.19.1 AS runner
# Set maintainer label
LABEL maintainer="Xstar97 <dev.xstar97@gmail.com>"
# Install necessary runtime dependencies
RUN apk --no-cache add ca-certificates
# Set the working directory
WORKDIR /app
# Copy the binary from the builder stage
COPY --from=builder /output/palworld-query-api ./
# Create the necessary directories
RUN mkdir -p /config /logs
# Set user and group environment variables
ENV APP_USER=apps \
APP_GROUP=apps \
APP_USER_ID=568 \
APP_GROUP_ID=568
# Create a non-root user and group
RUN addgroup -g $APP_GROUP_ID -S $APP_GROUP && \
adduser -u $APP_USER_ID -S $APP_USER -G $APP_GROUP
# Set environment variables
ENV RCON_CLI_CONFIG=/config/rcon.yaml \
LOGS_PATH=/logs \
PORT=3000
# Change ownership of the /config directory to the non-root user and group
RUN chown -R $APP_USER:$APP_GROUP /config
# Change ownership of the logs directory to the non-root user and group
RUN chown -R $APP_USER:$APP_GROUP $LOGS_PATH
# Expose the port
EXPOSE $PORT
# Set the default command to run the binary
CMD sh -c "./palworld-query-api"