Update Dockerfile
Browse files- Dockerfile +14 -9
Dockerfile
CHANGED
@@ -1,15 +1,19 @@
|
|
1 |
-
# Stage 1: Build the
|
2 |
-
FROM node:
|
3 |
|
4 |
# Set the working directory
|
5 |
WORKDIR /app
|
6 |
|
7 |
-
# Copy
|
8 |
COPY frontend/package.json frontend/package-lock.json ./frontend/
|
|
|
|
|
9 |
RUN cd frontend && npm install
|
10 |
|
11 |
-
#
|
12 |
COPY frontend ./frontend
|
|
|
|
|
13 |
RUN cd frontend && npm run build
|
14 |
|
15 |
# Stage 2: Set up the Node.js backend
|
@@ -18,23 +22,24 @@ FROM node:16
|
|
18 |
# Set the working directory
|
19 |
WORKDIR /app
|
20 |
|
21 |
-
# Copy backend
|
22 |
COPY backend/package.json backend/package-lock.json ./backend/
|
23 |
RUN cd backend && npm install
|
24 |
|
25 |
-
# Copy the
|
26 |
-
COPY --from=build /app/frontend/dist ./backend/
|
27 |
|
28 |
# Copy the backend source code
|
29 |
COPY backend ./backend
|
30 |
|
|
|
31 |
RUN mkdir -p /app/backend/database && chmod -R 777 /app/backend/database
|
32 |
|
33 |
-
|
34 |
# Expose the backend's port
|
35 |
EXPOSE 7860
|
36 |
|
|
|
37 |
WORKDIR /app/backend
|
38 |
|
39 |
# Start the backend server
|
40 |
-
CMD [ "node", "./index.js"]
|
|
|
1 |
+
# Stage 1: Build the Vite frontend
|
2 |
+
FROM node:18 AS build
|
3 |
|
4 |
# Set the working directory
|
5 |
WORKDIR /app
|
6 |
|
7 |
+
# Copy only package.json and lock file first (better for caching)
|
8 |
COPY frontend/package.json frontend/package-lock.json ./frontend/
|
9 |
+
|
10 |
+
# Install dependencies
|
11 |
RUN cd frontend && npm install
|
12 |
|
13 |
+
# Copy the rest of the frontend code
|
14 |
COPY frontend ./frontend
|
15 |
+
|
16 |
+
# Build the Vite app
|
17 |
RUN cd frontend && npm run build
|
18 |
|
19 |
# Stage 2: Set up the Node.js backend
|
|
|
22 |
# Set the working directory
|
23 |
WORKDIR /app
|
24 |
|
25 |
+
# Copy backend dependencies
|
26 |
COPY backend/package.json backend/package-lock.json ./backend/
|
27 |
RUN cd backend && npm install
|
28 |
|
29 |
+
# Copy the Vite build output from Stage 1 to the backend's static folder
|
30 |
+
COPY --from=build /app/frontend/dist ./backend/public
|
31 |
|
32 |
# Copy the backend source code
|
33 |
COPY backend ./backend
|
34 |
|
35 |
+
# Ensure database folder exists and has correct permissions
|
36 |
RUN mkdir -p /app/backend/database && chmod -R 777 /app/backend/database
|
37 |
|
|
|
38 |
# Expose the backend's port
|
39 |
EXPOSE 7860
|
40 |
|
41 |
+
# Set working directory to backend
|
42 |
WORKDIR /app/backend
|
43 |
|
44 |
# Start the backend server
|
45 |
+
CMD [ "node", "./index.js" ]
|