-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
76 lines (53 loc) · 1.92 KB
/
Dockerfile
File metadata and controls
76 lines (53 loc) · 1.92 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
69
70
71
72
73
74
75
76
# ==============================================================================
# Stage 1: Build Frontend
# ==============================================================================
FROM oven/bun:latest AS frontend-build
WORKDIR /app/frontend
# Copy package files
COPY frontend/package.json frontend/bun.lock ./
# Install dependencies
RUN bun install --frozen-lockfile
# Copy source files
COPY frontend/ ./
# Build production bundle
RUN bun run build
# ==============================================================================
# Stage 2: Build Backend
# ==============================================================================
FROM golang:1.26-alpine AS backend-build
WORKDIR /app/backend
# Install build dependencies
# Copy go mod files
COPY backend/go.mod backend/go.sum ./
# Download dependencies
RUN go mod download
# Copy source files
COPY backend/ ./
# Build static binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o /server ./cmd/server
# ==============================================================================
# Stage 3: Runtime
# ==============================================================================
FROM alpine:3.23
# Create non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
# Copy binary from backend build
COPY --from=backend-build /server /app/server
# Copy frontend assets from frontend build
COPY --from=frontend-build /app/frontend/dist /app/static
# Create data directory and set permissions
RUN mkdir -p /data && chown -R appuser:appgroup /data /app
# Switch to non-root user
USER appuser
# Set environment variables
ENV PORT=8080
ENV STATIC_DIR=/app/static
ENV DATA_DIR=/data
# Expose port
EXPOSE 8080
# Health check (wget is available in alpine)
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
# Run the server
CMD ["/app/server"]