version: '3.8'

services:
  # MySQL数据库服务
  mysql:
    image: mysql:8.0
    container_name: nxxmdata-mysql
    environment:
      MYSQL_ROOT_PASSWORD: aiotAiot123!
      MYSQL_DATABASE: ningxia_zhengfu
      MYSQL_USER: nxxmdata_user
      MYSQL_PASSWORD: NxxmData2024!@#
    volumes:
      - mysql_data:/var/lib/mysql
      - ./government-backend/database/init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "3306:3306"
    restart: unless-stopped
    networks:
      - nxxmdata-network

  # Redis缓存服务
  redis:
    image: redis:7-alpine
    container_name: nxxmdata-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    restart: unless-stopped
    networks:
      - nxxmdata-network

  # Government Backend服务
  government-backend:
    build: ./government-backend
    container_name: nxxmdata-government-backend
    environment:
      NODE_ENV: production
      PORT: 5352
      DB_DIALECT: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: ningxia_zhengfu
      DB_USER: root
      DB_PASSWORD: aiotAiot123!
      JWT_SECRET: government_super_secret_jwt_key_2024_very_long_and_secure
      LOG_LEVEL: info
      CORS_ORIGIN: "*"
      REDIS_HOST: redis
      REDIS_PORT: 6379
    ports:
      - "5352:5352"
    depends_on:
      - mysql
      - redis
    volumes:
      - uploads_data:/app/uploads
      - logs_data:/app/logs
    restart: unless-stopped
    networks:
      - nxxmdata-network

  # 养殖端后端服务
  backend:
    build: ./backend
    container_name: nxxmdata-backend
    environment:
      NODE_ENV: production
      PORT: 5350
      DB_HOST: mysql
      REDIS_HOST: redis
    ports:
      - "5350:5350"
    depends_on:
      - mysql
      - redis
    volumes:
      - uploads_data:/app/uploads
    restart: unless-stopped
    networks:
      - nxxmdata-network

  # 管理后台前端
  admin:
    build: ./admin-system
    container_name: nxxmdata-admin
    ports:
      - "5300:80"
    restart: unless-stopped
    networks:
      - nxxmdata-network

  # 官网前端
  website:
    build: ./website
    container_name: nxxmdata-website
    ports:
      - "8081:80"
    restart: unless-stopped
    networks:
      - nxxmdata-network

  # Nginx反向代理
  nginx:
    image: nginx:alpine
    container_name: nxxmdata-nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/ssl:/etc/ssl
      - uploads_data:/var/www/uploads
    depends_on:
      - government-backend
      - backend
      - admin
      - website
    restart: unless-stopped
    networks:
      - nxxmdata-network

volumes:
  mysql_data:
  redis_data:
  uploads_data:
  logs_data:

networks:
  nxxmdata-network:
    driver: bridge