References
A reference is a placeholder in the form ${...}. localspace replaces it with a value when it builds the environment of a service. The value is different for each workspace and for each consumer. To learn how to use references, see the templates guide.
Where references work
Section titled “Where references work”References work in the values of env in a service. They also work in the values of the --env service.KEY=value flags of lo new and lo up. They do not work in other fields, such as command, setup, ready or seed. A shell expands the variables in those commands, and the commands get the resolved env.
localspace builds the environment from three layers. Each layer replaces the value of the same key in the layers before it:
- The
envof the service in the template. - The overrides of the workspace, from
lo new --env. - The flags of this run, from
lo up --env.
Syntax
Section titled “Syntax”A reference starts with ${ and ends with the first }. A value can have more than one reference, with other text around them. A $ that does not come before { is plain text.
There is no escape for ${. A ${ without a } is an error.
| Reference | Value |
|---|---|
${<service>.<attribute>} |
An attribute of a service. See service attributes. |
${<resource>.<attribute>} |
An attribute of a resource. See resource attributes. |
${<remote>.<attribute>} |
An attribute of an external part of the template. See remote attributes and linked parts. |
${workspace.name} |
The name of the workspace. |
${workspace.slug} |
The slug of the workspace: the name in lowercase, with . and _ changed to -. It is the form that host names and file names use. |
${secret:<path>} |
A secret from the secret store. See secrets. |
${env:<NAME>} |
The value of the variable NAME in the environment of lo. |
${env:<NAME>} fails with the code invalid when lo does not have the variable. A name that is not a service and not a resource is also invalid. A reference such as ${booking} with no attribute is a problem too.
lo template validate checks each reference in the file. It reports an unknown name, an unknown attribute and an attribute that the service or resource and its remotes cannot give. See lo template validate.
Service attributes
Section titled “Service attributes”| Attribute | Value | Condition |
|---|---|---|
internal_url |
http://<host>:<port>: the address with which a consumer reaches the service. |
The service has a port. |
internal_host |
The host part of internal_url. |
The service has a port. |
port |
The port part of internal_url. |
The service has a port. |
public_url |
The URL that a browser uses to reach the service. | The service has expose: true. |
public_port |
The port in public_url. |
The service has expose: true. |
websocket_url |
public_url with the scheme wss for https and ws for http. A browser opens a WebSocket with it. |
The service has expose: true. |
internal_websocket_url |
internal_url with the scheme ws. |
The service has a port. |
ports.<port> |
The port with which a consumer reaches the container port <port>: the host port for a process, <port> for a container on the same network. |
The service lists <port> in publish. |
Use the internal attributes when one service calls a different service. Use public_url for a value that a browser reads, such as the setting of a frontend that calls an API from the page.
Public URL
Section titled “Public URL”The public URL is the same for all consumers. Its form changes with the machine setting proxy.address:
| Mode | Form | Example |
|---|---|---|
domain |
The scheme, the host name that the proxy serves, and the proxy port. The setting proxy.host gives the order of the service and the workspace. The setting proxy.domain gives the suffix. |
https://booking.shop-a.lo |
ip |
http://<ip>:<host port of the service>. The setting proxy.ip gives the IP address. |
http://127.0.0.1:20004 |
The scheme is https unless the setting proxy.https or the field https of the template says false. The public_port is the port of the proxy in domain mode. It is the host port of the service in ip mode. See public URLs.
Internal addresses
Section titled “Internal addresses”The host and the port of an internal address change with the way the consumer runs and the way the target runs. The consumer is the service that has the reference in its env.
| Consumer | Target | Host | Port |
|---|---|---|---|
| Process | A service or a resource in a container, or a process | 127.0.0.1, or ::1 if the target answered on that address |
The host port of the target |
| Container | A service or a resource in a container | The name of the service or the resource, on the network of the workspace | The port of the target in its container |
| Container | A service that runs as a process | The host alias of the engine, host.docker.internal for Docker |
The host port of the target |
The port in a container is the port of the service. For a resource it is the default port of the kind: 5432 for postgres, 27017 for mongo, 6379 for redis and 8333 for s3.
A resource with database isolation lives on a shared server. The address is the address of that server:
- A process reaches the server on its host port.
- A container reaches a server that localspace runs by the name of the server and its port.
- A container reaches the server of the machine setting
resources.<kind>.serverat the host of that server. If the host islocalhost,127.0.0.1or::1, the host alias of the engine replaces it.
Resource attributes
Section titled “Resource attributes”A resource gives the attributes of its kind. A reference to an attribute that the kind does not have is a problem.
| Kind | Attribute | Value |
|---|---|---|
postgres |
url |
postgres://postgres@<host>:<port>/<name>?sslmode=disable. The user is postgres. There is no password. |
postgres |
readonly_url |
The same form, with the read-only role as the user. The resource must have readonly_role: true. |
postgres |
host |
The host of the address. |
postgres |
port |
The port of the address. |
postgres |
name |
The name of the database. |
mongo |
url |
mongodb://<host>:<port>/<name> |
mongo |
host, port |
The host and the port of the address. |
mongo |
name |
The name of the database. |
redis |
url |
redis://<host>:<port>/<db>. <db> is 0 for an instance. For database isolation it is the number of the database of the workspace. |
s3 |
url |
http://<host>:<port>, the endpoint of the S3 gateway. |
s3 |
host, port |
The host and the port of the address. |
s3 |
bucket |
The name of the bucket. |
s3 |
region |
The region, us-east-1. |
s3 |
access_key, secret_key |
The credentials of the server. |
volume |
name |
The name of the container volume. |
With database isolation, the name of a database or a bucket is different for each workspace, so workspaces do not share data. A plugin can add more kinds. The Attributes of the plugin give the attributes of such a kind. See write a plugin.
Remote attributes
Section titled “Remote attributes”A service or a resource can run on a remote in a workspace. The reference does not change. It reads the remote in place of the local unit. See use services that run elsewhere.
| Attribute | Value on a remote |
|---|---|
url, internal_url, public_url |
The URL of the remote. A service has these attributes. A resource has url. |
host, internal_host |
The host name of the URL. A resource has host. |
port, public_port |
The port of the URL, or the port of its scheme. A resource has port. |
websocket_url, internal_websocket_url |
The URL of the remote with the scheme wss or ws, if its scheme is https or http. Only a service has them. |
name |
The path of the URL without /. Only a resource has name. |
An attribute in attrs |
The value of the remote, or the value that the workspace gives with --attr. |
A value in attrs takes the place of an attribute that the URL gives. A container and a process get the same value, because a remote is not on the network of the workspace.
A part of external that is one remote, or that resolved to a remote source, gives the same attributes. For example, ${stripe.key} reads the attribute key of external.stripe.
A variable that gets a secret from a remote is secret, and lo env shows ******** for it.
Linked parts
Section titled “Linked parts”A part of external can resolve to a service of a different workspace on this machine. The reference does not change. It reads that service. See connect workspaces of different templates.
The consumer reaches the linked service through the host. The linked service can run as a process or as a container in its workspace. The consumer always uses its host port.
| Attribute | Value |
|---|---|
internal_url, url |
http://<host>:<host port> of the linked service. |
internal_host, host |
127.0.0.1 for a consumer that is a process. The host alias of the engine for a consumer that is a container. |
port |
The host port of the linked service. |
public_url |
The public URL of the linked service in the workspace of that service. It works when that service has expose: true. |
public_port |
The port in that public URL. |
websocket_url, internal_websocket_url |
public_url and internal_url with the scheme wss or ws. |
An attribute in attrs |
The value in the attrs of the linked service. If the service has no such value, the attrs of the part. |
--attr <part>.<name>=<value> replaces the value of an attribute for one workspace.
If the part is unresolved, or the linked workspace has not started the service, a reference to the part fails with the reason. The service of the consumer does not start.
Secrets
Section titled “Secrets”${secret:<path>} reads a secret from the secret store that the machine setting secrets selects. The built-in store is file. The path is relative, such as strapi/app_keys.
Set a secret with lo secret set <path>. The command reads the value from the standard input. An empty path is a problem. A secret that is not set fails with the code not_found. See secrets.
A variable that has a secret in its value is secret. lo env shows ******** for it. lo env --reveal shows the value.