-
-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (50 loc) · 1.88 KB
/
Dockerfile
File metadata and controls
72 lines (50 loc) · 1.88 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
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
# Native build deps for modules that may compile from source (e.g., better-sqlite3 on arm64)
RUN apk add --no-cache python3 make g++
# Copy package files
COPY package*.json ./
COPY tsconfig.json ./
# Install dependencies
RUN npm ci && npm cache clean --force
# Copy prisma schema
COPY prisma ./prisma/
# Set default provider for build-time Prisma generation (runtime can override via DATABASE_PROVIDER)
RUN sed -i 's/provider = env("[^"]*")/provider = "sqlite"/' prisma/schema.prisma
# Generate Prisma Client at build time (for TypeScript compilation)
# Runtime will regenerate if DATABASE_PROVIDER differs
RUN npx prisma generate
# Copy source code
COPY src ./src
# Build TypeScript
RUN npx tsc
# Production stage
FROM node:20-alpine
# Install runtime packages and create non-root user
RUN apk add --no-cache openssl su-exec && \
addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install production dependencies only
RUN apk add --no-cache --virtual .build-deps python3 make g++ && \
npm ci --omit=dev && \
npm cache clean --force && \
apk del .build-deps
# Copy prisma schema and migrations for runtime and hydration template
COPY prisma ./prisma/
COPY prisma ./prisma_template/
# Copy built application from builder
COPY --from=builder /app/dist ./dist
# Copy the generated Prisma Client from builder (will be regenerated at runtime if provider changes)
COPY --from=builder /app/src/generated ./dist/generated
# Create necessary directories (ownership will be set in entrypoint)
RUN mkdir -p /app/uploads /app/prisma
# Copy and set permissions for entrypoint script
COPY docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
# REMOVED: USER nodejs (We must stay root to fix permissions in entrypoint)
EXPOSE 8000
ENTRYPOINT ["./docker-entrypoint.sh"]