version: '3'

services:
  user-db:
    image: mysql:8.0.31-debian
    hostname: user-db
    container_name: user-db
    ports:
      - 3380:3306
    environment:
      - MYSQL_ROOT_PASSWORD=123456
      - MYSQL_ROOT_HOST=%
      - MYSQL_DATABASE=user
    # volumes:
    #   - ./data/mysql/user:/var/lib/mysql
    #   - ./conf/mysql/conf.d:/etc/mysql/conf.d
  cache-redis:
    image: redis:6-alpine
    hostname: cache-redis
    # volumes:
    #   - ./data/redis/cache/:/data
    #   - ./conf/redis/cache/redis.conf:/etc/redis/redis.conf
    ports:
      - 6350:6379
    command: ["redis-server","/etc/redis/redis.conf"]
  
  # API服务器
  api-server:
    build:
      context: ../../
      dockerfile: deploy/build/Dockerfile
      args:
        - APP_NAME=app
        - APP_RELATIVE_PATH=./cmd/server/main.go
        - APP_ENV=prod
    image: nunu-api:latest
    container_name: nunu-api
    environment:
      - APP_CONF=config/prod.yml
    ports:
      - 8000:8000
    depends_on:
      - user-db
      - cache-redis
    restart: always

  # 任务服务
  task-server:
    build:
      context: ../../
      dockerfile: deploy/build/Dockerfile
      args:
        - APP_NAME=task
        - APP_RELATIVE_PATH=./cmd/task/main.go
        - APP_ENV=prod
    image: nunu-task:latest
    container_name: nunu-task
    environment:
      - APP_CONF=config/prod.yml
    depends_on:
      - user-db
      - cache-redis
    restart: always
