erlware / relx

Sane, simple release creation for Erlang
http://erlware.github.io/relx
Apache License 2.0
696 stars 233 forks source link

Add per template override of overlay vars #933

Closed seanhinde closed 5 months ago

seanhinde commented 7 months ago

This PR adds the possibility to have a different overlay_vars file applied to each template line in a release. This allows creation of multiple output files with different content from a single template file.

It implements the discussion from https://github.com/erlware/relx/issues/757

So from a single template file e.g. priv/app.config containing

{param, {{var}}}.

it will be possible to generate multiple output files in the same release:

{template, "priv/app.config", "host1/app.config", "host1_overlay_vars.config"},
{template, "priv/app.config", "host2/app.config", "host2_overlay_vars.config"},

where host1_overlay_vars.config could contain

{var, "host 1 config"}.

and host2_overlay_vars.config could contain

{var, "host 2 config"}.

generating two output files.

This PR includes a test case.

There is one change here I'm not sure about. When there is also a global overlay_vars file it would be nice if the template specific variables could override the global ones. In the implementation I've re-used rex_overlay:read_overlay_vars/3 but that function always makes newer variables hidden if they are already set. I've changed its behaviour, but this could cause breakage.

In my case I don't need this - I always set all the vars in each vars file, but it seems useful. Could also be fixed by making a copy of the read_overlay_vars function with the different ordering. I'd welcome some input here.

ferd commented 5 months ago

I've merged this because I agree we should ideally see local vars take over the global ones. I do share the risk around breakage there, but I'm not quite sure there's anything we can do to de-risk that.

seanhinde commented 5 months ago

Tremendous, thanks very much