Run the engine
Run Postgres and RabbitMQ in Docker. Run the API, worker, and scheduler on the host with Bun so they reload when you edit source. caps-engine is Bun. Do not use npm, pnpm, or Node for this repository.
Before you start
Section titled “Before you start”- Bun 1.x
- Docker 24 or newer, and Compose v2
- A clone of the engine:
git clone https://github.com/hisptz/caps-engine.gitcd caps-engineflowchart LR
subgraph docker [Docker]
pg[(Postgres :5432)]
mq[[RabbitMQ :5672]]
end
subgraph host [Host, bun --watch]
api[dev:api :4000]
worker[dev:worker]
scheduler[dev:scheduler x1]
end
api --> pg
api --> mq
worker --> pg
worker --> mq
scheduler --> pg
localhost in .env is correct for these host processes. It is wrong for the same variables inside a container. That case is the Deployment Guide.
The repository Compose file expects an external network named chap, even when you are not attaching to CHAP. Create it once:
docker network create chapmake up compiles distroless images and starts api, worker-1, worker-2, and scheduler as well as Postgres, RabbitMQ, and migrate. Those containers collide with the host processes, and a second scheduler double-fires pipelines. Start only the data stores and the one-shot migration:
docker compose up -d postgres rabbitmq migrateIf a previous make up left the app containers running, stop them:
docker compose stop api worker-1 worker-2 schedulerCopy .env.example to .env. For host processes the database and broker hosts are localhost. CHAP_BASE_URL is required. The API process does not listen without it, and it exits if the AMQP connection fails. admin / district is the demo DHIS2 pair for this local file only.
DATABASE_URL=postgresql://caps:replace-me@localhost:5432/capsRABBITMQ_URL=amqp://caps:replace-me@localhost:5672CHAP_BASE_URL=http://localhost:8000CLIMATE_API_BASE_URL=http://localhost:8001CLIMATE_DATA_BASE_URL=http://localhost:8081DHIS2_BASE_URL=http://localhost:8080DHIS2_USERNAME=adminDHIS2_PASSWORD=districtMatch replace-me to POSTGRES_PASSWORD and RABBITMQ_PASSWORD. The example file uses caps for both.
In three terminals:
bun installbun run db:generatebun run dev:apibun run dev:workerbun run dev:schedulerHow the source is arranged is Source architecture. Tests are Engine tests.
The API log says Server running on http://localhost:4000. This request needs no authentication header:
curl -fsS http://localhost:4000/system/infoA 200 means the API process answered.
If this fails
Section titled “If this fails”CHAP_BASE_URL missing, or RabbitMQ still starting, exits the API before it listens. docker network create chap is required by the repository Compose file. If port 4000 is already taken, a Compose api container is still running.