Introducing a new way to review your PRs.

Read the announcement

basecamp / kamal

Deploy web apps anywhere.

View on GitHub

17 documents · Updated Nov 16, 2026

docs / configuration-system

Deployment configuration system

Kamal turns deployment YAML into one checked configuration object before a command can act. It loads a base file and an optional destination file, resolves templates and secrets, builds shared views of the deployment, and rejects invalid or unsafe combinations early. The child pages Application topology configuration, Service configuration, and Environment and secrets explain the main configuration areas in more detail.

Configuration lifecycle

The configuration lifecycle converts files and command options into the state used by deployment commands. The CLI selects the input file, while Kamal::Configuration owns loading, merging, validation, and creation of the derived configuration areas.

When Kamal processes a command, it follows this sequence:

  1. The CLI selects config/deploy.yml by default and can select a destination such as staging.
  2. Kamal evaluates ERB in the base YAML and loads its keys.
  3. If a destination is present, Kamal loads config/deploy.<destination>.yml and deep-merges it over the base configuration.
  4. Kamal validates the complete raw configuration against the documented shape.
  5. Kamal creates views for servers, roles, registry, builder, environment, proxy, SSH, logging, accessories, and related settings.
  6. Kamal applies cross-area checks before commands use the configuration.

This flow means command code receives a consistent model instead of reading YAML files directly. A missing destination file stops loading, and a validation or consistency error stops configuration creation before remote work begins.

The following diagram shows how command input becomes command-ready deployment state.

flowchart LR
    A[CLI options] --> B[Base YAML]
    A --> C[Destination YAML]
    B --> D[ERB and YAML loading]
    C --> D
    D --> E[Deep-merged raw configuration]
    E --> F[Shape validation]
    F --> G[Derived configuration areas]
    G --> H[Cross-area checks]
    H --> I[Deployment commands]

References: lib/…/base.rb• L17-28 lib/…/base.rb• L52-75 lib/…/configuration.rb• L19-50 lib/…/configuration.rb• L54-91

Configuration structure

The raw configuration is the shared source for the deployment model. Kamal exposes its major areas as related objects so commands can ask for deployment facts such as roles, hosts, image names, environment data, and proxy behavior without knowing the file layout.

The main configuration areas have these responsibilities:

AreaResponsibilityRelated page
Service and imageIdentify the application and the image to deploy.Service configuration
Registry and builderDefine image access and how the image is built.Service configuration
Servers and rolesMap application roles to hosts and role-specific behavior.Application topology configuration
AccessoriesDescribe additional services that run beside the application.Application topology configuration
Environment and secretsBuild clear environment values and secret-backed values.Environment and secrets
Proxy and bootDefine traffic entry, readiness, and proxy startup behavior.Application topology configuration
SSH and SSHKitDefine how Kamal reaches hosts and runs remote work.—
Logging and outputDefine container log settings and Kamal output sinks.—
Hooks and pathsLocate hooks and runtime data and control hook output.—

The configuration also provides shared names and paths. A service and destination form the application identity used for runtime directories and container names. The selected version forms the image tag and container version used by commands.

References: lib/…/configuration.rb• L14-17 lib/…/configuration.rb• L61-79 lib/…/configuration.rb• L116-209 lib/…/configuration.rb• L248-303

Configuration validation

Validation protects the boundary between user configuration and deployment actions. Kamal first checks the structure and value types against YAML documentation, then checks rules that depend on several configuration areas or on the current project.

The validation model has three levels:

  • Shape checks reject unknown keys and wrong value types. Configuration extensions with an x- prefix are allowed for reusable YAML data.
  • Area checks validate special structures such as server host entries, role options, environment blocks, registry credentials, and builder settings.
  • Deployment checks enforce required values and safe relationships. These include a valid service name, a defined primary role, hosts for required roles, a compatible Kamal version, valid retention, valid hook output, and non-conflicting proxy settings.

Errors include the path to the invalid value where possible. This gives the engineer a file-like context such as servers/workers/proxy instead of a generic failure.

References: lib/…/validation.rb• L4-26 lib/…/validator.rb• L10-59 lib/…/validator.rb• L118-176 lib/…/validator.rb• L183-219 lib/…/configuration.rb• L1-6 lib/…/configuration.rb• L323-447

Derived configuration

Derived configuration turns nested file data into the objects that commands use. This step also combines defaults with local choices, so commands see effective values rather than repeating merge rules.

The most important derived relationships are:

  • Servers create roles. Roles expose hosts and combine global settings with role-specific environment, logging, proxy, labels, and Docker options.
  • Environment settings combine clear values, selected secrets, and host tags. Role environment is then merged with global environment for each host.
  • Registry settings resolve direct credentials or names that point to the secret store. The registry also determines whether the image is local or remote.
  • Builder settings determine local and remote build targets, supported architectures, cache use, and build context.
  • Proxy settings combine global proxy behavior with role-specific proxy behavior. Kamal checks the final proxy runs for each host so shared hosts do not receive conflicting proxy definitions.

This model lets deployment commands use one effective view while preserving the distinction between global settings and role or destination overrides.

References: lib/…/servers.rb• L6-23 lib/…/role.rb• L10-27 lib/…/role.rb• L66-96 lib/…/env.rb• L7-27 lib/…/registry.rb• L4-38 lib/…/builder.rb• L8-17 lib/…/proxy.rb• L9-18 lib/…/configuration.rb• L418-429

Destination configuration

A destination is a named deployment variant selected by the command line. It changes which overlay file Kamal loads and becomes part of the application identity used by runtime state and image tags.

The base file remains the common definition. The destination file supplies overrides and is deep-merged after the base file, so nested settings can change without copying the full deployment. A configuration can require a destination when the same project must not deploy without an explicit target.

References: lib/…/base.rb• L26-28 lib/…/configuration.rb• L23-30 lib/…/configuration.rb• L49-50 lib/…/configuration.rb• L116-118 lib/…/configuration.rb• L212-214 lib/…/configuration.rb• L325-331

Configuration consumers

Commands consume the prepared configuration after CLI setup completes. The command layer uses the configuration to select hosts and roles, form image and container names, build remote commands, load environment files, and control hooks.

The configuration is therefore a contract between deployment intent and command execution. If its shape or derived meaning changes, the affected command consumers must still receive the same effective values for hosts, images, credentials, paths, and timing.

References: lib/…/base.rb• L63-75 lib/…/base.rb• L7-15 lib/…/base.rb• L99-131 lib/…/configuration.rb• L305-320

Change checklist

When these files or sections are changed, remember to consider these:

  • A change to destination file loading must preserve the base-then-overlay merge order and the KAMAL_DESTINATION value used by downstream templates and secrets.
  • A change to the validation example or validator must keep accepted YAML shapes aligned with the derived objects that consume them.
  • A change to role, environment, registry, builder, or proxy merging must be checked against both global and specialized settings.
  • A change to version, service, or destination naming must preserve image tags, container names, and .kamal runtime paths together.
  • A change to secret references must preserve the distinction between direct values and names resolved from common or destination-specific secret files.

Important failure modes

TriggerConsequenceGuard
A selected destination file does not existConfiguration loading stops before a command runs.Keep the destination name and config/deploy.<destination>.yml pair in sync.
A required service, registry, image, or primary role is missingKamal cannot build a complete deployment target.Configuration creation raises a configuration error.
A role has no hosts when empty roles are not allowedThe role has no valid execution target.Define hosts or enable allow_empty_roles when that state is intentional.
Two roles or accessories give one host different proxy run settingsProxy behavior is ambiguous on that host.Use one effective proxy run configuration per host.
A secret reference has no matching secret valueEnvironment or registry setup cannot produce the required value.Provide the key in the common or selected destination secret file.
A local registry uses a remote builder without an SSH URLThe builder cannot reach the local registry through the expected transport.Use an SSH remote URL for the builder.

Key files

FileWhy to read it
lib/…/configuration.rbMain lifecycle, derived configuration areas, defaults, and cross-area checks.
lib/…/validation.rbShared entry point for schema validation.
lib/…/validator.rbCommon type, key, path, host, and error-context rules.
lib/…/configuration.ymlThe documented top-level configuration shape used for validation.
lib/…/servers.rbConversion from server settings to role objects.
lib/…/role.rbRelationship between hosts, role settings, environment, and proxy behavior.
lib/…/secrets.rbLoading and precedence of common and destination-specific secret files.
lib/…/base.rbCLI options that choose the configuration file, destination, and version before commands start.