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>]#

toml
[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" }
KeyTypeRequiredDefaultMeaning
commandarray of stringsyesThe command, run without a shell. Services append their args to it.
gracedurationnoweb: 45s, worker: Swarm's default (10s)stop_grace_period of every service running this process.
healthtablenoMakes it a web process: HTTP healthcheck and start-first rollout.
health.pathstringwith healthPath probed with curl -fsS http://localhost:<port><path>.
health.portintegerwith healthPort the process listens on inside the container.
health.start_perioddurationno60sHealthcheck 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>]#

toml
[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" },
]
KeyTypeRequiredDefaultMeaning
filestringyesStack 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_extendsarray of YAML aliasesnononeMerged into every service: <<: *app.
deploy_extendsarray of YAML aliasesnononeMerged into every service's deploy:: restart policy, placement.
replicasintegerno1Replicas of a service that does not set its own.
cpusstringhere or on every serviceCPU limit: a number, like "0.5" or "2".
memorystringhere or on every serviceMemory limit: digits with an optional K, M or G, like 512M or 1G.
orbital_prefixstringno""Prepended to service names by velyr-pack orbital, usually the stack name and _.
servicesarray of tablesno[]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:

yaml
services:
  # velyr:begin
  # velyr:end

Text 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"
Imagebuilt by a velyr builderany image
Service runsentrypoint: ["/cnb/process/<process>"]command: [<process command>..., <args>...]
args go tocommand: (appended by the CNB launcher)the end of command:
Raw command on a servicenot allowedallowed

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.

KeyTypeDefaultMeaning
namestringrequiredService name, unique in the env, ^[a-z0-9][a-z0-9-]*$.
processstringA process from [processes]. Set exactly one of process and command.
argsarray of stringsAppended to the process command, like ["--queue=mail"]. Only with process.
commandarray of stringsA raw command instead of a process. Not allowed with image = "cnb".
replicasintegerenv replicasReplica count.
cpus, memorystringenv valuesResource limits, same format as the env.
gracedurationprocess graceOverrides the process grace for this service.
notestringWritten as a YAML comment above the service; each line of a multi-line string becomes a comment line.
extendsarray of YAML aliasesenv service_extendsReplaces the env list for this service.
deploy_extendsarray of YAML aliasesenv deploy_extendsReplaces the env list for this service.
environmentYAML aliasWritten as environment: *alias.
volumesarray of stringsWritten as volumes: entries, like "storage:/workspace/storage".
env_filearray of stringsWritten as env_file: entries.
scaletableAutoscaler 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":

toml
{ name = "worker-mail", process = "worker", args = ["--queue=mail"], memory = "256M", note = "Transactional mail" }

renders as:

yaml
  # 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: 256M

The 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>]
toml
{ name = "worker", process = "worker", scale = { source = "list", ref = "default", min = 1, max = 4, target = 500 } }
console
$ velyr-pack orbital production
  - shop_worker:list:default:1:4:500
KeyRequiredMeaning
sourceyesLoad signal: kafka (consumer group lag), list (queue list length), stream (stream consumer group lag), caddy (FrankenPHP/Caddy utilization) or cpu.
refnoWhat to read for that source: the consumer group, the queue name or the stream profile. Printed as - when empty.
min, maxyesReplica bounds, 1 <= min <= max.
targetnoBacklog per replica the autoscaler aims for; 0 when the source does not use it (caddy, cpu).
conn_weightnoDatabase 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 health has a path and a positive port;
  • every service sets exactly one of process and command, and its process exists;
  • args only goes with process, and services of a cnb env use process;
  • cpus and memory resolve to a valid value, from the service or the env;
  • durations parse, and aliases look like *name;
  • scale.source is a known source, 1 <= min <= max, and target and conn_weight are 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.