# Stage 1: Build the Vite frontend FROM node:18 AS build # Set the working directory WORKDIR /app # Copy only package.json and lock file first (better for caching) COPY frontend/package.json frontend/package-lock.json ./frontend/ # Install dependencies RUN cd frontend && npm install # Copy the rest of the frontend code COPY frontend ./frontend # Build the Vite app RUN cd frontend && npm run build # Stage 2: Set up the Node.js backend FROM node:18 # Set the working directory WORKDIR /app # Copy backend dependencies COPY backend/package.json backend/package-lock.json ./backend/ RUN cd backend && npm install # Copy the Vite build output from Stage 1 to the backend's static folder COPY --from=build /app/frontend/dist ./backend/build # Copy the backend source code COPY backend ./backend # Ensure database folder exists and has correct permissions RUN mkdir -p /app/backend/database && chmod -R 777 /app/backend/database \ && touch /app/backend/server.log && chmod 777 /app/backend/server.log # Expose the backend's port EXPOSE 7860 # Set working directory to backend WORKDIR /app/backend # Start the backend server CMD [ "node", "./index.js" ]