services:
  nginx:
    image: nginx:1.25-alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./:/var/www
      - ./docker/nginx/prod.conf:/etc/nginx/conf.d/default.conf:ro
      - ./docker/nginx/certs:/etc/nginx/certs:ro
    depends_on:
      - php
    restart: unless-stopped

  php:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
      target: prod
    env_file:
      - .env
    environment:
      APP_ENV: prod
      APP_DEBUG: "0"
    volumes:
      - ./:/var/www
    depends_on:
      - db
      - memcached
    restart: unless-stopped

  scheduler:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
      target: prod
    env_file:
      - .env
    environment:
      APP_ENV: prod
      APP_DEBUG: "0"
    volumes:
      - ./:/var/www
    depends_on:
      - db
      - memcached
    command: sh -lc "while true; do php -d display_errors=0 bin/console scheduler:run || true; sleep 60; done"
    restart: unless-stopped

  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
      - ./db/init:/docker-entrypoint-initdb.d:ro
    restart: unless-stopped

  memcached:
    image: memcached:1.6-alpine
    restart: unless-stopped

volumes:
  db_data:
