Configurable Templates with Variables
Upon finalising your template repository you have the opportunity to enhance your templates with Template Variables. These are simple parameters
used during creation of environments.
This functionality empowers a single environment definition to be both configurable and maintainable for template creators. While simultaneously, it ensures ease of use for future users, fostering a seamless experience within our platform's ecosystem.
Preparing your environment
Within bunnyshell.yaml
everything is configurable. Template creators should strategically identify, expose, and leverage parameters relevant across the entire environment. Alternatively, the parameters should impact multiple layers of a single component. Let's delve into an illustrative example:
# ...
variables:
- description: 'Backend workers'
name: 'workers'
type: 'int'
- description: 'Enable remote development tooling'
name: 'remoteDevelopment'
type: 'bool'
- description: 'Verbosity level'
name: 'verbosity'
type: 'enum'
values: ['', 'v', 'vv', 'vvv']
- description: 'Application name'
name: 'app_name'
type: 'string'
# ...
and using them in bunnyshell.yaml
# ...
templateVariables:
workers: 5
remoteDevelopment: false
verbosity: 'vvv'
app_name: "My App"
# ...
components:
- name: 'backend'
dockerCompose:
environment:
THREAD_POOL: '{{ template.vars.workers }}'
# ...
- name: 'webserver'
dockerCompose:
build:
args:
MAX_CONNECTIONS: '{{ template.vars.workers * 100 }}'
LOG_VERBOSITY: '{{ template.vars.verbosity }}'
# ...
- name: 'frontend'
dockerComposer:
build:
args:
INSTALL_DEBUG_TOOLS: '{{ (template.vars.remoteDevelopment || template.vars.verbosity != '') ? "On" : ""})
ESLINT_NO_DEV_ERRORS: '{{ template.vars.remoteDevelopment ? "On" : "" }}'
APPLICATION_NAME: '{{ template.vars.app_name }}'
# ...
# ...
Template Variables Schema
# all properties are required
name: 'string'
description: 'string'
type: 'bool'|'int'|'float'|'string'|'enum'
# all properties are required
name: 'string'
description: 'string'
type: 'enum' # literal string
values: 'int[]|string[]'
See Also
Updated 5 months ago