Skip to content

Workspace Configuration Templates

Workspace Manager uses the Go template language to process templated files specified in /shared/workspaceInit.yaml. This guide covers the template syntax and available variables for workspace initialization.

Go templates are text files with dynamic expressions enclosed in double curly braces: {{ expression }}. Most content renders directly, with expressions replaced by their evaluated results.

Simple example:

<?php
echo "Hello {{ .name }}";

Configuration example:

<?php
return [
'db' => [
'connection' => [
'indexer' => [
'host' => '{{ .env.WORKSPACE_DB_HOST }}',
'dbname' => '{{ .env.WORKSPACE_DB_NAME }}',
'username' => '{{ .env.WORKSPACE_DB_USER }}',
'password' => '{{ .env.WORKSPACE_DB_PASSWORD }}',
]
]
]
];

Reference variables by starting with a period: .variableName

Built-in variable:

  • .env - Contains all environment variables available to the initialization job (see full list below)

Custom variables:

{{ $myVariable := "hello world" }}
{{ $myArray := split "a b c" " " }}

Functions are called by name and can take parameters:

{{ $myArray := split "a b c" " " }}

Functions can also be used as filters with the pipe operator |:

{{ $myArray := ("a b c" | split " ") }}

Available functions:

  • env - Get environment variable value

    {{ env "ENV_VAR_NAME" }}
  • default - Provide fallback value

    {{ .env.ENV_VAR_NAME | default "default_value" }}
  • html - HTML-escape a string

    {{ "5 > 2" | html }}
  • split - Split string by delimiter

    {{ split "a b c" " " }}
    {{ "example.foo.com" | split "." }}
  • join - Join array with delimiter

    {{ "a b c" | split " " | join "-" }} {{- /* Result: a-b-c */ -}}
  • add - Arithmetic addition

    {{ "a b c" | split " " | length | add -1 }} {{- /* Result: 2 */ -}}

See default Go template functions for additional built-in functions.

Conditionals:

{{- if $expression }}
{{- /* First option */ -}}
{{- else if $anotherExpression }}
{{- /* Else if option */ -}}
{{- else }}
{{- /* Else option */ -}}
{{- end }}

Loops:

{{- range $index, $value := $someArrayOrStruct }}
{{ $index }}: {{ $value }}
{{- end }}

Control whitespace around expressions with the minus sign:

  • {{- expression }} - Remove leading whitespace
  • {{ expression -}} - Remove trailing whitespace
  • {{- expression -}} - Remove whitespace on both sides
{{- /* This is a comment */ -}}

When you need literal {{ or }} in your output (common in Magento env.php files), escape them with backticks:

{{ `{{literal_thing}}` }}

Example:

'unsecure' => [
'base_url' => 'https://{{ .env.WORKSPACE_DOMAIN_1 }}/',
'base_link_url' => '{{ `{{unsecure_base_url}}` }}',
'base_static_url' => null,
],

Access environment variables using either .env.VARIABLE_NAME or env "VARIABLE_NAME":

{{ .env.WORKSPACE_NAME }}
{{ env "WORKSPACE_NAME" }}

Available variables:

VariableDescription
WORKSPACE_SHARED_DIRShared folder location (currently /shared)
WORKSPACE_DOMAINSSpace-separated list of all workspace domains
WORKSPACE_DOMAIN_NNth domain name (1-based: WORKSPACE_DOMAIN_1, WORKSPACE_DOMAIN_2, etc.)
WORKSPACE_SUBDOMAINSSpace-separated list of all subdomains
WORKSPACE_SUBDOMAIN_NNth subdomain (1-based: WORKSPACE_SUBDOMAIN_1, etc.)
WORKSPACE_NAMEWorkspace name/subdomain within the project
WORKSPACE_IDUnique workspace ID
WORKSPACE_PROJECT_NAMEProject name
WORKSPACE_PROJECT_IDUnique project ID
WORKSPACE_TEMPLATEWorkspace type (e.g., m2Ubuntu)
WORKSPACE_PROJECT_TEMPLATEProject type (e.g., default)
WORKSPACE_DEVELOPERWorkspace owner name
WORKSPACE_DEVELOPER_EMAILWorkspace owner email
WORKSPACE_DEVELOPER_IDUnique owner ID
WORKSPACE_DB_NAMEDatabase name for this workspace
WORKSPACE_DB_HOSTDatabase hostname (currently db)
WORKSPACE_DB_USERDatabase user (currently root)
WORKSPACE_DB_PASSWORDDatabase password
WORKSPACE_INIT_TYPEInitialization type: repo or empty
WORKSPACE_REPOGit repository SSH URL (if applicable)
WORKSPACE_REPO_REFBranch or tag name used to seed workspace
'db' => [
'connection' => [
'indexer' => [
'host' => '{{ .env.WORKSPACE_DB_HOST }}',
'dbname' => '{{ .env.WORKSPACE_DB_NAME }}',
'username' => '{{ .env.WORKSPACE_DB_USER }}',
'password' => '{{ .env.WORKSPACE_DB_PASSWORD }}',
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
'persistent' => null
],
'default' => [
'host' => '{{ .env.WORKSPACE_DB_HOST }}',
'dbname' => '{{ .env.WORKSPACE_DB_NAME }}',
'username' => '{{ .env.WORKSPACE_DB_USER }}',
'password' => '{{ .env.WORKSPACE_DB_PASSWORD }}',
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
'driver_options' => [
1014 => false
]
]
],
'table_prefix' => ''
],
'session' => [
'save' => 'redis',
'redis' => [
'host' => '{{ .env.WORKSPACE_REDIS_HOST | default "127.0.0.1" }}',
'port' => '{{ .env.WORKSPACE_REDIS_PORT | default "6379" }}',
'password' => '',
'timeout' => '2.5',
'persistent_identifier' => '',
'database' => '2',
'compression_threshold' => '2048',
'compression_library' => 'gzip',
'log_level' => '1',
'max_concurrency' => '6',
'break_after_frontend' => '5',
'break_after_adminhtml' => '30',
'first_lifetime' => '600',
'bot_first_lifetime' => '60',
'bot_lifetime' => '7200',
'disable_locking' => '0',
'min_lifetime' => '60',
'max_lifetime' => '2592000',
'sentinel_master' => '',
'sentinel_servers' => '',
'sentinel_connect_retries' => '5',
'sentinel_verify_master' => '0'
]
],
'cache' => [
'frontend' => [
'default' => [
'id_prefix' => '0e2_',
'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
'backend_options' => [
'server' => '{{ .env.WORKSPACE_REDIS_HOST | default "127.0.0.1" }}',
'database' => '0',
'port' => '{{ .env.WORKSPACE_REDIS_PORT | default "6379" }}',
'password' => '',
'compress_data' => '1',
'compression_lib' => ''
]
],
'page_cache' => [
'id_prefix' => '0e2_'
]
],
'allow_parallel_generation' => false
],
'downloadable_domains' => [
{{- $domainArr := split .env.WORKSPACE_DOMAINS " " }}
{{- range $ix, $domain := $domainArr }}
'{{ $domain }}'{{ if lt $ix (len $domainArr | add -1) }},{{ end }}
{{- end }}
],
'system' => [
'default' => [
'web' => [
'unsecure' => [
'base_url' => 'https://{{ .env.WORKSPACE_DOMAIN_1 }}/',
'base_link_url' => '{{ `{{unsecure_base_url}}` }}',
'base_static_url' => null,
'base_media_url' => null
],
'secure' => [
'base_url' => '{{ `{{unsecure_base_url}}` }}',
'base_link_url' => '{{ `{{secure_base_url}}` }}',
'base_static_url' => null,
'base_media_url' => null
],
'default' => [
'front' => 'cms'
],
'cookie' => [
'cookie_path' => null,
'cookie_domain' => null
]
],
'catalog' => [
'search' => [
'engine' => 'elasticsearch7',
'elasticsearch7_server_hostname' => '{{ .env.WORKSPACE_DB_HOST }}',
'elasticsearch7_server_port' => '{{ .env.WORKSPACE_ELASTICSEARCH_PORT | default "9200" }}',
'elasticsearch7_index_prefix' => '{{ .env.WORKSPACE_NAME }}'
]
]
]
]