2023-11-17 12:43:19 +00:00
|
|
|
# Stage 1: Building the React application
|
2023-12-12 11:14:24 +00:00
|
|
|
FROM node:20-alpine AS build
|
2023-11-17 12:43:19 +00:00
|
|
|
WORKDIR /app
|
|
|
|
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
|
|
|
RUN \
|
|
|
|
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
|
|
|
elif [ -f package-lock.json ]; then npm ci; \
|
|
|
|
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
|
2024-09-17 03:42:07 +00:00
|
|
|
else echo "Lockfile not found." && yarn; \
|
2023-11-17 12:43:19 +00:00
|
|
|
fi
|
|
|
|
COPY . .
|
|
|
|
RUN yarn build # or `npm run build` if using npm
|
|
|
|
|
|
|
|
# Stage 2: Setting up Nginx to serve the React application
|
|
|
|
FROM nginx:alpine AS production
|
|
|
|
# Copy built assets from 'build' stage
|
|
|
|
COPY --from=build /app/build /usr/share/nginx/html
|
|
|
|
# Optional: If you have a custom nginx.conf, you can copy it to the container
|
2024-09-17 03:42:07 +00:00
|
|
|
COPY nginx.conf /etc/nginx/nginx.conf
|
2023-12-04 08:19:05 +00:00
|
|
|
EXPOSE 80
|
2023-11-17 12:43:19 +00:00
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|