-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
78 lines (59 loc) · 2.28 KB
/
Copy pathDockerfile
File metadata and controls
78 lines (59 loc) · 2.28 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
77
78
# Multi-stage Dockerfile for JsonAtomic
# Production-hardened with non-root user, read-only filesystem, and minimal capabilities
# Stage 1: Build
FROM node:20.18.1-alpine3.20 AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies with npm ci for reproducible builds
RUN npm ci --only=production && \
npm cache clean --force
# Copy source code
COPY . .
# Build TypeScript
RUN npm run build
# Stage 2: Runtime
FROM node:20.18.1-alpine3.20 AS runtime
# Security: Create non-root user
RUN addgroup -g 1001 -S jsonatomic && \
adduser -u 1001 -S jsonatomic -G jsonatomic
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install only production dependencies
RUN npm ci --only=production && \
npm cache clean --force && \
rm -rf /root/.npm
# Copy built files from builder
COPY --from=builder --chown=jsonatomic:jsonatomic /app/dist ./dist
COPY --from=builder --chown=jsonatomic:jsonatomic /app/schemas ./schemas
# Create data directory with proper permissions
RUN mkdir -p /app/data && \
chown -R jsonatomic:jsonatomic /app
# Security: Use non-root user
USER jsonatomic:jsonatomic
# Expose ports (non-privileged)
EXPOSE 8000 9090
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:8000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Set environment variables
ENV NODE_ENV=production \
PORT=8000 \
HOST=0.0.0.0 \
LEDGER_PATH=/app/data/ledger.jsonl
# Security labels for metadata
LABEL org.opencontainers.image.title="JsonAtomic" \
org.opencontainers.image.description="Ledger-based constitutional governance platform" \
org.opencontainers.image.version="1.1.0" \
org.opencontainers.image.vendor="LogLineOS" \
org.opencontainers.image.source="https://github.com/danvoulez/JsonAtomic" \
org.opencontainers.image.licenses="MIT"
# Start the application
# Note: For maximum security in production, run with:
# docker run --read-only --cap-drop=ALL -v data:/app/data --tmpfs /tmp jsonatomic
# - --read-only: Read-only root filesystem
# - --cap-drop=ALL: Drop all Linux capabilities
# - -v data:/app/data: Writable volume for ledger data
# - --tmpfs /tmp: Temporary filesystem for runtime
CMD ["node", "dist/index.js"]