# ACE-Step 1.5 — open-source music generation foundation model
# (April 2026). Hybrid diffusion + LLM architecture, Apache 2.0.
# ~50-80 s for a 4-minute song on A6000; under 4 GB VRAM at idle,
# ~10-12 GB during inference. Beats YuE / DiffRhythm on the
# speed/coherence trade.
#
# We launch upstream's REST API (`infer-api.py`) instead of the
# default `gui.py` (Gradio). The REST surface is what we'll point
# clients + automation at; Gradio is dev-time eye candy.
#
# Image is built locally from upstream's repo via docker buildx git
# context, same pattern as fish-s2.
#
# All tunables live in .env — edit that, not this file.

services:
  ace-step:
    image: local/ace-step:${ACE_STEP_TAG}
    build:
      # Build from local Dockerfile (not upstream's git context) — we
      # ship a patched Dockerfile that fixes upstream's torch/cu126
      # resolution bug. Playbook uploads Dockerfile alongside this
      # compose.yaml.
      context: .
      dockerfile: Dockerfile
      args:
        ACE_STEP_REF: ${ACE_STEP_SHA}
    container_name: ace-step
    restart: unless-stopped
    runtime: nvidia
    ports:
      # Container default for infer-api.py is 8000 (hardcoded
      # uvicorn.run(host=0.0.0.0, port=8000) — no flags). Map host
      # ACE_STEP_PORT to it.
      - "${ACE_STEP_BIND:-0.0.0.0}:${ACE_STEP_PORT}:8000"
    environment:
      - NVIDIA_VISIBLE_DEVICES=${ACE_STEP_GPU_DEVICES:-1}
      # ACE_OUTPUT_DIR is read by acestep at generation time — keep
      # in sync with the bind mount below.
      - ACE_OUTPUT_DIR=/app/outputs
      # HF_HOME points the HuggingFace cache at the bind mount so the
      # ~5-10 GB checkpoint download survives container recreates.
      - HF_HOME=/app/hf_cache
    volumes:
      # ACE-Step has a HARDCODED checkpoint cache at
      # /root/.cache/ace-step/checkpoints — not honored by HF_HOME.
      # Mount our persistent dir there so model re-pull doesn't
      # happen on every container recreate.
      - ${ACE_STEP_CHECKPOINTS_DIR}:/root/.cache/ace-step/checkpoints
      - ${ACE_STEP_OUTPUTS_DIR}:/app/outputs
      - ${ACE_STEP_LOGS_DIR}:/app/logs
      - ${ACE_STEP_CACHE_DIR}:/app/hf_cache
    # Override upstream's default `python3 acestep/gui.py` with the
    # REST API entry point. infer-api.py self-binds 0.0.0.0:8000 and
    # exposes POST /generate + GET /health.
    command: ["python3", "infer-api.py"]
    healthcheck:
      # /health is the cheapest signal infer-api.py exposes — returns
      # 200 as soon as the FastAPI app is up. The pipeline lazy-loads
      # on first /generate, so /health says "process alive" not
      # "model warm". Good enough for a liveness signal; first
      # /generate has the ~30-60 s warmup baked in.
      test: ["CMD-SHELL", "python3 -c \"import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=5).status==200 else 1)\""]
      interval: 30s
      timeout: 10s
      retries: 3
      # First boot pulls ACE-Step checkpoint (~5-10 GB) into HF cache.
      start_period: 600s
    labels:
      - homepage.group=AI Systems
      - homepage.name=ACE-Step
      - homepage.icon=mdi-music-note-eighth
      - homepage.description=Open-source music generation — 4-min song in ~60s, lyrics + style prompts (irv-ml1)
      - homepage.href=http://10.100.79.3:${ACE_STEP_PORT}
