bossm8 / dockerfile-templater

GO utility to generate Dockerfiles in different variants from yml data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sprig Dict functions with {{ . }}

GabriFedi97 opened this issue · comments

In order to easily pass the current context {{ . }} plus some variables defined directly as a Dict in the template, to a sub template, I need to be able to merge the both maps in a single one.
Trying to do something like:

{{ $myDict := dict "name1" "value1" "name2" "value2" "name3" "value 3" }}
{{ template "anytemplate" deepCopy . | merge $myDict }}

I get the following error:

[ERROR]: Could not execute template 'Dockerfile.tpl': template: Dockerfile.tpl:7:41: 
executing "Dockerfile.tpl" at <$myDict>: wrong type for value; expected map[string]interface {}; got *interface {}

The issue is, more in general, that we can't expect to use any function that sprig offers to manipulate Dicts with {{ . }}, since its type is *interface {} and sprig Dicts require to be map[string]interface {}, as per sprig documentation:

The key to a dictionary must be a string. However, the value can be any type, even another dict or list.