version: '3.5'

services:
  cmdb-db:
    image: registry.cn-hangzhou.aliyuncs.com/veops/cmdb-db:3.0
    container_name: cmdb-db
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: '123456'
      MYSQL_DATABASE: 'cmdb'
      MYSQL_USER: 'cmdb'
      MYSQL_PASSWORD: '123456'
    volumes:
      - db-data:/var/lib/mysql
      - ./docs/mysqld.cnf:/etc/mysql/conf.d/mysqld.cnf
      - ./docs/cmdb.sql:/docker-entrypoint-initdb.d/cmdb.sql
    networks:
      new:
        aliases:
          - mysql
    ports:
      - '23306:3306'

  cmdb-cache:
    image: registry.cn-hangzhou.aliyuncs.com/veops/cmdb-cache:3.0
    container_name: cmdb-cache
    networks:
      new:
        aliases:
          - redis

  cmdb-api:
    image: registry.cn-hangzhou.aliyuncs.com/veops/cmdb-api:2.3.2
#    build:
#      context: .
#      target: cmdb-api
    container_name: cmdb-api
    environment:
      TZ: Asia/Shanghai
      WAIT_HOSTS: cmdb-db:3306, cmdb-cache:6379
    command:
      - /bin/sh
      - -c
      - |
        sed -i "s#USE_ACL = False#USE_ACL = True#g" settings.py
        /wait
        flask db-setup
        gunicorn --workers=3 autoapp:app -b 0.0.0.0:5000 -D
        flask cmdb-init-cache
        flask cmdb-init-acl
        nohup flask cmdb-counter > counter.log 2>&1 &

        celery -A celery_worker.celery worker -E -Q one_cmdb_async --concurrency=2 -D
        celery -A celery_worker.celery worker -E -Q acl_async --concurrency=2
    depends_on:
      - cmdb-db
      - cmdb-cache
    networks:
      new:
        aliases:
          - cmdb-api

  cmdb-ui:
    image: registry.cn-hangzhou.aliyuncs.com/veops/cmdb-ui:2.3.2
#    build:
#      context: .
#      target: cmdb-ui
    container_name: cmdb-ui
    depends_on:
      - cmdb-api
    environment:
      TZ: Asia/Shanghai
      CMDB_API_HOST: cmdb-api:5000
      NGINX_PORT: 80
    volumes:
      - ./docs/nginx.cmdb.conf.example:/etc/nginx/conf.d/nginx.cmdb.conf.example
    command:
      - /bin/sh
      - -c
      - |
        envsubst '$$CMDB_API_HOST  $$NGINX_PORT' < /etc/nginx/conf.d/nginx.cmdb.conf.example > /etc/nginx/conf.d/cmdb.conf
        nginx -g  'daemon off;'
    networks:
      - new
    ports:
      - "8000:80"

volumes:
  db-data:

networks:
  new:
