services:
  web:
    image: ubuntu:22.04
    container_name: plex-web
    build:
      context: .
      dockerfile: Dockerfile
      args:
        - IPADDRESS=${IPADDRESS}
    ports:
      - "8081:8081"
    volumes:
      - ./plex-panel:/var/www/html/plex-panel
      - ./apache2.conf:/etc/apache2/apache2.conf
    environment:
      - APP_URL=http://${IPADDRESS}
    depends_on:
      - db
    command: ["/usr/bin/bash", "/start.sh"]

  db:
    image: mysql:5.7
    container_name: plex-db
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: plexpanel
      MYSQL_USER: plexuser
      MYSQL_PASSWORD: plexpassword
    ports:
      - "3307:3307"
    volumes:
      - db_data:/var/lib/mysql
      - ./plexpanel.sql:/docker-entrypoint-initdb.d/plexpanel.sql

  cron:
    image: ubuntu:22.04
    container_name: plex-cron
    depends_on:
      - web
    command: >
      /bin/bash -c "apt-get update -y && apt-get install -y curl cron && echo '*/5 * * * * curl -s http://${IPADDRESS}/cron' | crontab - && cron -f"
    environment:
      - IPADDRESS=${IPADDRESS}

volumes:
  db_data:
