Installation¶
This is the canonical setup guide for Squirrel Backend. Two paths are supported: a fully containerized stack via Docker Compose (recommended), and a hybrid setup that runs infrastructure in containers but the application processes locally.
Prerequisites¶
- Docker and Docker Compose
- (Local development only) Python 3.11+
Option 1: Docker Compose (Recommended)¶
1. Clone and configure¶
git clone https://github.com/slaclab/react-squirrel-backend.git
cd react-squirrel-backend
# Copy the example environment file and edit for your site
cp docker/.env.example docker/.env
docker/.env is gitignored. Edit it if you need to reach EPICS servers outside localhost — see Configuration.
Linux users
On Linux you can skip the EPICS DNS mappings and uncomment network_mode: host in docker/docker-compose.yml instead.
2. Start the stack¶
Migrations run automatically via the API container's entrypoint. The Compose project is named squirrel, so containers are named:
| Container | Port | Role |
|---|---|---|
squirrel-api |
8080 | REST + WebSocket API |
squirrel-db |
5432 | PostgreSQL |
squirrel-redis |
6379 | Cache, queue, pub/sub |
squirrel-monitor |
— | EPICS PV monitor (1 replica) |
squirrel-worker-1, squirrel-worker-2 |
— | Arq background workers |
3. Create an API key¶
All endpoints require authentication. Create your first key from inside the API container:
Save your token
The plaintext token (sq_…) is only shown once. Store it securely before continuing.
4. Access the services¶
- API: http://localhost:8080
- Swagger UI: http://localhost:8080/docs
- Health summary: http://localhost:8080/v1/health/summary
Option 2: Local Development¶
Run PostgreSQL and Redis in Docker; run the API, monitor, and worker on the host with hot-reload.
1. Start infrastructure¶
2. Set up the Python environment¶
cd ..
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e ".[dev]"
3. Run migrations¶
4. Start the application processes¶
Each in its own terminal:
All three are required
- API handles HTTP and WebSocket traffic.
- Monitor maintains the Redis cache of live PV values.
- Worker processes background jobs (snapshot create / restore).
For configuration, see Configuration. For native runs the SQUIRREL_* settings come from your shell environment — there is no top-level .env file in this repo.
Loading PVs from CSV¶
Expected CSV columns:
Setpoint,Readback,Region,Area,Subsystem
FBCK:LNG6:1:BC2ELTOL,,"Feedback-All","LIMITS","FBCK"
QUAD:LI21:201:BDES,QUAD:LI21:201:BACT,"Cu Linac","LI21","Magnet"
Upload through the UI:
- Open the "Browse PVs" page in the frontend.
- Click "Import PVs".
- Select the CSV.
Docker command reference¶
# Start all services (foreground)
cd docker
docker compose up
# Start detached
docker compose up -d
# Rebuild after code changes
docker compose up --build
# Tail logs
docker compose logs -f api
docker compose logs -f monitor
docker compose logs -f worker
# Stop everything
docker compose down
# Stop and wipe the database
docker compose down -v
# Scale workers
docker compose up -d --scale worker=4
# Shell into a container
docker exec -it squirrel-api bash
docker exec -it squirrel-db psql -U squirrel
docker exec -it squirrel-redis redis-cli
# Run a one-off migration
docker exec -it squirrel-api alembic upgrade head
Troubleshooting¶
Snapshots are empty¶
Expected when no PVs exist on your EPICS network. Make sure the network is reachable from Docker (or your local machine) and that PVs have been imported.
Workers not running¶
Snapshots will hang if no worker is consuming from the queue:
Port 8080 already in use¶
Edit docker/docker-compose.yml and remap the port:
…or override API_HOST_PORT in docker/.env.
Monitor not connecting¶
Check the monitor logs and Redis connectivity:
Next steps¶
- Configuration — environment variables and
docker/.env - API Keys — create, list, deactivate
- API Reference — REST and WebSocket endpoints
- Architecture — system design