70 lines
1.5 KiB
Docker
70 lines
1.5 KiB
Docker
|
|
# Multi-stage Dockerfile para Frontend React + Vite
|
||
|
|
FROM node:20-alpine AS build
|
||
|
|
|
||
|
|
# Argumentos de construcción
|
||
|
|
ARG VITE_API_URL
|
||
|
|
ARG VITE_WS_URL
|
||
|
|
|
||
|
|
ENV VITE_API_URL=${VITE_API_URL}
|
||
|
|
ENV VITE_WS_URL=${VITE_WS_URL}
|
||
|
|
|
||
|
|
WORKDIR /app
|
||
|
|
|
||
|
|
# Copiar archivos de dependencias
|
||
|
|
COPY package*.json ./
|
||
|
|
|
||
|
|
# Instalar dependencias
|
||
|
|
RUN npm install
|
||
|
|
|
||
|
|
# Copiar código fuente
|
||
|
|
COPY . .
|
||
|
|
|
||
|
|
# Build de producción
|
||
|
|
RUN npm run build
|
||
|
|
|
||
|
|
# ================================
|
||
|
|
# Stage de producción con Nginx
|
||
|
|
# ================================
|
||
|
|
FROM nginx:alpine AS production
|
||
|
|
|
||
|
|
# Copiar archivos compilados
|
||
|
|
COPY --from=build /app/dist /usr/share/nginx/html
|
||
|
|
|
||
|
|
# Copiar configuración de nginx personalizada
|
||
|
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||
|
|
|
||
|
|
# Crear usuario no-root y configurar permisos
|
||
|
|
RUN chown -R nginx:nginx /usr/share/nginx/html && \
|
||
|
|
chown -R nginx:nginx /var/cache/nginx && \
|
||
|
|
chown -R nginx:nginx /var/log/nginx && \
|
||
|
|
chown nginx:nginx /etc/nginx/conf.d/default.conf && \
|
||
|
|
chmod 644 /etc/nginx/conf.d/default.conf && \
|
||
|
|
touch /var/run/nginx.pid && \
|
||
|
|
chown -R nginx:nginx /var/run/nginx.pid
|
||
|
|
|
||
|
|
USER nginx
|
||
|
|
|
||
|
|
EXPOSE 80
|
||
|
|
|
||
|
|
# Health check
|
||
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||
|
|
CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
|
||
|
|
|
||
|
|
CMD ["nginx", "-g", "daemon off;"]
|
||
|
|
|
||
|
|
# ================================
|
||
|
|
# Stage de desarrollo
|
||
|
|
# ================================
|
||
|
|
FROM node:20-alpine AS development
|
||
|
|
|
||
|
|
WORKDIR /app
|
||
|
|
|
||
|
|
COPY package*.json ./
|
||
|
|
RUN npm install
|
||
|
|
|
||
|
|
COPY . .
|
||
|
|
|
||
|
|
EXPOSE 5173
|
||
|
|
|
||
|
|
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
|