version: '3.8'

services:
  backend:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: polyhermes-backend
    ports:
      - "${SERVER_PORT:-8000}:8000"
    environment:
      - SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE:-prod}
      - DB_URL=${DB_URL:-jdbc:mysql://mysql:3306/polyhermes?useSSL=false&serverTimezone=UTC&characterEncoding=utf8&allowPublicKeyRetrieval=true}
      - DB_USERNAME=${DB_USERNAME:-root}
      - DB_PASSWORD=${DB_PASSWORD:-}
      - SERVER_PORT=8000
      - JWT_SECRET=${JWT_SECRET:-change-me-in-production}
      - ADMIN_RESET_PASSWORD_KEY=${ADMIN_RESET_PASSWORD_KEY:-change-me-in-production}
    depends_on:
      mysql:
        condition: service_healthy
    restart: unless-stopped
    networks:
      - polyhermes-network

  mysql:
    image: mysql:8.2
    container_name: polyhermes-mysql
    ports:
      - "${MYSQL_PORT:-3306}:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=${DB_PASSWORD:-rootpassword}
      - MYSQL_DATABASE=polyhermes
      - MYSQL_CHARACTER_SET_SERVER=utf8mb4
      - MYSQL_COLLATION_SERVER=utf8mb4_unicode_ci
    volumes:
      - mysql-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${DB_PASSWORD:-rootpassword}"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped
    networks:
      - polyhermes-network

volumes:
  mysql-data:

networks:
  polyhermes-network:
    driver: bridge

