x-django: &django
  image: funkwhale-api
  volumes:
    - ../api:/app
    - ../.env:/app/.env
    - '${MUSIC_DIRECTORY_SERVE_PATH:-../.state/music}:/music:ro'
    - '../.state/plugins:/srv/funkwhale/plugins'
    - '../.state/staticfiles:/staticfiles'
    - '../.state/media:/protected/media'
    - '../.state/${COMPOSE_PROJECT_NAME:-funkwhale}/media:/data/media'
  depends_on:
    postgres:
      condition: service_healthy
    redis:
      condition: service_healthy
  networks:
    - internal

services:
  api:
    <<: *django
    build:
      context: ../api
      dockerfile: Dockerfile.debian
    healthcheck:
      test: ['CMD-SHELL', 'docker compose logs api | grep -q "Uvicorn running on" || exit 0']
      interval: 3s
      timeout: 5s
      retries: 3
    command: >
      sh -c "
        funkwhale-manage collectstatic --no-input &&
        uvicorn --reload config.asgi:application --host 0.0.0.0 --port 5000 --reload-dir config/ --reload-dir funkwhale_api/
      "

  celeryworker:
    <<: *django
    command: >
      sh -c '
        pip install watchdog[watchmedo] &&
        watchmedo auto-restart --patterns="*.py" --recursive -- celery -A funkwhale_api.taskapp worker -l debug -B --concurrency=${CELERYD_CONCURRENCY:-0}
      '
    depends_on:
      api:
        condition: service_healthy
