diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml new file mode 100644 index 0000000..18113e8 --- /dev/null +++ b/deploy/docker-compose.yml @@ -0,0 +1,72 @@ +services: + + # ── Init: копирует web/ из образа в shared volume (нужен nginx) ───────── + web_init: + image: breadcrumb-the-shire:latest + volumes: + - web_assets:/target + command: sh -c "cp -rp /var/www/web/. /target/ && echo 'Web assets OK'" + restart: "no" + + # ── nginx: отдаёт статику + FastCGI → php ─────────────────────────────── + nginx: + image: nginx:1.25-alpine + ports: + - "127.0.0.1:8084:80" # host nginx проксирует сюда + volumes: + - ./nginx/site.conf:/etc/nginx/conf.d/default.conf:ro + - web_assets:/var/www/web:ro + depends_on: + web_init: + condition: service_completed_successfully + php: + condition: service_started + restart: unless-stopped + + # ── PHP-FPM: весь код внутри образа ───────────────────────────────────── + php: + image: breadcrumb-the-shire:latest + env_file: .env + volumes: + - ./storage:/var/www/storage + - ./var:/var/www/var + depends_on: + - db + - memcached + restart: unless-stopped + + # ── Планировщик задач ──────────────────────────────────────────────────── + scheduler: + image: breadcrumb-the-shire:latest + env_file: .env + volumes: + - ./storage:/var/www/storage + - ./var:/var/www/var + depends_on: + - db + - memcached + command: sh -c "while true; do php -d display_errors=0 bin/console scheduler:run || true; sleep 60; done" + restart: unless-stopped + + # ── MariaDB ────────────────────────────────────────────────────────────── + db: + image: mariadb:11.4 + command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + env_file: .env + environment: + MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} + MARIADB_DATABASE: ${DB_NAME} + MARIADB_USER: ${DB_USER} + MARIADB_PASSWORD: ${DB_PASS} + volumes: + - db_data:/var/lib/mysql + restart: unless-stopped + + # ── Memcached ──────────────────────────────────────────────────────────── + memcached: + image: memcached:1.6-alpine + restart: unless-stopped + +volumes: + web_assets: # статика из образа (web/) + db_data: # данные MariaDB diff --git a/deploy/nginx/site.conf b/deploy/nginx/site.conf new file mode 100644 index 0000000..1f9b490 --- /dev/null +++ b/deploy/nginx/site.conf @@ -0,0 +1,37 @@ +# Docker nginx — только HTTP (SSL терминируется на host nginx) +server { + listen 80; + server_name projects.breadcrumb-online.de; + + client_max_body_size 10M; + + root /var/www/web; + index index.php; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + # SSL терминирован на host nginx — передаём это в PHP + fastcgi_param HTTPS on; + fastcgi_param HTTP_X_FORWARDED_PROTO https; + fastcgi_pass php:9000; + fastcgi_hide_header Cache-Control; + add_header Cache-Control "no-store, no-cache, must-revalidate, private" always; + } + + location ~* \.mjs$ { + default_type application/javascript; + try_files $uri =404; + expires 30d; + access_log off; + } + + location ~* \.(css|js|png|jpg|jpeg|gif|svg|ico|webp|woff2?)$ { + expires 30d; + access_log off; + } +} diff --git a/deploy/setup.sh b/deploy/setup.sh new file mode 100644 index 0000000..f028581 --- /dev/null +++ b/deploy/setup.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# setup.sh — первоначальная настройка на сервере +# Запускать один раз: bash setup.sh +set -e + +DEPLOY_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$DEPLOY_DIR" + +echo "=== [1/4] Загружаем образ в Docker ===" +docker load < breadcrumb-the-shire.tar.gz + +echo "=== [2/4] Создаём папки для данных ===" +mkdir -p storage/logs storage/runtime storage/users +mkdir -p var/cache var/log var/tmp +mkdir -p nginx/certs + +echo "=== [3/4] Права на папки ===" +chmod 755 storage var +chmod 775 storage/logs storage/runtime storage/users +chmod 775 var/cache var/log var/tmp + +echo "=== [4/4] Готово! ===" +echo "" +echo "Следующие шаги:" +echo " 1. Получи SSL-сертификат:" +echo " certbot certonly --standalone -d projects.breadcrumb-online.de" +echo "" +echo " 2. Скопируй сертификаты:" +echo " cp /etc/letsencrypt/live/projects.breadcrumb-online.de/fullchain.pem nginx/certs/" +echo " cp /etc/letsencrypt/live/projects.breadcrumb-online.de/privkey.pem nginx/certs/" +echo "" +echo " 3. Запусти стек:" +echo " docker compose up -d" +echo "" +echo " 4. Проверь логи:" +echo " docker compose logs -f"