2.6 KiB
| title | description | keywords |
|---|---|---|
| Compose Bridge templates | Learn about the Compose Bridge templates syntax | compose, bridge, templates |
{{< include "compose-bridge-early-access.md" >}}
Compose Bridge's default transformation uses templates to produce Kubernetes manifests. This page describes the templating mechanism.
Syntax
Templates are plain text files, using go-template
to allow logic and data injection based on the compose.yaml model.
When a template is executed, it must produce a YAML file. Multiple files can be generated
as long as those are separated by ---
The first line, when creating the YAML file, defines the file being generated using a custom notation:
#! manifest.yaml
With this header comment, manifest.yaml will be created by Compose Bridge with the content following
the annotation.
Combining these together, you can write a template to iterate over some of Compose resources, then for each resource you can produce a dedicated manifest:
{{ range $name, $service := .services }}
---
#! {{ $name }}-manifest.yaml
# Generated code, do not edit
key: value
## ...
{{ end }}
This example produces a manifest file for each and every Compose service in you Compose model.
Input
The input compose model is the canonical yaml model you can get by running
docker compose config. Within a template you can access model nodes using
dot notation:
# iterate over a yaml sequence
{{ range $name, $service := .services }}
# access a nested attribute using dot notation
{{ if eq $service.deploy.mode "global" }}
kind: DaemonSet
{{ end }}
{{ end }}
You can check the Compose Specification json-spec file to have a full overview of the Compose model.
Helpers
As part of the Go templating syntax, Compose Bridge offers a set of helper functions:
seconds: convert a duration into an integeruppercaseconvert a string into upper case characterstitle: convert a string by capitalizing first letter of each wordsafe: convert a string into a safe identifier, replacing all characters but [a-z] with-truncate: removes the N first elements from a listjoin: group elements from a list into a single string, using a separatorbase64: encode string as base64map: transform value according to mappings expressed as"value -> newValue"stringsindent: writes string content indented by N spaceshelmValue: write the string content as a template value in final file