-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (40 loc) · 1.55 KB
/
Copy pathDockerfile
File metadata and controls
56 lines (40 loc) · 1.55 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
49
50
51
52
53
54
55
56
# =============================================================================
# Stage 1: builder
# =============================================================================
FROM golang:1.26.3-alpine AS builder
# Install git (needed by some go modules) and build essentials
RUN apk add --no-cache git
WORKDIR /build
# Use local toolchain so go.mod's future 'go' directive doesn't block the build
ENV GOTOOLCHAIN=local
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
# Download dependencies in a separate layer for better layer caching
COPY go.mod go.sum ./
RUN go mod download
# Copy the full source tree
COPY . .
# Build a statically-linked binary
RUN go build -trimpath -ldflags="-s -w" -o /app/server ./cmd/main.go
# =============================================================================
# Stage 2: runner
# =============================================================================
FROM alpine:3.19 AS runner
# ca-certificates: required for HTTPS calls to GitHub API and other TLS endpoints
# tzdata: keeps time-zone handling consistent
RUN apk add --no-cache ca-certificates tzdata
# Create a non-root user and group
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
# Copy the compiled binary from the builder stage
COPY --from=builder /app/server ./server
# Copy the default config file (may be overridden by a bind-mount at runtime)
COPY config.yaml ./config.yaml
# Copy frontend static files
COPY --from=builder /build/frontend ./frontend
# Drop to non-root
USER appuser
EXPOSE 8080
# Run the server
CMD ["/app/server"]