2024-05-13 14:22:31 +00:00
|
|
|
# Stage 1: Build the React app using Vite
|
|
|
|
FROM node:18 AS build
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Copy package.json and package-lock.json to install dependencies
|
|
|
|
COPY package*.json ./
|
|
|
|
RUN yarn install
|
|
|
|
|
|
|
|
# Copy source code
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
# Set environment variables
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
|
|
|
|
# Build the React app using Vite
|
|
|
|
RUN yarn run build
|
|
|
|
|
|
|
|
# Stage 2: Create a lightweight production image
|
|
|
|
FROM nginx:alpine
|
|
|
|
COPY --from=build /app/dist /usr/share/nginx/html
|
|
|
|
|
|
|
|
#copy public folder
|
|
|
|
COPY --from=build /app/public /usr/share/nginx/html
|
|
|
|
|
2024-05-13 18:33:17 +00:00
|
|
|
#copy allowed mime types and nginx config
|
2024-05-13 14:22:31 +00:00
|
|
|
COPY ./nginx/mime.types /etc/nginx/mime.types
|
2024-05-13 18:40:22 +00:00
|
|
|
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf
|
2024-05-13 14:22:31 +00:00
|
|
|
|
|
|
|
# Expose port 80 to access the app
|
|
|
|
EXPOSE 80
|
|
|
|
|
|
|
|
# Start Nginx server
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|