# docker-compose.yml pins services to a tested release for reproducible deployments.
# Use docker-compose.latest.yml if you prefer to track the :latest container tags.
x-environment: &default-env
  SQLALCHEMY_DATABASE_URI: mysql://root:ai-shifu@ai-shifu-mysql:3306/ai-shifu?charset=utf8mb4
  SECRET_KEY: ai-shifu
  UNIVERSAL_VERIFICATION_CODE: 1024
  REDIS_HOST: ai-shifu-redis
  REDIS_PORT: 6379
  SKIP_LOAD_DOTENV: "1"
  CELERY_BROKER_URL: redis://ai-shifu-redis:6379/0
  CELERY_RESULT_BACKEND: redis://ai-shifu-redis:6379/1
services:
  ai-shifu-api:
    container_name: ai-shifu-api
    # Use latest for development, check releases for specific versions
    # Available versions: https://hub.docker.com/u/aishifu or https://github.com/ai-shifu/ai-shifu/releases
    image: aishifu/ai-shifu-api:v2.1.0
    entrypoint: ["sh", "-c", "until timeout 1 bash -c 'cat < /dev/null > /dev/tcp/ai-shifu-mysql/3306'; do sleep 1; done && flask db upgrade && flask console update_demo_shifu && exec gunicorn -w 4 -b 0.0.0.0:5800 'app:app' --timeout 300 --log-level debug --access-logfile /var/log/app.log --capture-output"]
    env_file:
      - ./.env
    environment: *default-env
    volumes:
      - ./storage:/app/storage
    depends_on:
      - ai-shifu-mysql
      - ai-shifu-redis
  ai-shifu-celery-worker:
    container_name: ai-shifu-celery-worker
    image: aishifu/ai-shifu-api:v2.1.0
    entrypoint: ["sh", "-c", "until timeout 1 bash -c 'cat < /dev/null > /dev/tcp/ai-shifu-mysql/3306'; do sleep 1; done && until timeout 1 bash -c 'cat < /dev/null > /dev/tcp/ai-shifu-redis/6379'; do sleep 1; done && exec python -m celery -A celery_app:celery_app worker --loglevel info"]
    env_file:
      - ./.env
    environment: *default-env
    volumes:
      - ./storage:/app/storage
    depends_on:
      - ai-shifu-mysql
      - ai-shifu-redis
  ai-shifu-celery-beat:
    container_name: ai-shifu-celery-beat
    image: aishifu/ai-shifu-api:v2.1.0
    entrypoint: ["sh", "-c", "until timeout 1 bash -c 'cat < /dev/null > /dev/tcp/ai-shifu-mysql/3306'; do sleep 1; done && until timeout 1 bash -c 'cat < /dev/null > /dev/tcp/ai-shifu-redis/6379'; do sleep 1; done && exec python -m celery -A celery_app:celery_app beat --loglevel info"]
    env_file:
      - ./.env
    environment: *default-env
    volumes:
      - ./storage:/app/storage
    depends_on:
      - ai-shifu-mysql
      - ai-shifu-redis
  ai-shifu-cook-web:
    container_name: ai-shifu-cook-web
    image: aishifu/ai-shifu-cook-web:v2.1.0
    env_file:
      - ./.env
    environment:
      - I18N_ROOT=/app/i18n
    depends_on:
      - ai-shifu-api
  ai-shifu-nginx:
    container_name: ai-shifu-nginx
    image: nginx:latest
    ports:
      - "8080:8080"
    depends_on:
      - ai-shifu-api
      - ai-shifu-cook-web
    restart: always
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
  ai-shifu-mysql:
    container_name: ai-shifu-mysql
    environment:
      MYSQL_ROOT_PASSWORD: ai-shifu
      MYSQL_DATABASE: ai-shifu
    image: mysql:8.0
    volumes:
      - ./mysql_data:/var/lib/mysql
  ai-shifu-redis:
    container_name: ai-shifu-redis
    image: redis:7-alpine
    volumes:
      - ./redis_data:/data
