Skip to Content
Alzo

Services

A service is a long-running thing. It may be a container or a host process; the graph does not distinguish them.

Every service and task declares exactly one execution strategy: run for a host process, or provision for an image or an adopted service. Missing both is an editor error as well as a load refusal.

const web = defineService({
  name: 'web',
  ports: {
    http: { ingress: local },
    health: { internal: true },
  },
  run: (self) => `pnpm dev --port ${self.port.http} --strictPort`,
  cwd: './apps/web',
  restart: { policy: 'always', delay: '2s', backoff: 'exponential', maxDelay: '30s' },
  dependsOn: [api.available],
  env: (self) => ({ PORT: self.port.http, API_URL: api.url.api }),
});

Ports

ports names what the service listens on, and each name becomes part of the service's addresses: web.url.http, web.address.http, self.port.http.

You do not write port numbers for a host process. It has no container to be inside, so there is no fixed number to declare — Alzo allocates one and you read it back through self. That is why run is a callback above: a Vite or Next dev server takes --port, and passing a PORT variable it does not read is the quiet way to end up with a server on the wrong port and a dashboard link that 404s.

A container is the opposite case: its port is fixed, because it is namespaced and cannot collide with anything. Alzo publishes it on an allocated host port.

ports: { pg: { port: 5432 } },     // container: 5432 inside, allocated outside
ports: { http: { ingress: local } }, // host process: allocated, name only

internal: true marks a port that receives no ingress hostname and no dashboard link, which is what you want for a health endpoint. Managed containers still publish it on 127.0.0.1, so you can still curl it and Alzo can still probe it. Host processes own their listener's bind address; this flag does not restrict it.

internal is a presentation and ingress choice, not network isolation. It also excludes the port from the automatic choice of a default readiness probe, so declare an explicit probe for a service whose ports are all internal when process startup is not sufficient readiness. alzo plan shows each service's readiness policy: automatic TCP on the selected port, an explicit probe, or process startup only. Dependencies and readiness covers probes, and Networking covers the addresses a port gets.

Restarts

restart exists because the alternative is what real configurations actually contain — while true; do …; sleep 2; done — and that does not survive contact with a process supervisor. Lifecycle explains delays, backoff and uptime.

Interactive processes

A host process that reads standard input declares interactive: true:

const api = defineService({
  name: 'api',
  ports: { http: {} },
  run: (self) => `pnpm dev --port ${self.port.http}`,
  cwd: './services/api',
  interactive: true,
});

In foreground alzo up, interactive: true makes api selectable for input: press i or Enter to attach, then Ctrl+z to return to Alzo. The handoff uses a real terminal, with resize and raw ANSI output, and applies only to supervised host processes.

Images

A monorepo image often needs files from more than one package. Name the extra build contexts rather than making context the repository root:

provision: {
  image: {
    context: './apps/api',
    contexts: { shared: './packages/shared' },
  },
},

The Dockerfile reads them with COPY --from=shared . /srv/shared, and the build stops shipping the whole tree.

A container's command is provision.args. One image serving several roles is the normal shape for anything with workers:

const scheduler = defineService({
  name: 'scheduler',
  provision: { image: 'apache/airflow:3.0', args: ['scheduler'] },
});

const worker = defineService({
  name: 'worker',
  provision: { image: 'apache/airflow:3.0', args: ['celery', 'worker'] },
});

Builds covers image platforms, build arguments and private dependencies.

Custom outputs

Keep application-specific values under node.outputs, separate from Alzo's own address members:

const db = defineService({
  name: 'db',
  ports: { pg: 5432 },
  env: { POSTGRES_DB: 'acme', POSTGRES_PASSWORD: 'dev' },
  provision: { image: 'postgres:17' },
  outputs: ({ hostname, port }) => ({
    connectionString: (u: { database: string }) => `postgres://postgres:dev@${hostname}:${port.pg}/${u.database}`,
  }),
});

const api = defineService({
  name: 'api',
  run: 'pnpm dev',
  dependsOn: [db.available],
  env: () => ({ DATABASE_URL: db.outputs.connectionString({ database: 'acme' }) }),
});

This database exposes db.outputs.connectionString({ database: 'acme' }), while db.url.pg keeps the ordinary per-port shape. Outputs are computed after allocation and resolve relative to their consumer, just like the built-in addresses. Read them inside a callback such as env: () => …, not at module scope.

Custom values are read only through db.outputs, never as members of db itself, so a custom key cannot replace one of Alzo's own members: an output named url is read as db.outputs.url, and db.url is still the per-port record. No output key is reserved: an output named available is db.outputs.available, and dependsOn: [db.available] still waits for the database.

Sidecars

Two containers that are one unit — a database proxy, an Envoy sidecar, a Tailscale front, a log shipper:

const proxy = defineService({
  name: 'proxy',
  ports: { pg: 5432 },
  provision: { image: 'gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.13' },
  ready: { tcp: { on: 'pg' } },
});

const app = defineService({
  name: 'app',
  provision: { image: 'acme/app' },
  attach: { to: proxy, pid: true },   // the network is always shared; `pid` is the opt-in
});

Note which one owns the namespace. If the application owned it and the proxy attached, the application would boot first and fail to connect until the proxy arrived — the sidecar startup race. Inverted, the ordering is correct by construction.

An attached node cannot declare ports or egress, because it has no network of its own — the namespace owner publishes ports and owns network policy for the group — and you cannot attach to an attachment, because namespaces form a star. ports and attachment chains are compile errors; an explicit egress is a load error, so conditionally built objects cannot slip past the rule. The namespace owner and every member must use the same start policy. Selecting, restarting or stopping any one of them acts on the whole group — even with --only — because a shared namespace is one lifecycle unit.

Alzo attaches to the exact container it started for the namespace owner, never to whatever currently has that name. Concurrent starts wait for the namespace owner, and replacing it recreates every attached member against the new container.

Compose spells this network_mode: "service:app", as a string. Here to is the binding itself.

On this page