# Deploy

How to deploy changes to the fal.ai ComfyUI server.

## Prerequisites

- You have the admin repo (`server/` folder)
- You have a fal.ai API key with deploy permissions
- Python 3.11 installed
- `fal` CLI authenticated: `fal auth login`

## Quick deploy

```bash
cd server
make deploy
```

This runs:
```
fal deploy server.py::Comfy --app-name comfy --auth private
```

## What gets deployed

When you run `make deploy`:
1. Your local `server/` folder is packaged
2. fal builds a Docker image with the Python env from `requirements.txt`
3. The image is cached (subsequent deploys are fast if `requirements.txt` hasn't changed)
4. A new "revision" of the app is registered

## Important — runners don't auto-update

**Running runners keep the OLD code** until they die or are killed.

To force the new code:
1. Go to https://fal.ai/dashboard/apps/<org>/<app>/runners
2. Terminate each active runner manually
3. Next user request starts a new runner with the new code

## Typical deploy flow

```bash
# 1. Edit server/comfy.py (add a model or a custom node)
nano server/comfy.py

# 2. Deploy
cd server
make deploy

# 3. Kill runners (so the change takes effect immediately)
# Open https://fal.ai/dashboard/apps/<org>/<app>/runners in the browser
# Click "Terminate" on each active runner

# 4. Test
# Relaunch the proxy locally: ./run.sh
# Run a workflow
# Watch the new runner's logs
```

## First-time setup

### 1. Clone the admin repo
```bash
git clone <private-repo>
cd <repo>/server
```

### 2. Install Python 3.11
```bash
# Mac
brew install python@3.11

# Windows
winget install Python.Python.3.11
```

### 3. Initialize
```bash
make init
```

This creates a local `.venv`, installs the `fal` CLI.

### 4. Login
```bash
.venv/bin/fal auth login
```

### 5. Deploy
```bash
make deploy
```

## Configuration files

All config lives in `server/` — you only edit 2 files:

- **`comfy.py`** — Models, custom nodes, ComfyUI commit hash, REPO_NAME
- **`requirements.txt`** — Python dependencies

## REPO_NAME — when to bump

The `REPO_NAME` in `comfy.py` defines where ComfyUI is cloned on fal's persistent storage:
```
/data/.fal/repos/<REPO_NAME>/
```

- **Don't bump** for adding models/nodes — just deploy and models get re-symlinked.
- **Bump** (e.g. `-1` → `-2`) when:
  - You changed `COMFY_COMMIT_HASH`
  - You want a fresh ComfyUI clone (e.g. to recover from a corrupted state)

## COMFY_COMMIT_HASH — which version

Currently pinned to `v0.19.0` (April 2026).

Newer versions may add LTX 2.3 support, bugfixes, new model formats.
Older versions may be more stable for specific workflows.

**Before changing**:
1. Check the v0.X.0 requirements.txt for new mandatory packages
2. Bump `REPO_NAME` so you get a fresh clone
3. Deploy and watch the runner logs for import errors
4. Some custom nodes may break on version changes — have their GitHub issues open

## Rollback

If a deploy breaks things:

```bash
fal apps revisions list --app-name comfy
fal apps deploy comfy <old-revision-id>
```

## Monitoring

- **Deploy status**: output of `make deploy`
- **Runner logs**: https://fal.ai/dashboard/apps/<org>/<app>/runners
- **App metrics**: https://fal.ai/dashboard/apps/<org>/<app>
- **Cost / usage**: https://fal.ai/dashboard/usage
