Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
77 lines (58 loc) · 2.34 KB
/
Copy pathDockerfile
File metadata and controls
77 lines (58 loc) · 2.34 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
# Multi-stage Docker build
FROM node:22-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package files first for better caching
COPY package*.json ./
COPY frontend/package*.json ./frontend/
COPY backend/package*.json ./backend/
COPY landing/package*.json ./landing/
# Install dependencies for all parts
RUN npm install --omit=dev --ignore-scripts
RUN cd frontend && npm install --ignore-scripts
RUN cd backend && npm install --ignore-scripts
RUN cd landing && npm install --include=optional --ignore-scripts
# Copy source code
COPY . .
# Build the application with environment variables
# These will be replaced at build time with actual values
ARG NG_APP_API_URL
ARG NG_APP_WS_URL
ARG NG_APP_TURNSTILE_SITE_KEY
ARG NODE_ENV=production
ENV NG_APP_API_URL=$NG_APP_API_URL
ENV NG_APP_WS_URL=$NG_APP_WS_URL
ENV NG_APP_TURNSTILE_SITE_KEY=$NG_APP_TURNSTILE_SITE_KEY
ENV NODE_ENV=$NODE_ENV
# Build all components from root
WORKDIR /app
# Build Angular frontend
RUN cd frontend && npm run build
# Build Astro landing pages
RUN cd landing && npm run build
# Build Node.js backend
RUN cd backend && npm run build
# Production stage
FROM node:22-alpine AS production
# Install curl for health checks
RUN apk add --no-cache curl
WORKDIR /app
# Copy built assets from builder stage
COPY --from=builder /app/backend/dist ./backend/dist
COPY --from=builder /app/backend/package*.json ./backend/
COPY --from=builder /app/backend/prisma ./backend/prisma
COPY --from=builder /app/backend/node_modules/.prisma ./backend/node_modules/.prisma
COPY --from=builder /app/backend/node_modules/@prisma ./backend/node_modules/@prisma
COPY --from=builder /app/frontend/dist/browser ./dist
COPY --from=builder /app/landing/dist ./public
# Install only production dependencies for backend
RUN cd backend && npm install --omit=dev && npm cache clean --force
# Generate Prisma client and run migrations
RUN cd backend && npx prisma generate
# Expose port (Railway uses PORT env var)
EXPOSE $PORT
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:${PORT:-3000}/health || exit 1
# Start the application with Railway's PORT
CMD ["sh", "-c", "cd backend && echo 'Starting deployment...' && (npx prisma migrate deploy || echo 'Migration failed, continuing...') && echo 'Starting server...' && PORT=${PORT:-3000} node dist/server.js"]