|
1 |
| -# Stage 1: Build |
2 |
| -FROM node:18-alpine as build |
| 1 | +# Stage 1: Build React App |
| 2 | +FROM node:18-alpine AS build |
3 | 3 |
|
4 |
| -# Set working directory |
| 4 | +# Set working directory inside the container |
5 | 5 | WORKDIR /app
|
6 | 6 |
|
7 |
| -# Copy package.json and lock files first (for better caching) |
| 7 | +# Copy only package files for better layer caching |
8 | 8 | COPY package*.json ./
|
9 |
| -#COPY .npmrc .npmrc |
10 | 9 |
|
11 |
| -# Optional: clean npm cache (helps with weird issues) |
| 10 | +# Optional: clean npm cache |
12 | 11 | RUN npm cache clean --force
|
13 | 12 |
|
14 |
| -# Manually install ajv v6 and ajv-keywords v3 to avoid breaking changes |
| 13 | +# Install ajv v6 and ajv-keywords v3 to avoid breaking changes |
15 | 14 | RUN npm install ajv@6 ajv-keywords@3 --legacy-peer-deps
|
16 | 15 |
|
17 |
| -# Now copy the rest of the app |
18 |
| -COPY . . |
19 |
| - |
20 |
| -# Install remaining dependencies with legacy flag |
| 16 | +# Install other dependencies |
21 | 17 | RUN npm install --legacy-peer-deps
|
22 | 18 |
|
23 |
| -# Build the app |
| 19 | +# Copy the rest of the application code |
| 20 | +COPY . . |
| 21 | + |
| 22 | +# Build the React application |
24 | 23 | RUN npm run build
|
25 | 24 |
|
26 |
| -# Stage 2: Serve the build output |
| 25 | +# Stage 2: Serve with Nginx |
27 | 26 | FROM nginx:alpine
|
28 | 27 |
|
29 |
| -# Copy only the frontend build output |
30 |
| -COPY --from=build /app/packages/react-scripts/build /usr/share/nginx/html |
| 28 | +# Remove default nginx static files |
| 29 | +RUN rm -rf /usr/share/nginx/html/* |
| 30 | + |
| 31 | +# Copy build output from previous stage |
| 32 | +COPY --from=build /app/build /usr/share/nginx/html |
| 33 | + |
| 34 | +# Copy custom nginx config if you have one (optional) |
| 35 | +# COPY nginx.conf /etc/nginx/nginx.conf |
31 | 36 |
|
32 | 37 | # Expose port 80
|
33 | 38 | EXPOSE 80
|
|
0 commit comments