Commit
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
# Stage 1: Build the React app (Frontend)
|
||||
FROM node:18-slim AS frontend-build
|
||||
# Combined Frontend and Backend Setup
|
||||
FROM node:18-slim AS combined-build
|
||||
WORKDIR /app
|
||||
|
||||
# Copy frontend files
|
||||
# Copy and install frontend dependencies
|
||||
COPY frontend/package*.json ./frontend/
|
||||
WORKDIR /app/frontend
|
||||
RUN npm install
|
||||
COPY frontend/ .
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: Setup Nginx to serve the React App
|
||||
FROM nginx:alpine AS frontend-server
|
||||
COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
# Stage 3: Setup the Backend
|
||||
FROM node:18-slim AS backend
|
||||
# Copy frontend build output to /app directory
|
||||
WORKDIR /app
|
||||
RUN mkdir -p /app/public
|
||||
COPY --from=combined-build /app/frontend/dist /app/public
|
||||
|
||||
# Copy package.json to /app directory
|
||||
COPY frontend/package*.json ./
|
||||
# Setup backend
|
||||
COPY backend/package*.json ./
|
||||
RUN npm install
|
||||
|
||||
# Copy remaining backend files
|
||||
COPY backend/ .
|
||||
|
||||
# Run backend
|
||||
# Setup Nginx to serve the React App
|
||||
FROM nginx:alpine
|
||||
COPY --from=combined-build /app/public /usr/share/nginx/html
|
||||
|
||||
# Expose ports for frontend and backend
|
||||
EXPOSE 80
|
||||
EXPOSE 3001
|
||||
CMD ["node", "/app/src/components/server.js"]
|
||||
|
||||
# Run backend and frontend servers
|
||||
CMD ["sh", "-c", "node /app/src/components/server.js & nginx -g 'daemon off;'"]
|
||||
Reference in New Issue
Block a user