Spaces:
Running
Running
| # Stage 1: Build the React app | |
| FROM node:16-alpine AS build | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy package.json and package-lock.json | |
| COPY package*.json ./ | |
| # Install dependencies | |
| RUN npm install | |
| # Copy the rest of the application code | |
| COPY . . | |
| # Build the React app | |
| RUN npm run build | |
| # Stage 2: Serve the built app with a lightweight web server | |
| FROM nginx:alpine | |
| # Set up a new user named "user" with user ID 1001 | |
| RUN adduser -D -u 1001 user | |
| # Switch to the root user to perform privileged operations | |
| USER root | |
| # Remove the default Nginx configuration file | |
| RUN rm /etc/nginx/conf.d/default.conf | |
| # Copy the built files from the previous stage | |
| COPY --from=build /app/dist /usr/share/nginx/html | |
| # Replace the default nginx.conf with our configuration | |
| COPY nginx.conf /etc/nginx/nginx.conf | |
| # Create the necessary directories and set the correct permissions | |
| RUN mkdir -p /var/cache/nginx/client_temp /var/cache/nginx/proxy_temp /var/cache/nginx/fastcgi_temp /var/cache/nginx/uwsgi_temp /var/cache/nginx/scgi_temp && \ | |
| chown -R user:user /usr/share/nginx/html /etc/nginx /var/cache/nginx /var/run /var/log/nginx | |
| # Ensure the /var/run/nginx.pid file has correct permissions | |
| RUN touch /var/run/nginx.pid && chown user:user /var/run/nginx.pid | |
| # Switch back to the "user" user | |
| USER user | |
| # Expose port 7860 | |
| EXPOSE 7860 | |
| # Start Nginx server | |
| CMD ["nginx", "-g", "daemon off;"] | |