diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..636850c --- /dev/null +++ b/.dockerignore @@ -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/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c403ba4 --- /dev/null +++ b/Dockerfile @@ -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;"] \ No newline at end of file diff --git a/README-Docker.md b/README-Docker.md new file mode 100644 index 0000000..22ae603 --- /dev/null +++ b/README-Docker.md @@ -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 +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 +``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4b32929 --- /dev/null +++ b/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/nginx.conf b/nginx.conf index 710532f..ee858f7 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,42 +1,30 @@ -# You should look at the following URL's in order to grasp a solid understanding -# of Nginx configuration files in order to fully unleash the power of Nginx. -# https://www.nginx.com/resources/wiki/start/ -# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ -# https://wiki.debian.org/Nginx/DirectoryStructure -# -# 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 -# updated by the nginx packaging team. -# -# This file will automatically load configuration files provided by other -# applications, such as Drupal or Wordpress. These applications will be made -# available underneath a path with that package name, such as /drupal8. -# -# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. -## +server { + listen 80; + server_name anthillsib.ru www.anthillsib.ru; + + root /var/www/build; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { + expires max; + log_not_found off; + } + +} + + + + + -# Default server configuration -# 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; # Add index.php to the list if you are using PHP