-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (45 loc) · 1.49 KB
/
Dockerfile
File metadata and controls
68 lines (45 loc) · 1.49 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
60
61
62
63
64
65
66
67
68
# Multi-stage Dockerfile for CrowdSec Manager
# Stage 1: Build frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app/web
# Copy package files
COPY web/package*.json ./
# Install dependencies
RUN npm ci --legacy-peer-deps
# Copy frontend source
COPY web/ ./
# Build frontend
RUN npm run build
# Stage 2: Build Go backend
FROM golang:1.23-alpine AS backend-builder
WORKDIR /app
# Install build dependencies (CGO required for go-sqlite3)
RUN apk add --no-cache git gcc musl-dev sqlite-dev
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY cmd/ cmd/
COPY internal/ internal/
# Build binary (CGO_ENABLED=1 required for go-sqlite3)
RUN CGO_ENABLED=1 GOOS=linux go build -o crowdsec-manager ./cmd/server
# Stage 3: Final runtime image
FROM alpine:latest
# Install runtime dependencies
RUN apk --no-cache add ca-certificates tzdata curl
WORKDIR /app
# Copy binary from builder
COPY --from=backend-builder /app/crowdsec-manager .
# Copy frontend build from frontend-builder
COPY --from=frontend-builder /app/web/dist ./web/dist
# Create necessary directories
RUN mkdir -p /app/backups /app/logs /app/config /app/data
# Expose port
EXPOSE 8080
# Health check (uses PORT env var, defaults to 8080)
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:${PORT:-8080}/health || exit 1
# Run as root user (no USER directive)
# This allows write access to mounted volumes
CMD ["./crowdsec-manager"]