-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.web
45 lines (31 loc) · 939 Bytes
/
Dockerfile.web
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
# Build stage
FROM golang:1.20-alpine AS builder
WORKDIR /app
# Copy the rest of the application code
COPY web .
# Initialize Go modules
RUN go mod init app
# Force regenerate go.sum and download dependencies
RUN go mod tidy && go mod download
# Build the Go binary
RUN CGO_ENABLED=0 go build -o app .
# Final stage
FROM alpine:3.21
# Create a non-root user with default UID/GID (will be overridden in entrypoint.sh)
RUN addgroup -g 1000 mygroup && \
adduser -D -u 1000 -G mygroup myuser
WORKDIR /app
# Copy the compiled binary from the builder stage
COPY --from=builder /app/app .
# Copy static assets (CSS, JS, HTML templates)
COPY web/static /app/static
COPY web/templates /app/templates
# Copy entrypoint script
COPY web/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Expose the application port
EXPOSE 5000
# Set the entrypoint
ENTRYPOINT ["/entrypoint.sh"]
# Run the application as myuser
CMD ["./app"]