Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (45 loc) · 1.74 KB
/
Copy pathDockerfile
File metadata and controls
59 lines (45 loc) · 1.74 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
57
58
59
# Multi-stage build for OpenRisk
# Stage 1: Build backend
# Float to the latest 1.26.x patch so the binary's standard library carries Go
# security fixes; go.mod's `go` line sets the floor.
FROM golang:1.26-alpine AS backend-builder
WORKDIR /app
RUN apk add --no-cache git make
# Copy backend code
COPY backend/go.mod backend/go.sum ./
RUN go mod download
COPY backend/ ./
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -o openrisk ./cmd/server
# Stage 2: Build frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app
COPY frontend/package*.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build
# Stage 3: Runtime
# alpine:3.18 reached end of life in May 2025 and no longer gets fixes.
FROM alpine:3.24
RUN apk upgrade --no-cache && apk add --no-cache ca-certificates curl
WORKDIR /app
# Copy backend binary from builder
COPY --from=backend-builder /app/openrisk /app/openrisk
# Copy frontend build from builder
COPY --from=frontend-builder /app/dist /app/public
# The SQL migration layer (#1001). The Helm chart sets DATABASE_URL, and with it
# the server runs these at boot and refuses to start when it cannot find them.
COPY migrations/ /app/migrations/
ENV MIGRATIONS_DIR=/app/migrations
# Create non-root user
RUN addgroup -g 1000 openrisk && \
adduser -D -u 1000 -G openrisk openrisk
# Uploaded evidence and exports (STORAGE_LOCAL_PATH defaults to ./uploads).
# The process runs as openrisk, which cannot create it under a root-owned
# /app; the Helm chart mounts a volume here (#1022).
RUN mkdir -p /app/uploads && chown openrisk:openrisk /app/uploads
USER openrisk
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/api/v1/health || exit 1
EXPOSE 8080
CMD ["./openrisk"]