ldez / seihon

A simple tool to build and publish multi-arch images on the Docker Hub.
Other
21 stars 1 forks source link

tmpl.Dockerfile name cannot be changed #17

Closed andig closed 3 years ago

andig commented 3 years ago

I needed to have a separate template file and copied tmpl.Dockerfileto ci.Dockerfile. Running with different name fails:

Version: 0.62 2021-08-22_09:43:34
seihon publish --dry-run=false --template docker/ci.Dockerfile --base-runtime-image alpine:3.13 \
       --image-name andig/evcc -v "latest" --targets=arm.v6,arm.v8,amd64
Error: template: "tmpl.Dockerfile" is an incomplete or empty template

This seems to happen inside parse.Execute because t.Tree is nil but I couldn't figure out why. The produced architecture dockerfile turns up empty.

andig commented 3 years ago

Update: looks as if the problem is the command chaining:

    if name == t.Name() {
        tmpl = t
    } else {
        tmpl = t.New(name)
    }

will create a template of ci.Dockerfile name, not tmpl.Dockerfile as one might expect due to

parse, err := template.New("tmpl.Dockerfile").
    Funcs(sprig.FuncMap()).
    ParseFiles(dockerfileTemplate)
if err != nil {
    return err
}

Imho this does not work as expected

andig commented 3 years ago

One potential workaround could be to use template.Parse instead of template.ParseFiles here as this will keep the template name unchanged. I'm not sure if that will handle hierarchical templates though.

ldez commented 3 years ago

Fixed by 3f28a201b4402c19d2ad9d898da4fd9a61ccdd4e