version: '3.8'

services:
  # PHP Application
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: kicktipp-app
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ./public:/var/www/html
      - ./src:/var/www/src
      - ./config:/var/www/config
      - ./scripts:/var/www/scripts
      - ./database:/var/www/database
    environment:
      - DB_HOST=db
      - DB_PORT=3306
      - DB_NAME=kicktipp_antenne_peine
      - DB_USER=kicktipp_user
      - DB_PASS=kicktipp_password
      - APP_ENV=production
      - JWT_SECRET=your-secret-key-change-in-production
    depends_on:
      - db
    networks:
      - kicktipp-network

  # MySQL Database
  db:
    image: mysql:8.0
    container_name: kicktipp-db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: kicktipp_antenne_peine
      MYSQL_USER: kicktipp_user
      MYSQL_PASSWORD: kicktipp_password
    volumes:
      - mysql_data:/var/lib/mysql
      - ./database/schema.sql:/docker-entrypoint-initdb.d/schema.sql
    ports:
      - "3307:3306"
    networks:
      - kicktipp-network

  # Cron Job für Synchronisation
  cron:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: kicktipp-cron
    restart: unless-stopped
    volumes:
      - ./scripts:/var/www/scripts
      - ./src:/var/www/src
      - ./config:/var/www/config
      - ./database:/var/www/database
    environment:
      - DB_HOST=db
      - DB_PORT=3306
      - DB_NAME=kicktipp_antenne_peine
      - DB_USER=kicktipp_user
      - DB_PASS=kicktipp_password
    depends_on:
      - db
    command: >
      sh -c "
        echo '0 6 * * * php /var/www/scripts/sync.php >> /var/log/cron.log 2>&1' > /etc/cron.d/sync-cron &&
        chmod 0644 /etc/cron.d/sync-cron &&
        crontab /etc/cron.d/sync-cron &&
        cron -f
      "
    networks:
      - kicktipp-network

volumes:
  mysql_data:

networks:
  kicktipp-network:
    driver: bridge 