-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
109 lines (81 loc) · 2.69 KB
/
Copy pathDockerfile
File metadata and controls
109 lines (81 loc) · 2.69 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
102
103
104
105
106
107
108
109
# Build stage
FROM node:20-alpine AS build
WORKDIR /app
# Build-time environment variable for Prisma generation
ARG DATABASE_URL=postgresql://dummy:dummy@localhost:5432/dummy
ENV DATABASE_URL=$DATABASE_URL
# Install dependencies for Prisma and build tools
RUN apk update && apk add --no-cache \
python3 \
make \
g++
# Copy package files
COPY package*.json ./
COPY tsconfig.json ./
COPY prisma.config.ts ./
COPY prisma ./prisma/
# Copy PostCSS and Tailwind config
COPY postcss.config.js ./
COPY tailwind.config.js ./
# Install all dependencies and generate Prisma Client
RUN npm ci
RUN npx prisma generate
# Copy source code
COPY src ./src
# Copy React frontend files
COPY src/web/frontend ./src/web/frontend
COPY vite.frontend.config.ts ./
# Build React frontend - will use latest code
RUN npm run build:frontend
# Note: TypeScript backend will be run via tsx, not pre-compiled
# This avoids Prisma generation issues during build time
# Copy startup script and healthcheck to build stage too
COPY docker/start.sh /start.sh
COPY docker/healthcheck.sh /healthcheck.sh
RUN chmod +x /start.sh /healthcheck.sh
# Runtime stage
FROM node:20-alpine AS runtime
WORKDIR /app
# Install runtime dependencies including PostgreSQL client for pg_dump/psql
RUN apk update && apk add --no-cache \
dumb-init \
openssl \
postgresql-client
# Set production environment
ENV NODE_ENV=production
# Copy package files and install production dependencies
COPY package*.json ./
COPY prisma.config.ts ./
COPY --from=build /app/package-lock.json ./
RUN npm ci --omit=dev
# Copy Prisma schema
COPY --from=build /app/prisma ./prisma
# Copy generated Prisma Client from build stage
COPY --from=build /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=build /app/node_modules/@prisma ./node_modules/@prisma
# Copy React frontend build
COPY --from=build /app/dist/web/frontend ./dist/web/frontend
# Copy TypeScript source (will be run via tsx)
COPY --from=build /app/src ./src
COPY --from=build /app/tsconfig.json ./tsconfig.json
COPY --from=build /app/vite.frontend.config.ts ./vite.frontend.config.ts
# Install tsx for running TypeScript
RUN npm install -g tsx
# Copy healthcheck script
COPY docker/healthcheck.sh /healthcheck.sh
RUN chmod +x /healthcheck.sh
# Copy startup script
COPY docker/start.sh /start.sh
RUN chmod +x /start.sh
# Create non-root user
RUN addgroup -S nodejs && adduser -S -G nodejs nodejs
# Change ownership
RUN chown -R nodejs:nodejs /app && \
chown nodejs:nodejs /start.sh
USER nodejs
# Healthcheck
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD ["/healthcheck.sh"]
# Run with dumb-init and startup script
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["/start.sh"]