velyr.toml Experimental
Every key of the velyr-pack manifest, its default, its format and how it is validated.
velyr.toml lives at the root of your app, next to composer.json. It is TOML with two
tables:
processes: what the app can run. A velyr builder turns each one into an image process.envs: one entry per Swarm stack file, listing the services that run those processes.
Unknown keys are an error (velyr.toml: unknown key processes.web.helth), so a typo fails instead of being
silently ignored. See Concepts for how the pieces relate.
[processes.<name>]#
[processes.web]
command = ["php", "artisan", "octane:start", "--server=frankenphp", "--host=0.0.0.0", "--port=8000"]
grace = "30s"
health = { path = "/up", port = 8000, start_period = "120s" }| Key | Type | Required | Default | Meaning |
|---|---|---|---|---|
command | array of strings | yes | The command, run without a shell. Services append their args to it. | |
grace | duration | no | web: 45s, worker: Swarm's default (10s) | stop_grace_period of every service running this process. |
health | table | no | Makes it a web process: HTTP healthcheck and start-first rollout. | |
health.path | string | with health | Path probed with curl -fsS http://localhost:<port><path>. | |
health.port | integer | with health | Port the process listens on inside the container. | |
health.start_period | duration | no | 60s | Healthcheck start period, and the window after an update in which a failure rolls back. |
- The name must match
^[a-z0-9][a-z0-9-]*$: lowercase letters, digits and hyphens, not starting with a hyphen. - Durations use Go syntax:
45s,2m,1m30s,500ms."1 min"is an error. - If exactly one process has
health, it is the image's default process. - The command runs as is. To use shell features (
&&, variables), wrap it:["sh", "-c", "..."], or call a script:["sh", "docker/boot.sh", "php", "artisan", "octane:start"].
[envs.<name>]#
[envs.production]
file = "stack.yml"
image = "cnb"
service_extends = ["*app"]
deploy_extends = ["*restart", "*placement"]
replicas = 1
cpus = "0.5"
memory = "512M"
orbital_prefix = "shop_"
services = [
{ name = "web", process = "web", replicas = 2, cpus = "2", memory = "1G" },
]| Key | Type | Required | Default | Meaning |
|---|---|---|---|---|
file | string | yes | Stack file, relative to velyr.toml. It must contain the markers (see below). | |
image | "cnb" or "dockerfile" | no | "dockerfile" | How services run their process; see image modes. |
service_extends | array of YAML aliases | no | none | Merged into every service: <<: *app. |
deploy_extends | array of YAML aliases | no | none | Merged into every service's deploy:: restart policy, placement. |
replicas | integer | no | 1 | Replicas of a service that does not set its own. |
cpus | string | here or on every service | CPU limit: a number, like "0.5" or "2". | |
memory | string | here or on every service | Memory limit: digits with an optional K, M or G, like 512M or 1G. | |
orbital_prefix | string | no | "" | Prepended to service names by velyr-pack orbital, usually the stack name and _. |
services | array of tables | no | [] | The services, written in this order. |
The environment name is free-form (production, hmg-one); it is what you pass to velyr-pack compose.
Aliases must look like *name (letters, digits, _ and -). velyr-pack only references them: the anchors
(x-app: &app) stay hand-written in the stack file, outside the generated block, and docker stack deploy
resolves them.
memory takes Docker's short units only. Kubernetes-style 512Mi or 1Gi is rejected.
The markers#
The stack file needs these two lines under services:, each starting at the beginning of a line with exactly
two spaces of indentation:
services:
# velyr:begin
# velyr:endText after # velyr:begin on the same line is replaced on every run (velyr-pack writes a "generated by"
comment there). Each environment needs its own file; two environments pointing at the same file overwrite each
other's block.
Image modes#
image = "cnb" | image = "dockerfile" | |
|---|---|---|
| Image | built by a velyr builder | any image |
| Service runs | entrypoint: ["/cnb/process/<process>"] | command: [<process command>..., <args>...] |
args go to | command: (appended by the CNB launcher) | the end of command: |
Raw command on a service | not allowed | allowed |
dockerfile is the way in for an existing stack: describe the services with your current image first, then
switch the environment to cnb when you move to the builder. Only the generated lines change.
Services#
Each entry of services becomes one Swarm service.
| Key | Type | Default | Meaning |
|---|---|---|---|
name | string | required | Service name, unique in the env, ^[a-z0-9][a-z0-9-]*$. |
process | string | A process from [processes]. Set exactly one of process and command. | |
args | array of strings | Appended to the process command, like ["--queue=mail"]. Only with process. | |
command | array of strings | A raw command instead of a process. Not allowed with image = "cnb". | |
replicas | integer | env replicas | Replica count. |
cpus, memory | string | env values | Resource limits, same format as the env. |
grace | duration | process grace | Overrides the process grace for this service. |
note | string | Written as a YAML comment above the service; each line of a multi-line string becomes a comment line. | |
extends | array of YAML aliases | env service_extends | Replaces the env list for this service. |
deploy_extends | array of YAML aliases | env deploy_extends | Replaces the env list for this service. |
environment | YAML alias | Written as environment: *alias. | |
volumes | array of strings | Written as volumes: entries, like "storage:/workspace/storage". | |
env_file | array of strings | Written as env_file: entries. | |
scale | table | Autoscaler entry, see scale. Does not change the stack file. |
extends and deploy_extends replace the environment lists instead of adding to them, so a service can opt
out of a shared default by listing only what it needs. An empty list (extends = []) opts out of all of them.
environment is an alias rather than a table on purpose: the shared environment map stays in one anchor in the
stack file, outside the generated block.
What a service becomes#
This service, in an env with image = "cnb", service_extends = ["*app"], deploy_extends = ["*restart"] and
cpus = "0.5", running a worker process with grace = "60s":
{ name = "worker-mail", process = "worker", args = ["--queue=mail"], memory = "256M", note = "Transactional mail" }renders as:
# Transactional mail
worker-mail:
<<: *app
init: true
entrypoint: ["/cnb/process/worker"]
command: ["--queue=mail"]
stop_grace_period: 60s
deploy:
mode: replicated
replicas: 1
update_config: {parallelism: 1, order: stop-first, failure_action: rollback, monitor: 30s}
rollback_config: {parallelism: 1, order: stop-first, failure_action: pause}
<<: *restart
resources:
limits:
cpus: "0.5"
memory: 256MThe keys always come in this order: note, merge key, init, entrypoint/command, volumes, environment,
env_file, healthcheck, stop_grace_period, deploy. Rollout policy explains each value.
scale#
scale describes how an external autoscaler should size the service. It does not change the stack file;
velyr-pack orbital <env> prints one line per scaled service:
<orbital_prefix><name>:<source>:<ref>:<min>:<max>:<target>[:<conn_weight>]{ name = "worker", process = "worker", scale = { source = "list", ref = "default", min = 1, max = 4, target = 500 } }$ velyr-pack orbital production
- shop_worker:list:default:1:4:500| Key | Required | Meaning |
|---|---|---|
source | yes | Load signal: kafka (consumer group lag), list (queue list length), stream (stream consumer group lag), caddy (FrankenPHP/Caddy utilization) or cpu. |
ref | no | What to read for that source: the consumer group, the queue name or the stream profile. Printed as - when empty. |
min, max | yes | Replica bounds, 1 <= min <= max. |
target | no | Backlog per replica the autoscaler aims for; 0 when the source does not use it (caddy, cpu). |
conn_weight | no | Database connections one replica holds, for an autoscaler that shares a connection budget. Omitted when 0. |
The output is a YAML list, indented to paste under a key of the autoscaler's config.
Validation#
Every command loads and checks the whole manifest before doing anything, and stops at the first error:
- the TOML parses and has no unknown keys;
- process and service names are lowercase and service names are unique in their env;
- every process has a command, and
healthhas apathand a positiveport; - every service sets exactly one of
processandcommand, and its process exists; argsonly goes withprocess, and services of acnbenv useprocess;cpusandmemoryresolve to a valid value, from the service or the env;- durations parse, and aliases look like
*name; scale.sourceis a known source,1 <= min <= max, andtargetandconn_weightare not negative.
The error names the env and the service: env "production": service "web": unknown process "api". The
troubleshooting page lists every message.
A complete example#
examples/laravel/velyr.toml and the
stack.yml generated from it. CI regenerates the stack with -check, so the
example always matches the current renderer.