Skip to content

Template file

A template is a YAML file that tells localspace which services and resources make up a system. This page lists each field. To learn how to write a template, see the templates guide.

localspace reads the template in one of two modes. The mode decides the file name and where each service gets its code.

File Mode Location Source of the code
localspace.yaml Template mode In a template directory: <templates directory>/<name>/localspace.yaml. The name of the directory is the name of the template. Each service names a repo from repos.
.localspace.yaml Worktree mode At the root of a git repository. Each service runs from the worktree that holds the file.

The machine setting templates lists the directories that hold templates.

localspace reads the file in strict mode:

  • An unknown field is a problem.
  • A value of the incorrect type is a problem.
  • Each problem has the line and the column of the value.

lo template validate lists all problems. A template that has a problem does not start. See lo template validate.

Relative paths in the file, such as a seed file, start at the directory of the template. In worktree mode they start at the root of the repository. A path that starts with ~/ is in your home directory.

Field Type Default Meaning
defaults mapping none Values that apply to all services. See defaults.
repos mapping of name to repo none The git repositories of the template. Template mode only. See repos.
https boolean The machine setting proxy.https Set to true or false to select the scheme of the public URLs of the workspaces of this template.
domains list of strings none The domains of the host names of the services. See domains.
services mapping of name to service none The processes and containers of the system. See services.
resources mapping of name to resource none The stateful dependencies of the system. See resources.
external mapping of name to external part none The parts that the services use and that are external to the workspace, with no local service or resource. Each part is a remote or a list of sources. See external parts.

An empty file is a problem. A service, a resource and a part of external must not have the same name, because a reference to it is then ambiguous.

The key of a service or a resource becomes a host name and a container alias. The name of a remote must follow the same rules. It must have these properties:

  • It has lowercase letters, digits and dashes only.
  • It starts and ends with a letter or a digit.
  • It has 63 characters or fewer.
Field Type Default Meaning
defaults.ref string none The branch or ref that each repo uses when nothing else selects one. The ref of a repo replaces it for that repo.

lo new selects the ref of a repo in this order:

  1. A repo=ref or service=ref pair of lo new, or the one branch that --match finds.
  2. The ref of the repo in repos.
  3. defaults.ref.

When none of them gives a ref, the command fails with the code invalid. See errors.

repos maps the name of a repo to a local git checkout of that repo. A service names one of these repos in its repo field. A repo has two forms:

Form Meaning
A string The path of the checkout. It is the same as {path: <path>}.
A mapping The fields path and ref. Other keys are a problem.
Field Type Meaning
path string The path of the checkout. It starts with / or ~/. Necessary.
ref string The branch or ref that the repo uses when lo new selects none. It replaces defaults.ref for this repo.
defaults:
ref: develop
repos:
api: ~/code/api
frontend:
path: ~/code/frontend
ref: release/next

In this example, api uses develop and frontend uses release/next.

In worktree mode, repos must not be present. Each service runs from the worktree that holds .localspace.yaml.

domains lists the domains of the host names of the services, for example domains: [acme.com]. The names are only for this machine. Nothing changes in the public DNS.

Each entry is one or more DNS labels with dots between them. It has lowercase letters, digits and dashes only, and it has no dot at the end. It is not a public suffix, such as com or co.uk, from the public suffix list.

A template comes from a repository, so it cannot change the name resolution of your machine alone. lo new and lo up stop with the code conflict when a domain is not in the machine setting dns.domains. You add the domain with --yes, with lo proxy dns add, or in the dashboard. See a name in a domain that you select.

A service is one process or one container. The key in services is the name of the service.

A service runs in one of two ways:

  • A source service runs code from a repo, or from the worktree in worktree mode. It has no image field.
  • An image service runs a prebuilt container image. It has the image field.
Field Type Default Meaning
image string none A prebuilt container image, such as chrislusf/seaweedfs:4.55. The service always runs as a container.
repo string none The name of a repo in repos. Necessary for a source service in template mode. Invalid in worktree mode and with image.
dir string The root of the repo A directory in the repo that holds the code. It must stay in the repository. Invalid with image.
run container or process container if the source has a Dockerfile, if not process How the service runs. process runs on the host. container must have a Dockerfile in the source. process is invalid with image.
command string Found by discovery for a process The command that starts the service. See command and setup.
setup string none A command that runs before each start of the service. Invalid with image.
install string or false The install command that discovery finds The install step of a process. A string replaces the install step. false removes it. See command and setup. Invalid with image and with run: container.
port integer, 0 to 65535 0 (no port) The port on which the service listens. localspace also gives it to the service in the variable PORT.
expose boolean false Give the service a public URL. The service must have a port.
host string The machine pattern, such as <service>.<workspace>.lo The host name of the public URL of the service. It replaces {workspace} and {service}. It is in a domain of domains. See host.
aliases list of strings none Fixed host names that one workspace answers at a time, and that lo checkout points to a workspace. Must have expose: true. See aliases.
env mapping of string to string none The environment variables of the service. The values can have references.
ready string A connection to the port How localspace tells that the service is ready. See ready.
on_switch restart, rebuild or none restart The action that lo set takes to a running service when the code changes. Invalid with image.
rebuild_on list of strings none Paths that make lo set rebuild the service when they change. Invalid with image.
shareable boolean false Let workspaces share one instance of the service.
shared boolean false Share one instance by default. It implies shareable.
mounts mapping of resource name to path none Volumes to mount in the container. The service must run as a container. See mounts.
platform, entrypoint, args, working_dir, publish, volumes, cap_add, oneshot see container options none Options of a service that runs as a container, as a compose file writes them.
depends_on list of strings none The services and resources that the service must have to start. See dependencies.
attrs mapping of string to string none Extra attributes that references read from the service, with the values that the service has on your machine. See attrs.
remotes mapping of name to remote none Deployments of the service that run elsewhere. See remotes.
default string none The remote of remotes that a workspace uses when it selects nothing. It must not be used with shared: true.

For a process, localspace runs command with sh -c in the directory of the service. When command is empty, discovery reads the code and finds a command for a known framework. If discovery finds none, the start fails with the code invalid.

For a container, command replaces the command of the image. localspace runs sh -c <command>, so the image must have /bin/sh.

setup runs before each start. For a process, it runs on the host in the directory of the service. For a container, it runs one time in a container of the same image.

For a process, an install step runs before setup. By default, it is the install command that discovery finds, such as npm ci or composer install. install changes it:

Value Install step
Empty The install command that discovery finds.
A command The command, in place of the install command of discovery.
false No install step. setup does all the work.

Use a command when the install of discovery fails for the repo, for example npm install --legacy-peer-deps. Use false for a service in a monorepo that installs at the root in its setup. A container installs in its Dockerfile, so install is invalid with run: container. When discovery selects a container, install has no effect.

The install step, setup and command get the environment of the service. lo ls --json shows the full command that runs before each start, in the field setup of each service.

lo up and lo restart read run, command, install and setup from the template each time they start a service that does not run. If the template changes run, the service starts with the new run kind, and localspace removes the container or the process of the previous kind. A service that runs keeps its command and setup until it restarts. lo up shows a warning when the template is different from the values of the service.

The service reads its port from the variable PORT. The value is the port in the container for a container. It is the host port for a process.

ready has three forms:

Value How localspace tests the service
Empty It opens a connection to the host port of the service. The service is ready when it answers. A service without a port is ready when it starts.
A string that starts with / It sends an HTTP GET request to that path on the host port. The service is ready when the status code is lower than 400.
Any other string It runs the string as a shell command on the host, in the directory of the service and with the environment of the service. The service is ready when the exit code is 0.

localspace tests again each 250 milliseconds. The service fails when it is not ready after 120 seconds.

A reference such as ${orders.internal_url} can have two uses. A service can call orders to start, or it can only keep the address, for example for a webhook. depends_on tells localspace which services and resources a service must have.

services:
cms:
depends_on: [db]
env:
DATABASE_HOST: ${db.internal_host}
ORDERS_WEBHOOK_URL: ${orders.internal_url}/hook
orders:
depends_on: [db, cms]
env:
CMS_URL: ${cms.internal_url}/api

depends_on changes three things:

  • Start order. A service starts after the items in its depends_on. A service without depends_on starts after the services that it references. In the example, cms starts before orders, although cms references orders.
  • --service. lo up --service orders also starts the items in the depends_on of orders, and then their depends_on. It starts the resources that these services reference. A shared instance starts only if one of these services is in it, or if a selected service without depends_on references it.
  • Failures. If an item in the depends_on of a service fails to start, the service does not start. lo up records it as failed.

Each item is the name of a service or a resource of the template. An item that is not a service or a resource is a problem. A service that lists itself is a problem. A cycle is a problem, for example when cms lists orders and orders lists cms.

attrs adds attributes to a service, besides the built-in ones. A reference such as ${booking.api_key} reads one of them. The value is the one that the service has when it runs on your machine. It can have ${secret:...} and ${env:...}.

A name has letters, digits and _, and it does not start with a digit. It must not be the name of a built-in attribute. Each remote of the service must give each attribute of attrs. See remotes.

lo set moves a service to a different branch. It compares the changed files of the previous and the new source.

  1. If a changed path matches a rebuild_on entry, the service rebuilds. The image build does not use the cache.
  2. If not, the action in on_switch applies.

An entry of rebuild_on is a path pattern, such as package-lock.json or db/*.sql. An entry that ends with / matches each path in that directory. With on_switch: none, a running service does not change. See lo set.

host gives one exposed service a name that is not the machine pattern, for example front.{workspace}.acme.com. ${front.public_url} and the route of the proxy use this name. A service without host keeps the name of the machine settings.

{workspace} is the workspace name as it is in host names. {service} is the name of the service. The name must have these properties:

  • It is lowercase and it has valid DNS labels.
  • It is in one of the domains of the template.
  • It has 253 characters or fewer, also for a workspace name that has 63 characters.

With {workspace}, each workspace has a separate name, and the workspaces run side by side. Without {workspace}, such as front.acme.com, the name is the same for all workspaces. One workspace holds it at a time. lo up stops with the code conflict and names the workspace that holds it. Run lo down for that workspace, then run lo up again.

A service that you share between workspaces cannot have a host. A shared instance has one name for all the workspaces that use it.

aliases gives one exposed service fixed host names, for example sso.acme.com. An SSO provider can accept only one callback origin, but each workspace of the template has a separate URL. An alias is the same name for all workspaces, and one workspace answers it at a time.

lo checkout <workspace> points each alias of the template to the service of that workspace. The workspace that had the alias keeps running at its normal URL. When no workspace holds an alias, the proxy has no route for it. See fixed ports.

An alias has these properties:

  • It is one fixed name. It has no {workspace} and no {service}.
  • It is lowercase and it has valid DNS labels.
  • It is in one of the domains of the template, so that the DNS server of localspace answers it.
  • It is not the same as an alias or the host of a different service.

Aliases are for the proxy in domain mode. In IP mode, lo checkout does not move them.

The key is the name of a resource of the kind volume. The value is an absolute path in the container. A key that is not a volume resource is a problem. A relative path is a problem. mounts is invalid when run is process.

A service that runs as a container, with image or with run: container, can have the options of this table. Each option is a problem on a service that does not set image or run: container.

Field Type Meaning
platform linux/amd64 or linux/arm64 The platform of the image, for an image that is made for one architecture. A build from a Dockerfile uses it too.
entrypoint string or list of strings It replaces the entrypoint of the image. The first word is the program. The other words come before args. It is a problem with command.
args list of strings They replace the CMD of the image. It is a problem with command.
working_dir string The working directory in the container. It must be an absolute path.
publish list of integers More container ports. localspace publishes each port on a host port that it selects. A reference reads it as ${<service>.ports.<port>}.
volumes list of volumes Host paths and named volumes to mount, besides the volume resources of mounts. See the next table.
cap_add list of strings Linux capabilities for the container: IPC_LOCK, NET_ADMIN, NET_BIND_SERVICE, NET_RAW, SYS_NICE, SYS_PTRACE, SYS_RESOURCE or SYS_TIME.
oneshot boolean A job that runs to completion, such as a migration. See oneshot.

An item of volumes has these fields:

Field Meaning
source A host path to mount. A relative path starts at the template directory, or at the worktree in worktree mode.
volume The name of a named volume of yours. localspace does not make it with a label, and lo rm does not remove it. Use source or volume, not the two.
target The path in the container. It must be an absolute path. Necessary.
read_only If true, the container cannot write to it.
services:
worker:
image: acme/worker:3
platform: linux/amd64
entrypoint: [/bin/tini, --]
args: [worker, --queue, default]
working_dir: /app
publish: [9090]
cap_add: [SYS_PTRACE]
volumes:
- { source: ./config, target: /app/config, read_only: true }
- { volume: worker-cache, target: /cache }

A service with oneshot: true runs one time at each start and then stops. It is done if it stops with the exit code 0, and failed if not. A service that has it in depends_on starts after it is done. That service does not start if the oneshot fails. lo logs shows the output of the last run.

A oneshot has no port, no expose and no ready. Each of them is a problem.

services:
migrate:
image: acme/api:latest
oneshot: true
args: [npm, run, migrate]
depends_on: [db]
env:
DATABASE_URL: ${db.url}
api:
image: acme/api:latest
port: 8080
depends_on: [migrate]
  • A source service in template mode must have a repo, and the repo must be in repos.
  • expose: true is invalid without a port.
  • host is invalid without expose: true. It is valid for an image service that has expose: true.
  • host must be a valid host name, in lowercase, in one of the domains. It must have only the replacements {workspace} and {service}.
  • Two services must not have the same name in host.
  • aliases is invalid without expose: true. An alias must be a valid host name, in lowercase, with no replacements, in one of the domains. It must not be the same as an alias of a different service or a host.
  • A reference in env must name a service or a resource of the template. The attribute must be one that the service or the resource has. See references.
  • An item in depends_on must name a service or a resource of the template, and depends_on must not make a cycle.
  • install is invalid with image and with run: container.
  • A container option is invalid on a service that does not set image or run: container. entrypoint and args are invalid with command. A working_dir or a volume target that is not an absolute path is a problem. A port of publish must not be the port of the service, and must not be in the list two times.

A resource is a stateful dependency, such as a database. localspace makes it for each workspace. The key in resources is the name of the resource.

Field Type Default Meaning
kind string none The kind of resource: postgres, mongo, redis, s3 or volume. A plugin can add more kinds. Necessary.
version integer 16 for postgres, 8 for mongo, 7 for redis The major version of the server image. s3 and volume do not use it.
seed string or mapping none The data to load when the resource is new. See seed.
readonly_role boolean false Make a read-only role in the database. It gives the attribute readonly_url. Only for postgres.
image string The official image of the kind An image to run in place of the official image, for example pgvector/pgvector:pg16. The resource then runs in a separate instance. Invalid for a volume.
remotes mapping of name to remote none Deployments of the resource that run elsewhere. See remotes. A volume has none.
default string none The remote of remotes that a workspace uses when it selects nothing.

An unknown kind is a problem. The message lists the kinds that are installed.

Kind Isolation Seed file Attributes for references
postgres instance, database .sql or .sql.gz dump url, readonly_url, host, port, name
mongo instance, database none url, host, port, name
redis instance, database none url
s3 instance, database none url, host, port, bucket, region, access_key, secret_key
volume instance .tar.gz or .tgz archive name

The isolation is a choice of the machine. See the setting resources. The resources guide tells how isolation works.

A seed is a file, a command, or the two together. When the two are present, the file loads first.

Form Meaning
A string The path of a seed file. It is the same as seed: {file: <path>}.
A mapping The fields file, run and service. Other keys are a problem.
Field Type Meaning
file string The path of a file that the resource loads. The file must be present.
run string A command that fills the resource. It runs in the directory or the container of service, with the environment of that service, after its setup.
service string The service that runs run. It must reference the resource in its env or in its mounts.

run and service go together. A service without run is a problem. A run without service is a problem. redis, mongo and s3 take no seed file, so seed them with run.

A seed command runs one time for each new resource. It runs again after lo db reset.

A remote is a deployment of a service or a resource that runs elsewhere. localspace does not start, stop or remove it. Each workspace selects if a service or a resource runs on your machine or on one of its remotes. See use services that run elsewhere.

A remote is a mapping with these fields:

Field Type Default Meaning
url string none Where the remote answers. It has a scheme, such as https://host. It can have ${secret:...} and ${env:...}. Necessary.
ready string none A path such as /health, or a shell command. See ready.
attrs mapping of string to string none The attributes that references read from the remote, besides those that its URL gives. The values can be secrets.

A service or a resource lists its remotes in remotes. The top-level external lists the parts that the services use, that are external to the workspace and that have no local service or resource. A part of external is one remote, as in the example below. It can also have a list of sources, which can be a service of a different workspace. See external parts. A reference reads a part with its name, for example ${stripe.key}.

services:
booking:
port: 8080
attrs: { api_key: dev-key }
remotes:
staging:
url: https://booking.staging.acme.com
ready: /health
attrs: { api_key: "${secret:booking/staging_key}" }
default: staging
resources:
booking-db:
kind: postgres
remotes:
staging:
url: ${secret:booking-db/staging_url}
external:
stripe:
url: https://api.stripe.com
attrs: { key: "${secret:stripe/test_key}" }

ready has two forms. A string that starts with / is a path. localspace sends an HTTP GET request to the URL with that path, and the remote answers when the status code is lower than 400. Any other string is a shell command on the host. The remote answers when the exit code is 0.

With ready, the status of the remote is reachable or unreachable. localspace checks at lo up and when a command or a page reads the workspace. Without ready, the status is remote. A service that lists a remote in depends_on waits up to 15 seconds for the check, and does not start when it fails.

  • A remote without url is a problem. A url without a scheme is a problem.
  • A remote of a service must give each attribute in the attrs of the service.
  • A remote of a resource must give each attribute that an env reads from the resource. Its URL gives url, host, port and name.
  • default must name a remote of the same service or resource. It must not be used with shared: true.
  • A part of external must not have the name of a service or a resource.
  • The name of a remote must have lowercase letters, digits and dashes only.
  • A value in url or attrs can use ${secret:...} and ${env:...}. Other references are a problem.
  • A reference to an attribute that the service and its remotes do not give is a problem.

An external part is a part that the services use and that is external to the workspace. It has no service and no resource in the template. A reference reads it with its name, as for a service. See connect workspaces of different templates.

A part has one of two forms:

  • A remote. Give url, and ready and attrs if necessary. See remotes.
  • A list of sources in from. localspace tries the sources in order, and the first source that is available wins. A source is a service of a different workspace on this machine, or a remote.
external:
stripe:
url: https://api.stripe.com
api:
from:
- workspace: { template: backend, ref: same }
- workspace: { template: backend, ref: main }
- { name: staging, url: "https://api.staging.acme.com", ready: /health }
service: api
start: true
attrs: { api_key: dev-key }
Field Type Default Meaning
url string none The URL of a part that is one remote. Do not use it with from. Put the URL on a source of from.
ready string none The check of a part that is one remote. Do not use it with from.
from list of sources none The sources, in the order to try. See sources.
service string none The service that a workspace source reaches. Necessary when from has a workspace source. It is a problem without one.
start boolean false If true, lo up starts the service of a workspace source that is stopped. The workspace source is then available. It is a problem without from.
create boolean false If true, lo up makes the workspace of a workspace source that localspace does not find, from its template on its ref, and starts it.
attrs mapping of string to string none The attributes that references read from the part. All the sources get them. An attrs of a source replaces the value of the same name.

A source is a mapping. It has a workspace field or a url field. It does not have the two.

A workspace source finds a workspace by its template and its ref, and not by its name. The ref is the ref of the repository that the service runs from. The field workspace is a mapping with these fields:

Field Type Default Meaning
template string none The name of the template of the workspace. In worktree mode, the name of the template is the name of the directory of the repository. Necessary.
ref string none same, or a branch such as main. Necessary. same is the branch that the workspace of the consumer runs.
repo string none The repository of the consumer. ref: same reads the branch of this repository. Use it in template mode when the template has more than one repository.

These rules apply:

  • A workspace source does not match the workspace of the consumer.
  • If more than one workspace matches, the part is unresolved. The message tells you to select one with workspace:<name>.
  • A workspace source is available when its service runs. It is also available when the part has start: true.
  • With create: true, the first workspace source that finds no workspace makes one. localspace does not try the next sources. The workspace has the name of the ref, or <template>--<ref> when a workspace has that name.
  • repo is a problem with a ref other than same. repo is also a problem in worktree mode, where ref: same reads the branch of the worktree.

A remote source is a remote of the part. It has these fields:

Field Type Default Meaning
url string none Where the remote answers. Necessary. It can have ${secret:...} and ${env:...}.
name string none The name that a workspace uses in the choice remote:<name>. Give it to a source that a workspace must be able to select by name.
ready string none A path such as /health, or a shell command. See ready.
attrs mapping of string to string none The attributes of this source. They replace the attrs of the part.

A remote source is available when it has no ready, or when its ready check answers.

A reference to a part that resolved to a workspace source reads the service of that workspace. See references. A reference to a remote source reads the remote, as in remote attributes.

The from list gives the default order. Each workspace can select a different source with lo new, lo set or the MCP tools:

Choice Meaning
api=workspace:<ws> The service of the workspace <ws>. The template and the ref of that workspace do not matter.
api=remote:<name> The remote source with that name.
api=<url> A URL that you enter. The template does not list it.
api=auto The order of from again.

--attr api.<name>=<value> gives an attribute to the choice of one workspace. It wins over all the attrs of the template. --attr refuses a built-in attribute such as url, host or port. Set api=<url> in its place.

  • A part must not have the name of a service or a resource.
  • A part with from must not have url or ready at its top level. Put them on a source.
  • A source with workspace must not have url, ready, name or attrs.
  • A workspace source must have template and ref.
  • ref: same in a template with more than one repository must have repo. repo must name a repository of the template.
  • Two remote sources of a part must not have the same name.
  • A part with a workspace source must have service.
  • A part without a workspace source must not have service, start or create.
  • A reference to an attribute that a part with only remote sources does not give is a problem. Each source must give the attribute in its attrs, or the part must give it.
  • The rules for a remote also apply to each remote source. See problems in a remote.

At lo up, a part can be unresolved. This is not a problem of the file. It is the state of the workspace. The part has the status unresolved and a message. For example: no source of api is available: no workspace of backend on feature-1234; no workspace of backend on main. A service that reads an unresolved part does not start.

localspace.yaml
defaults:
ref: develop
repos:
booking-service: ~/code/booking-service
customer-service:
path: ~/code/customer-service
ref: main
frontend: ~/code/frontend
https: true
services:
booking:
repo: booking-service
run: container
port: 8080
expose: true
ready: /health
env:
DATABASE_URL: ${booking-db.url}
CUSTOMER_URL: ${customer.internal_url}
APP_KEY: ${secret:booking/app_key}
rebuild_on:
- Dockerfile
- go.sum
customer:
repo: customer-service
dir: server
port: 8080
shareable: true
install: npm install --legacy-peer-deps
setup: npm run migrate
command: npm start
env:
DATABASE_URL: ${customer-db.url}
frontend:
repo: frontend
port: 3000
expose: true
depends_on: [booking]
env:
VITE_BOOKING_URL: ${booking.public_url}
storage:
image: chrislusf/seaweedfs:4.55
port: 8333
resources:
booking-db:
kind: postgres
version: 16
seed: seeds/booking.sql.gz
readonly_role: true
customer-db:
kind: postgres
seed:
run: npm run seed
service: customer

A repository in worktree mode has a shorter file. Each service has no repo, and the file has no repos:

.localspace.yaml
services:
web:
port: 3000
expose: true
command: npm run dev -- --port $PORT
env:
DATABASE_URL: ${db.url}
resources:
db:
kind: postgres