services:
  app:
    build: .
    container_name: webgis-portal-app
    restart: unless-stopped
    expose:
      - "80"
    environment:
      DB_HOST: ${DB_HOST:-db}
      DB_DATABASE: ${DB_DATABASE:-webgis_miskin}
      DB_USERNAME: ${DB_USERNAME:-webgis_user}
      DB_PASSWORD: ${DB_PASSWORD:-webgis_password}
      DB_CHARSET: ${DB_CHARSET:-utf8mb4}
      DB_SETUP_USERNAME: ${DB_SETUP_USERNAME:-root}
      DB_SETUP_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root_password}
      SPBU_DB_HOST: ${SPBU_DB_HOST:-db}
      SPBU_DB_DATABASE: ${SPBU_DB_DATABASE:-webgis_spbu}
      SPBU_DB_USERNAME: ${SPBU_DB_USERNAME:-webgis_user}
      SPBU_DB_PASSWORD: ${SPBU_DB_PASSWORD:-webgis_password}
    depends_on:
      db:
        condition: service_healthy

  db:
    image: mysql:8.0
    container_name: webgis-portal-db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root_password}
      MYSQL_DATABASE: ${DB_DATABASE:-webgis_miskin}
      MYSQL_USER: ${DB_USERNAME:-webgis_user}
      MYSQL_PASSWORD: ${DB_PASSWORD:-webgis_password}
    volumes:
      - db_data:/var/lib/mysql
      - ./Leaflet/sql/schema.sql:/docker-entrypoint-initdb.d/01-spbu-schema.sql:ro
      - ./Leaflet/sql/spatial_schema.sql:/docker-entrypoint-initdb.d/02-spbu-spatial.sql:ro
      - ./Leaflet2/sql/miskin_schema.sql:/docker-entrypoint-initdb.d/03-miskin-schema.sql:ro
      - ./docker/mysql-init/99-grants.sql:/docker-entrypoint-initdb.d/99-grants.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h localhost -uroot -p$${MYSQL_ROOT_PASSWORD}"]
      interval: 10s
      timeout: 5s
      retries: 10

volumes:
  db_data:
