version: '3.8'

services:
  scheduled-task-service:
    build:
      context: ../../
      dockerfile: deploy/docker/Dockerfile
    container_name: scheduled-task-service
    ports:
      - "8088:8088"
    environment:
      - SPRING_PROFILES_ACTIVE=docker
      - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/erp_task?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
      - SPRING_DATASOURCE_USERNAME=root
      - SPRING_DATASOURCE_PASSWORD=nihao588+
      - SPRING_DATA_REDIS_HOST=redis
      - SPRING_DATA_REDIS_PORT=6379
      - SPRING_DATA_REDIS_PASSWORD=Y(@r5tGk9$Lp2
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - erp-network
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8088/actuator/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  mysql:
    image: mysql:8.0
    container_name: erp-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=nihao588+
      - MYSQL_DATABASE=erp_task
    ports:
      - "3306:3306"
    volumes:
      - mysql-data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - erp-network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-pnihao588+"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    container_name: erp-redis
    command: redis-server --requirepass Y(@r5tGk9$Lp2
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    networks:
      - erp-network
    healthcheck:
      test: ["CMD", "redis-cli", "-a", "Y(@r5tGk9$Lp2", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

networks:
  erp-network:
    driver: bridge

volumes:
  mysql-data:
  redis-data:
