version: '3.0'

services:
  ctel:
    build:
      context: .
      args:
        - "UID=${UID:-1000}"
        - "GID=${GID:-1000}"
    command: sh -c "python manage.py collectstatic --no-input && 
                    python manage.py makemigrations &&
                    python manage.py compilemessages &&
                    gunicorn fwd.asgi:application -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000" # pre-makemigrations on prod
    ports:
      - "8003:8000"
    environment:
      - MEDIA_ROOT=${MEDIA_ROOT}
      - DB_ENGINE=${DB_ENGINE}
      - DB_SCHEMA=${DB_SCHEMA}
      - DB_USER=${DB_USER}
      - DB_PASSWORD=${DB_PASSWORD}
      - DB_HOST=${DB_HOST}
      - DB_PORT=${DB_PUBLIC_PORT}
      - DEBUG=${DEBUG}
      - CORS_ALLOWED_ORIGINS=${CORS_ALLOWED_ORIGINS}
      - BASE_URL=${BASE_URL}
      - CTEL_KEY=${CTEL_KEY}
      - ALLOWED_HOSTS=${ALLOWED_HOSTS}
      - BROKER_URL=${BROKER_URL}
      - BASE_UI_URL=${BASE_UI_URL}
      - AUTH_TOKEN_LIFE_TIME=${AUTH_TOKEN_LIFE_TIME}
      - IMAGE_TOKEN_LIFE_TIME=${IMAGE_TOKEN_LIFE_TIME}
      - INTERNAL_SDS_KEY=${INTERNAL_SDS_KEY}
      - FI_USER_NAME=${FI_USER_NAME}
      - FI_PASSWORD=${FI_PASSWORD}
    restart: always
    volumes:
      - type: bind
        source: ${HOST_MEDIA_FOLDER}
        target: ${MEDIA_ROOT}
  celery:
    build:
      context: .
      args:
        - "UID=${UID:-1000}"
        - "GID=${GID:-1000}"
    command: sh -c "celery -A fwd_api.celery_worker.worker worker -l INFO"
    environment:
      - MEDIA_ROOT=${MEDIA_ROOT}
      - PYTHONPATH=${PYTHONPATH}:/app  # For import module
      - PYTHONUNBUFFERED=1  # For show print log
      - DB_SCHEMA=${DB_SCHEMA}
      - DB_USER=${DB_USER}
      - DB_PASSWORD=${DB_PASSWORD}
      - DB_HOST=${DB_HOST}
      - DB_PORT=${DB_INTERNAL_PORT}
      - BROKER_URL=${BROKER_URL}
      - DB_ENGINE=${DB_ENGINE}
      - DEBUG=${DEBUG}
    network_mode: host
    restart: always
    volumes:
      - type: bind
        source: ${HOST_MEDIA_FOLDER}
        target: ${MEDIA_ROOT}
