services:
  db:
    image: mariadb:10.11
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    volumes:
      - tas_councils_db_data:/var/lib/mysql
    restart: unless-stopped
    ports:
      - "3306:3306"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uscraper", "-pscr@perpass"]
      interval: 10s
      timeout: 5s
      retries: 10

  adminer:
    image: adminer
    ports:
      - "9980:8080"
    depends_on:
      - db
    restart: unless-stopped

  scraper:
    build: .
    environment:
      MYSQL_HOST: db
      MYSQL_PORT: "3306"
      MYSQL_DB: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      # If set, the runner loops. Minutes between runs:
      SCRAPE_EVERY_MINUTES: "720"
      COUNCIL_WHITELIST: "Hobart City Council,Launceston City Council,Clarence City Council"
      GOOGLE_MAPS_API_KEY: ${GOOGLE_MAPS_API_KEY}
      DOWNLOAD_ATTACHMENTS: "1"
      DOWNLOAD_DIR: /downloads
      LOOKUP_URL: ${LOOKUP_URL}
      LOOKUP_THROTTLE_MS: ${LOOKUP_THROTTLE_MS:-150}
      # Log verbosity: debug | info (default) | warn | error
      LOG_LEVEL: ${LOG_LEVEL:-info}
      # SMTP — summary error emails (optional; leave blank to disable)
      SMTP_HOST: ${SMTP_HOST:-}
      SMTP_PORT: ${SMTP_PORT:-587}
      SMTP_USERNAME: ${SMTP_USERNAME:-}
      SMTP_PASSWORD: ${SMTP_PASSWORD:-}
      SMTP_SMTPSecure: ${SMTP_SMTPSecure:-tls}
      SMTP_SENTFROM: ${SMTP_SENTFROM:-}
      SMTP_ADDADDRESS: ${SMTP_ADDADDRESS:-}
    volumes:
      - ./scrapers:/app/scrapers:ro
      - ./downloads:/downloads
      - ./lib:/app/lib:ro
    depends_on:
      db:
        condition: service_healthy
    # Default runs all once and exits. To loop, set SCRAPE_EVERY_MINUTES env above.
    command: ["/app/entrypoint.sh"]
    restart: unless-stopped

  web:
    build: ./web
    image: councils-web:latest
    volumes:
      - ./web:/var/www/html:ro
      - ./downloads:/srv/files:ro
      - ./web/000-files.conf:/etc/apache2/conf-enabled/000-files.conf:ro
    ports:
      - "9981:80"
    environment:
      MYSQL_HOST: db
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped

volumes:
  tas_councils_db_data:
    external: true
