-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
98 lines (75 loc) · 2.18 KB
/
Dockerfile
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
# Build stage
FROM node:18-alpine AS builder
# Set working directory
WORKDIR /app
# Install build dependencies including OpenSSL
RUN apk add --no-cache \
python3 \
make \
g++ \
openssl \
openssl-dev \
libc6-compat
# Copy backend files first
WORKDIR /app/backend
COPY backend/package*.json ./
COPY backend/tsconfig.json ./
COPY backend/prisma ./prisma/
# Install backend dependencies
RUN npm install
RUN npm install -g typescript
RUN npm install --save-dev @types/helmet @types/compression
# Set temporary DATABASE_URL for prisma generate
ENV DATABASE_URL="postgresql://dummy:dummy@localhost:5432/dummy"
# Generate Prisma Client
RUN npx prisma generate
# Copy source files
COPY backend/src ./src/
# Debug and build backend
RUN echo "Starting build process..."
RUN ls -la
RUN npm run build || (echo "Build failed" && npm run build --verbose && exit 1)
# Setup frontend
WORKDIR /app/frontend
# Copy frontend files
COPY frontend/package*.json ./
# Install frontend dependencies
RUN npm install
RUN npm install react-router-dom react-hot-toast @types/react @types/react-dom
# Copy frontend source files
COPY frontend/index.html ./
COPY frontend/vite.config.js ./
COPY frontend/tailwind.config.js ./
COPY frontend/postcss.config.js ./
COPY frontend/src ./src/
COPY frontend/public ./public/
# Debug frontend files
RUN echo "Frontend files:"
RUN ls -la src/
RUN ls -la src/routes/
# Build frontend
RUN npm run build
# Production stage
FROM node:18-alpine
# Install production dependencies
RUN apk add --no-cache \
openssl \
libc6-compat
# Set up backend
WORKDIR /app/backend
COPY --from=builder /app/backend/dist ./dist
COPY --from=builder /app/backend/node_modules ./node_modules
COPY --from=builder /app/backend/package*.json ./
COPY --from=builder /app/backend/prisma ./prisma
# Set up frontend static files
COPY --from=builder /app/frontend/dist ../frontend/dist
# Install production dependencies
RUN npm ci --only=production
# Set temporary DATABASE_URL for second prisma generate
ENV DATABASE_URL="postgresql://dummy:dummy@localhost:5432/dummy"
# Generate Prisma Client again for production
RUN npx prisma generate
# Expose port
EXPOSE 5002
# Start command
CMD ["npm", "start"]