add docker

This commit is contained in:
ilya_zahvatkin 2025-09-11 12:10:39 +07:00
parent 7cb2f4df1c
commit 5db40f2b2d
5 changed files with 207 additions and 34 deletions

40
.dockerignore Normal file
View File

@ -0,0 +1,40 @@
# Игнорируем ненужные файлы при сборке Docker образа
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Файлы разработки
.git
.gitignore
README.md
.env.local
.env.development.local
.env.test.local
.env.production.local
# Системные файлы
.DS_Store
Thumbs.db
# IDE файлы
.vscode
.idea
*.swp
*.swo
# Временные файлы
*.tmp
*.temp
# Уже собранный build (будет пересобран в контейнере)
build
# Docker файлы (не нужны внутри образа)
Dockerfile
docker-compose.yml
.dockerignore
# Конфигурация nginx (заменится на оптимизированную)
nginx.conf
nginx/

58
Dockerfile Normal file
View File

@ -0,0 +1,58 @@
# 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;"]

57
README-Docker.md Normal file
View File

@ -0,0 +1,57 @@
# Docker Setup для Anthill Landing
## Быстрый старт
Запуск приложения на порту 8030:
```bash
# Сборка и запуск
docker compose up -d --build
# Проверка статуса
docker compose ps
# Просмотр логов
docker compose logs -f anthill-web
# Остановка
docker compose down
```
## Доступ
- **Локально**: http://localhost:8030
- **На сервере**: http://your-server-ip:8030
## Структура
- `Dockerfile` - Multi-stage сборка (Node.js + Nginx)
- `docker-compose.yml` - Конфигурация для запуска
- `.dockerignore` - Исключения для сборки
## Производство
Для production на сервере:
```bash
# Клонирование репозитория
git clone <repo-url>
cd anthill_web
# Запуск
docker compose up -d --build
# Обновление (при изменениях)
git pull
docker compose up -d --build --force-recreate
```
## Мониторинг
```bash
# Проверка здоровья контейнера
docker compose exec anthill-web wget -qO- http://localhost:80
# Использование ресурсов
docker stats anthill-web
```

30
docker-compose.yml Normal file
View File

@ -0,0 +1,30 @@
services:
anthill-web:
build:
context: .
dockerfile: Dockerfile
container_name: anthill-web
ports:
- "8030:80"
restart: unless-stopped
environment:
- NODE_ENV=production
# Опциональные настройки для production
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
# Проверка здоровья контейнера
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:80"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# Опциональная сеть для изоляции
networks:
default:
name: anthill-network

View File

@ -1,42 +1,30 @@
# You should look at the following URL's in order to grasp a solid understanding server {
# of Nginx configuration files in order to fully unleash the power of Nginx. listen 80;
# https://www.nginx.com/resources/wiki/start/ server_name anthillsib.ru www.anthillsib.ru;
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure root /var/www/build;
# index index.html;
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be location / {
# updated by the nginx packaging team. try_files $uri $uri/ /index.html;
# }
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
# available underneath a path with that package name, such as /drupal8. expires max;
# log_not_found off;
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. }
##
}
# Default server configuration
#
server { server {
listen 80 default_server; listen 80 default_server;
listen [::]:80 default_server; listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/build; root /var/www/build;
# Add index.php to the list if you are using PHP # Add index.php to the list if you are using PHP