services:
  mysql:
    image: mysql:8.0
    container_name: bebana-mysql
    environment:
      MYSQL_DATABASE: bebana
      MYSQL_USER: morgan
      MYSQL_PASSWORD: morgan
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "6306:3306"
    volumes:
      - ./mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h localhost -u root -p root || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 10

  postgres:
    image: postgis/postgis:16-3.4
    container_name: bebana-postgres
    environment:
      POSTGRES_DB: route
      POSTGRES_USER: morgan
      POSTGRES_PASSWORD: morgan
    ports:
      - "6432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init-postgis.sql:/docker-entrypoint-initdb.d/init-postgis.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U morgan -d route"]
      interval: 10s
      timeout: 5s
      retries: 10

  bebana-app:
    container_name: bebana-app
    build:
      context: .
      dockerfile: Dockerfile.mysql
    depends_on:
      mysql:
        condition: service_healthy
    ports:
      - "6080:8080"
    volumes:
      - ./bebana-0.0.1.jar:/app/bebana.jar
    environment:
      SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/bebana
      SPRING_DATASOURCE_USERNAME: morgan
      SPRING_DATASOURCE_PASSWORD: morgan
      SPRING_PROFILES_ACTIVE: dev
    restart: unless-stopped

  route-app:
    build:
      context: .
      dockerfile: Dockerfile.route
    container_name: route-app
    ports:
      - "6081:8080"
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - ./route-0.0.1.jar:/app/route.jar

volumes:
  postgres_data:

