Skip to content

Commit a772620

Browse files
authored
Merge pull request #933 from seanhinde/multiple-overlay-files
Add per template override of overlay vars
2 parents fe2fc77 + 96e4726 commit a772620

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

src/rlx_overlay.erl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ read_overlay_vars(State, OverlayVars, FileNames) ->
118118
% definitions should be able to be overwritten by both internal
119119
% and rendered vars, as not to change behaviour in
120120
% setups preceding the support for overlays from the caller.
121-
OverlayVars ++ NewTerms ++ OverlayVarsValues;
121+
% Place NewTerms at the start - the last overlays added should be able
122+
% to override those that came before
123+
NewTerms ++ OverlayVars ++ OverlayVarsValues;
122124
Error ->
123125
Error
124126
end.
@@ -324,6 +326,17 @@ do_individual_overlay(State, Release, _Files, OverlayVars, {template, From, To})
324326
absolute_path_to(State, Release, ToFile))
325327
end)
326328
end);
329+
do_individual_overlay(State, Release, _Files, OverlayVars0, {template, From, To, OverlayFilename}) ->
330+
OverlayVars = read_overlay_vars(State, OverlayVars0, [OverlayFilename]),
331+
file_render_do(OverlayVars, From,
332+
fun(FromFile) ->
333+
file_render_do(OverlayVars, To,
334+
fun(ToFile) ->
335+
write_template(OverlayVars,
336+
absolute_path_from(State, FromFile),
337+
absolute_path_to(State, Release, ToFile))
338+
end)
339+
end);
327340
do_individual_overlay(_State, _Release, _Files, _OverlayVars, Invalid) ->
328341
?RLX_ERROR({malformed_overlay, Invalid}).
329342

test/rlx_release_SUITE.erl

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,72 @@ make_dev_mode_template_release(Config) ->
829829
%% ensure that the original vm.args didn't get overwritten
830830
?assertMatch({ok, <<"-sname {{nodename}}">>}, file:read_file(VmArgs)).
831831

832+
make_multiple_overlay_vars_template_release(Config) ->
833+
LibDir1 = ?config(lib_dir, Config),
834+
OutputDir = ?config(out_dir, Config),
835+
836+
SysConfig = filename:join([LibDir1, "config", "sys.config"]),
837+
SysConfigTerm = [{this_is_a_test, "yup it is"},
838+
{this_is_an_overlay_var, "{{var1}}"},
839+
{this_is_another_overlay_var, "{{var2}}"}],
840+
rlx_test_utils:write_config(SysConfig, SysConfigTerm),
841+
842+
VarsFile1 = filename:join([LibDir1, "config", "vars1.config"]),
843+
rlx_test_utils:write_config(VarsFile1, [{var1, "indeed it is"},
844+
{var2, "and so"},
845+
{nodename, "testnode"}]),
846+
847+
VarsFile2 = filename:join([LibDir1, "config", "vars2.config"]),
848+
rlx_test_utils:write_config(VarsFile2, [{var1, "indeed it is and more"}]),
849+
850+
VarsFile3 = filename:join([LibDir1, "config", "vars3.config"]),
851+
rlx_test_utils:write_config(VarsFile3, [{var1, "indeed it is and more"},
852+
{var2, "and so on"}]),
853+
854+
RelxConfig = [{dev_mode, true},
855+
{mode, dev},
856+
{sys_config, SysConfig},
857+
{overlay_vars, [VarsFile1]},
858+
{overlay, [
859+
{template, "config/sys.config",
860+
"releases/{{release_version}}/sys.config"},
861+
{template, "config/sys.config",
862+
"releases/{{release_version}}/a/sys.config", VarsFile2},
863+
{template, "config/sys.config",
864+
"releases/{{release_version}}/b/sys.config", VarsFile3}]},
865+
{release, {foo, "0.0.1"},
866+
[goal_app_1,
867+
goal_app_2]},
868+
{check_for_undefined_functions, false}],
869+
870+
871+
{ok, State} = relx:build_release(foo, [{root_dir, LibDir1}, {lib_dirs, [LibDir1]},
872+
{output_dir, OutputDir} | RelxConfig]),
873+
874+
[{{foo, "0.0.1"}, _Release}] = maps:to_list(rlx_state:realized_releases(State)),
875+
876+
?assert(rlx_file_utils:is_symlink(filename:join([OutputDir, "foo", "lib", "non_goal_1-0.0.1"]))),
877+
?assert(rlx_file_utils:is_symlink(filename:join([OutputDir, "foo", "lib", "non_goal_2-0.0.1"]))),
878+
?assert(rlx_file_utils:is_symlink(filename:join([OutputDir, "foo", "lib", "goal_app_1-0.0.1"]))),
879+
?assert(rlx_file_utils:is_symlink(filename:join([OutputDir, "foo", "lib", "goal_app_2-0.0.1"]))),
880+
?assert(rlx_file_utils:is_symlink(filename:join([OutputDir, "foo", "lib", "lib_dep_1-0.0.1"]))),
881+
?assert(not rlx_file_utils:is_symlink(filename:join([OutputDir, "foo", "releases", "0.0.1",
882+
"sys.config"]))),
883+
?assert(not rlx_file_utils:is_symlink(filename:join([OutputDir, "foo", "releases", "0.0.1","a",
884+
"sys.config"]))),
885+
?assert(not rlx_file_utils:is_symlink(filename:join([OutputDir, "foo", "releases", "0.0.1","b",
886+
"sys.config"]))),
887+
{ok, AConfig} = file:consult(filename:join([OutputDir, "foo", "releases", "0.0.1","a",
888+
"sys.config"])),
889+
?assertMatch("indeed it is and more", proplists:get_value(this_is_an_overlay_var, AConfig)),
890+
?assertMatch("and so", proplists:get_value(this_is_another_overlay_var, AConfig)),
891+
{ok, BConfig} = file:consult(filename:join([OutputDir, "foo", "releases", "0.0.1","b",
892+
"sys.config"])),
893+
?assertMatch("indeed it is and more", proplists:get_value(this_is_an_overlay_var, BConfig)),
894+
?assertMatch("and so on", proplists:get_value(this_is_another_overlay_var, BConfig)),
895+
%% ensure that the original sys.config didn't get overwritten
896+
?assertMatch({ok, SysConfigTerm}, file:consult(SysConfig)).
897+
832898
%% verify that creating a new app with the same name after creating a release results in the
833899
%% newest version being used in the new release
834900
make_release_twice(Config) ->

0 commit comments

Comments
 (0)