74 lines
1.8 KiB
Docker
74 lines
1.8 KiB
Docker
# Multi-stage build for development and production
|
|
FROM node:22-slim AS base
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Development stage
|
|
FROM base AS development
|
|
RUN npm install
|
|
COPY . .
|
|
EXPOSE 5173
|
|
CMD ["npm", "run", "dev"]
|
|
|
|
# Build stage
|
|
FROM base AS build
|
|
|
|
# Accept build argument for API URL
|
|
ARG VITE_API_URL
|
|
ENV VITE_API_URL=$VITE_API_URL
|
|
|
|
# Install build dependencies for native modules (Debian-based)
|
|
RUN apt-get update && apt-get install -y \
|
|
python3 \
|
|
make \
|
|
g++ \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install dependencies
|
|
RUN npm ci --only=production && npm cache clean --force
|
|
RUN npm install typescript @vitejs/plugin-react vite
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application with environment variable available
|
|
RUN npm run build
|
|
|
|
# Production stage
|
|
FROM nginx:alpine AS production
|
|
|
|
# Copy custom nginx configuration
|
|
COPY nginx.conf /etc/nginx/nginx.conf
|
|
|
|
# Copy built application from build stage
|
|
COPY --from=build /app/dist /usr/share/nginx/html
|
|
|
|
# Create non-root user for security
|
|
RUN addgroup -g 1001 -S appuser && \
|
|
adduser -S appuser -u 1001 -G appuser
|
|
|
|
# Set proper permissions and create necessary directories
|
|
RUN chown -R appuser:appuser /usr/share/nginx/html && \
|
|
chown -R appuser:appuser /var/cache/nginx && \
|
|
chown -R appuser:appuser /var/log/nginx && \
|
|
chown -R appuser:appuser /etc/nginx/conf.d && \
|
|
mkdir -p /tmp/nginx && \
|
|
chown -R appuser:appuser /tmp/nginx && \
|
|
touch /tmp/nginx/nginx.pid && \
|
|
chown appuser:appuser /tmp/nginx/nginx.pid
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost/ || exit 1
|
|
|
|
EXPOSE 80
|
|
|
|
# Start nginx
|
|
CMD ["nginx", "-g", "daemon off;"]
|