anthil_web/Dockerfile
ilya_zahvatkin 5db40f2b2d add docker
2025-09-11 12:10:39 +07:00

58 lines
1.7 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Multi-stage build для React приложения
FROM node:18-alpine AS builder
# Устанавливаем рабочую директорию
WORKDIR /app
# Копируем package.json и package-lock.json
COPY package*.json ./
# Устанавливаем зависимости
RUN npm ci --only=production
# Копируем исходный код
COPY . .
# Собираем приложение для production
RUN npm run build
# Production stage с Nginx
FROM nginx:alpine
# Копируем собранное приложение из builder stage
COPY --from=builder /app/build /usr/share/nginx/html
# Создаем оптимизированную конфигурацию Nginx для SPA
RUN echo 'server { \
listen 80; \
server_name localhost; \
root /usr/share/nginx/html; \
index index.html; \
\
# Обслуживание React Router (SPA) \
location / { \
try_files $uri $uri/ /index.html; \
} \
\
# Кэширование статических файлов \
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|webp|woff|woff2|ttf|eot)$ { \
expires 1y; \
add_header Cache-Control "public, immutable"; \
add_header Vary Accept-Encoding; \
} \
\
# Безопасность - запрещаем доступ к служебным файлам \
location ~ /\. { \
deny all; \
} \
\
# Gzip сжатие \
gzip on; \
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; \
}' > /etc/nginx/conf.d/default.conf
# Открываем порт 80
EXPOSE 80
# Запускаем Nginx
CMD ["nginx", "-g", "daemon off;"]