Support passing the whole context for env and resources

This commit is contained in:
Daniel Berteaud 2024-01-17 16:03:03 +01:00
parent ba25682e54
commit ec581ab748
2 changed files with 30 additions and 6 deletions

View File

@ -1,4 +1,16 @@
[[- range $k, $v := . ]]
[[- /*
# vim: syntax=hcl
# Note: for compatibility, we take env either from .env (when passing the whole context to the template)
# or from . (when only .env is passed as context)
*/ -]]
[[- $env := dict ]]
[[- if and (has . "env") (isKind "map" .env) ]]
[[- $env = .env ]]
[[- else ]]
[[ $env = . ]]
[[- end -]]
[[- range $k, $v := $env ]]
[[- if isKind "number" $v ]]
[[ $k ]] = [[ $v ]]
[[- else ]]

View File

@ -1,7 +1,19 @@
[[- /*
# vim: syntax=hcl
# Note: for compatibility, we take resources either from .resources (when passing the whole context to the template)
# or from . (when only .resources is passed as context)
*/ -]]
[[- $resources := dict ]]
[[- if and (has . "resources") (isKind "map" .resources) ]]
[[- $resources = .resources ]]
[[- else ]]
[[ $resources = . ]]
[[- end -]]
resources {
cpu = [[ .cpu ]]
memory = [[ .memory ]]
[[- if has . "memory_max" ]]
memory_max = [[ .memory_max ]]
[[- end ]]
cpu = [[ $resources.cpu ]]
memory = [[ $resources.memory ]]
[[- if has $resources "memory_max" ]]
memory_max = [[ $resources.memory_max ]]
[[- end ]]
}