gaialive commited on
Commit
563aafd
·
verified ·
1 Parent(s): 2944329

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +62 -0
Dockerfile ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # STAGE 1: Build the React frontend with a fresh and clean dependency install
2
+ FROM node:18-bullseye AS builder
3
+
4
+ WORKDIR /app
5
+
6
+ # Copy ONLY the frontend's package.json file to force a fresh install
7
+ COPY web/package.json ./
8
+
9
+ # Run npm install (NOT ci) to create a new dependency tree from scratch.
10
+ # This is the key step to fix a potentially corrupted lock file issue.
11
+ RUN npm install
12
+
13
+ # Copy the rest of the frontend's source code
14
+ COPY web/ ./
15
+
16
+ # Increase the memory available to the Node.js process for the build.
17
+ ENV NODE_OPTIONS=--max-old-space-size=4096
18
+
19
+ # Build the frontend. It will now have a clean and correct node_modules.
20
+ RUN npm run build
21
+
22
+ # STAGE 2: Create the final, lean production image
23
+ FROM node:18-bullseye
24
+
25
+ WORKDIR /app
26
+
27
+ # Install System Dependencies required for the backend
28
+ RUN apt-get update && apt-get install -y python3 python3-pip build-essential && rm -rf /var/lib/apt/lists/*
29
+
30
+ # Copy only the necessary package manifests for the backend and root
31
+ COPY package.json package-lock.json* ./
32
+ COPY backend/package.json ./backend/
33
+ COPY backend/python/requirements.txt ./backend/python/
34
+
35
+ # Install only production dependencies for the backend and root using npm ci
36
+ RUN npm ci --omit=dev
37
+
38
+ # Install Python dependencies
39
+ RUN pip3 install --no-cache-dir -r backend/python/requirements.txt
40
+
41
+ # Create the backend directory and ensure it's owned by 'node' before copying contents
42
+ RUN mkdir -p /app/backend && chown node:node /app/backend
43
+
44
+ # Switch to the non-root 'node' user BEFORE copying backend source
45
+ USER node
46
+
47
+ # Copy backend source code as 'node' user
48
+ COPY backend/ ./backend/
49
+
50
+ # Pre-create the directories that the Node.js app needs to write to.
51
+ # This ensures they exist with correct permissions before the app tries to create them.
52
+ RUN mkdir -p /app/backend/uploads /app/backend/temp /app/backend/results
53
+
54
+ # Copy the pre-built frontend from the builder stage
55
+ COPY --from=builder /app/build ./web/build
56
+
57
+ # --- Final Configuration ---
58
+ ENV PORT=7860
59
+ EXPOSE 7860
60
+
61
+ # Define the command to start the production server
62
+ CMD ["node", "backend/server.js"]