Core Features
Dependency Management
runnem allows you to define dependencies between services, ensuring they start in the correct order and only after their dependencies are ready.
Defining Dependencies
In your runnem.yaml
file, use the depends_on
field to specify service dependencies:
services:
database:
command: cd ~/projects/myproject/database && docker-compose up
url: postgresql://localhost:5432
api:
command: cd ~/projects/myproject/api && npm run dev
url: http://localhost:3000
depends_on: ["database"] # api depends on database
frontend:
command: cd ~/projects/myproject/frontend && npm run dev
url: http://localhost:3001
depends_on: ["api"] # frontend depends on api
How Dependencies Work
When you run runnem up
:
- runnem builds a dependency graph
- Services are started in topological order
- Each service waits for its dependencies to be ready
- A service is considered ready when:
- Its URL is accessible (if defined)
- Or after a brief startup delay (if no URL is defined)
URL-Based Health Checks
For services with defined URLs, runnem will:
- Wait for the URL to be accessible
- Retry up to 3 times with a 2-second delay
- Show status messages during the wait
Example with URL health checks:
services:
database:
command: cd ~/projects/myproject/database && docker-compose up
url: postgresql://localhost:5432/health # Given this health endpoint is setup in your compose file
api:
command: cd ~/projects/myproject/api && npm run dev
url: http://localhost:3000/docs # Can double as health check endpoint and handy to click on to open
depends_on: ["database"]
Circular Dependencies
runnem detects and prevents circular dependencies:
services:
service_a:
command: echo "Service A"
depends_on: ["service_b"] # Circular dependency!
service_b:
command: echo "Service B"
depends_on: ["service_a"] # Circular dependency!
If circular dependencies are detected, runnem will:
- Show an error message
- List the services in the cycle
- Prevent any services from starting
Best Practices
- Define URLs for services when possible
- Keep dependency chains short and simple
- Use health check endpoints for better reliability
- Avoid circular dependencies
- Test your dependency configuration with
runnem up