# Modern Dockerfile for Vite + React application # Build stage FROM 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/* # Copy built application COPY --from=builder /app/build /usr/share/nginx/html # 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 curl -f http://localhost/ || exit 1 # Start nginx CMD ["nginx", "-g", "daemon off;"]