Skip to content

Commit

Permalink
Merge pull request #151 from nickhammond/yml-anchors
Browse files Browse the repository at this point in the history
Add a full example of using yml anchors
  • Loading branch information
djmb authored Dec 18, 2024
2 parents c950e45 + 6602a3f commit a150951
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions _data/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
url: /docs/configuration/accessories/
- title: "Aliases"
url: /docs/configuration/aliases/
- title: "Anchors"
url: /docs/configuration/anchors/
- title: "Booting"
url: /docs/configuration/booting/
- title: "Builders"
Expand Down
30 changes: 30 additions & 0 deletions docs/configuration/anchors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Anchors
---

# Anchors

You can re-use parts of your Kamal configuration by defining them as anchors and referencing them with aliases.

For example, you might need to define a shared healthcheck for multiple worker roles. Anchors
begin with `x-` and are defined at the root level of your deploy.yml file.

```yaml
x-worker-healthcheck: &worker-healthcheck
health-cmd: bin/worker-healthcheck
health-start-period: 5s
health-retries: 5
health-interval: 5s
```
To use this anchor in your deploy configuration, reference it via the alias.
```yaml
servers:
worker:
hosts:
- 867.53.0.9
cmd: bin/jobs
options:
<<: *worker-healthcheck
```
4 changes: 2 additions & 2 deletions docs/configuration/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ e.g., `kamal deploy -d staging`.
In this case, the configuration will also be read from `config/deploy.staging.yml`
and merged with the base configuration.

## [Extensions](#extensions)
## [Anchors](#anchors)

Kamal will not accept unrecognized keys in the configuration file.

However, you might want to declare a configuration block using YAML anchors
and aliases to avoid repetition.

You can prefix a configuration section with `x-` to indicate that it is an
extension. Kamal will ignore the extension and not raise an error.
anchor. Kamal will ignore the anchor and not raise an error. See [Anchors](../anchors) for more information.

## [The service name](#the-service-name)

Expand Down

0 comments on commit a150951

Please sign in to comment.