-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (34 loc) · 1.17 KB
/
Dockerfile
File metadata and controls
48 lines (34 loc) · 1.17 KB
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
# Build Stage
FROM golang:1.25 AS builder
WORKDIR /app
# Copy dependency files and download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source code
COPY . .
# Ensure the binary is statically compiled for Alpine by disabling CGO,
# and reduce binary size with linker flags.
ENV CGO_ENABLED=0
RUN go build -ldflags="-s -w" -o ticketpulse .
# Final Stage
FROM alpine:3.22
RUN apk add --no-cache ca-certificates wget
# Create a non-root user for security
RUN adduser -D appuser
WORKDIR /home/appuser
# Copy the statically built binary from the builder stage
COPY --from=builder /app/ticketpulse .
# Copy templates and static assets required at runtime
COPY --from=builder /app/templates ./templates
COPY --from=builder /app/static ./static
# Create the data directory for the SQLite database volume mount
RUN mkdir /data && chown appuser:appuser /data
VOLUME /data
# Expose the application port
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/healthz || exit 1
# Switch to the non-root user
USER appuser
# Run the application
CMD ["./ticketpulse"]