Skip to content

Dependencies

When one component’s image depends on another, you need to tell EMB so it builds them in the right order.

In a component’s Embfile, use the dependencies array:

Terminal window
cat worker/Embfile.yml
description: Background job worker
resources:
image:
type: docker/image
publish: true
dependencies:
- base:image
tasks:
test:
description: Run worker tests
script: npm test
scale:
description: Show scaling info
script: echo "Worker concurrency is controlled by WORKER_CONCURRENCY env var"
executors:
- local

The key part is:

resources:
image:
type: docker/image
dependencies:
- base:image # Build base:image first

This tells EMB: “Before building worker:image, make sure base:image is built.”

Dependencies use the format component:resource:

  • base:image - The image resource of the base component
  • api:image - The image resource of the api component

See all resources and their dependencies:

Terminal window
emb resources
ID NAME TYPE PUBLISHABLE REFERENCE
-------------------------------------------------------------------------------
api:image image docker/image ✓ microservices/api:latest
base:image image docker/image microservices/base:latest
gateway:image image docker/image ✓ microservices/gateway:latest
worker:image image docker/image ✓ microservices/worker:latest

The API also depends on base:

Terminal window
cat api/Embfile.yml
description: REST API service
resources:
image:
type: docker/image
publish: true
dependencies:
- base:image
tasks:
test:
description: Run API tests
pre:
- lint
script: npm test
lint:
description: Run linter
script: npm run lint

Both api and worker depend on base, meaning base must be built first.

Without explicit dependencies, EMB might try to build worker before base exists, causing the build to fail. Dependencies ensure:

  1. Correct build order - Parents built before children
  2. Parallel optimization - Independent components can build simultaneously
  3. Rebuild detection - If base changes, dependents are rebuilt

Continue to Build Ordering to see how EMB resolves the complete build graph.