forked from bannert1337/ephemera
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
101 lines (73 loc) · 3.61 KB
/
Copy pathDockerfile
File metadata and controls
101 lines (73 loc) · 3.61 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Multi-stage Dockerfile for ephemera
# Simplified single-process architecture: Node.js serves both API and static files
# Stage 1: Dependencies and Build Environment
FROM node:22-alpine AS build-env
# Install build dependencies for native modules (better-sqlite3)
RUN apk add --no-cache python3 make g++ gcc musl-dev
# Enable corepack for pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /build
# Copy workspace config and all package source code
# .dockerignore will exclude node_modules/ and dist/ automatically
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY packages/ ./packages/
# Install all dependencies (including devDependencies for build)
# This creates proper workspace symlinks
RUN pnpm install --frozen-lockfile
# Build all packages sequentially to ensure proper dependency resolution
# Use tsc --build --force to ensure clean builds (no stale incremental data)
RUN cd packages/shared && npx tsc --build --force && cd ../.. && \
cd packages/api && npx tsc --build --force && cd ../.. && \
cd packages/web && npx tsc && npx vite build
# Stage 2: Production Dependencies
FROM node:22-alpine AS prod-deps
# Install build dependencies for native modules
RUN apk add --no-cache python3 make g++ gcc musl-dev
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# Copy package files and source before install (for workspace resolution)
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY packages/ ./packages/
# Approve better-sqlite3 build script before install
RUN pnpm config set enable-pre-post-scripts false
# Install only production dependencies (ignore scripts to skip husky)
RUN pnpm install --frozen-lockfile --prod --ignore-scripts
# Force rebuild better-sqlite3 with node-gyp
# Find the better-sqlite3 package and run build-release
RUN SQLITE_PATH=$(find /app/node_modules/.pnpm -type d -path "*/better-sqlite3@*/node_modules/better-sqlite3" | head -n 1) && \
if [ -n "$SQLITE_PATH" ]; then \
cd "$SQLITE_PATH" && npm run build-release; \
fi
# Stage 3: Production Runtime
FROM node:22-alpine AS runtime
# Install packages needed for PUID/PGID support
RUN apk add --no-cache shadow su-exec
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
WORKDIR /app
# Copy production dependencies (includes rebuilt native modules)
COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=prod-deps /app/packages/shared/node_modules ./packages/shared/node_modules
COPY --from=prod-deps /app/packages/api/node_modules ./packages/api/node_modules
# Copy built artifacts
COPY --from=build-env /build/packages/shared/dist ./packages/shared/dist
COPY --from=build-env /build/packages/shared/package.json ./packages/shared/
COPY --from=build-env /build/packages/api/dist ./packages/api/dist
COPY --from=build-env /build/packages/api/package.json ./packages/api/
COPY --from=build-env /build/packages/api/src/db ./packages/api/src/db
COPY --from=build-env /build/packages/web/dist ./packages/web/dist
# Copy package files
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
# Copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Note: Container starts as root to allow PUID/PGID modification
# Entrypoint script will drop privileges to nodejs user via su-exec
# Expose application port (default 8286)
EXPOSE 8286
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT:-8286}/health || exit 1
# Set entrypoint
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]