# Modern Dockerfile for Vite + React application # Build stage FROM node:24.9-alpine3.21 AS builder WORKDIR /app ARG OWN_NPM_TOKEN # Copy npm config required for private registry access. Ensure the build context includes .npmrc. COPY .npmrc .npmrc # Copy package files COPY package*.json ./ # Install dependencies (include devDependencies for Vite build) RUN npm ci RUN rm -f .npmrc # Copy source code COPY . . # Build the application ARG VITE_BASE_PATH="" ENV VITE_BASE_PATH=${VITE_BASE_PATH} RUN npm run build # Production stage - Use nginx for better performance FROM nginx:1.29.1-alpine # Remove default nginx website RUN rm -rf /usr/share/nginx/html/* # Create subfolder structure dynamically based on VITE_BASE_PATH ARG VITE_BASE_PATH="" RUN if [ -n "$VITE_BASE_PATH" ]; then mkdir -p /usr/share/nginx/html/$VITE_BASE_PATH; fi # Copy built application COPY --from=builder /app/build /usr/share/nginx/html/${VITE_BASE_PATH} # Copy nginx configuration COPY nginx.conf /etc/nginx/nginx.conf # Add environment variables ENV Author="Tudor Stanciu" ARG APP_VERSION=0.0.0 ENV APP_VERSION=${APP_VERSION} # Expose port 80 EXPOSE 80 # Health check HEALTHCHECK --interval=120s --timeout=10s --start-period=60s --retries=3 \ CMD if [ -n "$VITE_BASE_PATH" ]; then curl -f http://localhost/$VITE_BASE_PATH/ || exit 1; else curl -f http://localhost/ || exit 1; fi # Start nginx CMD ["nginx", "-g", "daemon off;"]