version: '3.8'

services:
  app:
    build: .
    container_name: tag-app
    ports:
      - "8080:8080"
    environment:
      # Match property names exactly as Spring Boot expects (uppercase with underscores is OK)
      - SPRING_DATASOURCE_URL=jdbc:mysql://db:3306/trackash_tag_db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
      - SPRING_DATASOURCE_USERNAME=trackash_root
      - SPRING_DATASOURCE_PASSWORD=letusgrindAB12@@
      - SPRING_JPA_HIBERNATE_DDL_AUTO=update
      - SERVER_PORT=8080
      - SERVER_ADDRESS=0.0.0.0
      - SPRING_DATA_REDIS_HOST=redis
      - SPRING_DATA_REDIS_PORT=6379
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    restart: unless-stopped

  db:
    image: mysql:8.0
    container_name: tag-mysql
    environment:
      MYSQL_ROOT_PASSWORD: letusgrindAB12@@
      MYSQL_DATABASE: trackash_tag_db
      MYSQL_USER: trackash_root          # ← This creates the user
      MYSQL_PASSWORD: letusgrindAB12@@   # ← Password for the new user
    ports:
      - "3307:3306"
    volumes:
      - mysql-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "trackash_root"]
      interval: 10s
      timeout: 5s
      retries: 20
      start_period: 30s   # Gives MySQL time to initialize
    restart: unless-stopped

  redis:
    image: redis:7
    container_name: tag-redis
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  mysql-data:
  redis-data:
