version: "3.9"

services:
  db:
    image: mysql:8.0
    container_name: honey-mysql
    restart: always
    environment:
      MYSQL_DATABASE: ${DB_NAME:honey_db}
      MYSQL_USER: ${DB_USERNAME:root}
      MYSQL_PASSWORD: ${DB_PASSWORD:password}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:password}
    ports:
      - "3306:3306"
    volumes:
      - honey_mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${DB_ROOT_PASSWORD:password}"]
      interval: 10s
      timeout: 5s
      retries: 5

  app:
    env_file:
      - .env
    build: .
    container_name: honey-backend
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "8080:8080"
    environment:
      - SPRING_DATASOURCE_URL=jdbc:mysql://db:3306/${DB_NAME:honey_db}
      - SPRING_DATASOURCE_USERNAME=${DB_USERNAME:root}
      - SPRING_DATASOURCE_PASSWORD=${DB_PASSWORD:password}

volumes:
  honey_mysql_data:


