gaialive commited on
Commit
e21e66e
·
verified ·
1 Parent(s): 1e1c950

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +34 -14
  2. start.sh +4 -5
Dockerfile CHANGED
@@ -1,27 +1,47 @@
1
- # Use a single Node.js base image
2
- FROM node:18-bullseye
3
 
4
  # Create app directory
5
  WORKDIR /app
6
 
7
- # Copy package files
8
- COPY frontend/package*.json ./frontend/
9
- COPY backend/package*.json ./backend/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- # Install dependencies for both frontend and backend
12
- RUN cd frontend && npm install
13
- RUN cd backend && npm install
 
 
 
 
 
14
 
15
- # Copy the rest of the application code
16
- COPY . .
17
 
18
- # Fix permissions for node_modules directories
19
- RUN chmod -R 777 frontend/node_modules backend/node_modules
20
 
21
- # Make the startup script executable
 
22
  RUN chmod +x start.sh
23
 
24
- # Expose port 8501 for Hugging Face Spaces
25
  EXPOSE 8501
26
 
27
  # Start both services
 
1
+ # Multi-stage build: Build frontend first
2
+ FROM node:18-bullseye AS frontend-build
3
 
4
  # Create app directory
5
  WORKDIR /app
6
 
7
+ # Copy frontend files
8
+ COPY frontend/package*.json ./
9
+ RUN npm install
10
+
11
+ # Copy frontend source
12
+ COPY frontend/ ./
13
+
14
+ # Build the frontend
15
+ RUN npm run build
16
+
17
+ # Backend build
18
+ FROM node:18-bullseye AS backend-build
19
+
20
+ WORKDIR /app
21
+ COPY backend/package*.json ./
22
+ RUN npm install
23
+ COPY backend/ ./
24
 
25
+ # Final stage
26
+ FROM node:18-bullseye
27
+
28
+ # Install serve globally to serve frontend
29
+ RUN npm install -g serve
30
+
31
+ # Create app directory
32
+ WORKDIR /app
33
 
34
+ # Copy built frontend from frontend-build stage
35
+ COPY --from=frontend-build /app/dist ./frontend-dist
36
 
37
+ # Setup backend
38
+ COPY --from=backend-build /app ./backend
39
 
40
+ # Copy startup script
41
+ COPY start.sh .
42
  RUN chmod +x start.sh
43
 
44
+ # Expose port 8501
45
  EXPOSE 8501
46
 
47
  # Start both services
start.sh CHANGED
@@ -4,14 +4,13 @@
4
  export PORT=8501
5
 
6
  # Start the backend server in the background
7
- echo "Starting backend server on port $PORT..."
8
  cd backend
9
  npm start &
10
 
11
  # Wait a moment for the backend to start
12
  sleep 5
13
 
14
- # Start the frontend development server
15
- echo "Starting frontend server..."
16
- cd ../frontend
17
- npm run dev
 
4
  export PORT=8501
5
 
6
  # Start the backend server in the background
7
+ echo "Starting backend server on port 3000..."
8
  cd backend
9
  npm start &
10
 
11
  # Wait a moment for the backend to start
12
  sleep 5
13
 
14
+ # Serve the frontend build
15
+ echo "Serving frontend on port $PORT..."
16
+ serve -s frontend-dist -l $PORT