aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/rlx_cmd_args.erl3
-rw-r--r--src/rlx_prv_overlay.erl3
-rw-r--r--src/rlx_state.erl8
-rw-r--r--test/rlx_release_SUITE.erl23
-rw-r--r--test/rlx_test_utils.erl3
5 files changed, 33 insertions, 7 deletions
diff --git a/src/rlx_cmd_args.erl b/src/rlx_cmd_args.erl
index 4f5e9da..1dc10c1 100644
--- a/src/rlx_cmd_args.erl
+++ b/src/rlx_cmd_args.erl
@@ -298,6 +298,9 @@ create(add_providers, Opts) ->
create(providers, Opts) ->
Providers = proplists:get_value(providers, Opts, []),
{providers, Providers};
+create(api_caller_overlays, Opts) ->
+ ApiCallerOverlays = proplists:get_value(api_caller_overlays, Opts, []),
+ {api_caller_overlays, ApiCallerOverlays};
create(_, _) ->
[].
diff --git a/src/rlx_prv_overlay.erl b/src/rlx_prv_overlay.erl
index 75608b3..5ba3f75 100644
--- a/src/rlx_prv_overlay.erl
+++ b/src/rlx_prv_overlay.erl
@@ -273,7 +273,8 @@ generate_state_vars(State) ->
erlang:atom_to_list(Name1);
{Name1, Vsn1} ->
erlang:atom_to_list(Name1) ++ "-" ++ Vsn1
- end}].
+ end}
+ | rlx_state:api_caller_overlays(State)].
-spec do_overlay(rlx_state:t(), list(), proplists:proplist()) ->
{ok, rlx_state:t()} | relx:error().
diff --git a/src/rlx_state.erl b/src/rlx_state.erl
index cab55f6..a4b21fa 100644
--- a/src/rlx_state.erl
+++ b/src/rlx_state.erl
@@ -44,6 +44,7 @@
goals/2,
config_file/1,
config_file/2,
+ api_caller_overlays/1,
cli_args/1,
cli_args/2,
providers/1,
@@ -104,6 +105,7 @@
output_dir :: file:name(),
lib_dirs=[] :: [file:name()],
config_file=[] :: file:filename() | undefined,
+ api_caller_overlays=[] :: [{atom(),string()}],
cli_args=[] :: proplists:proplist(),
goals=[] :: [rlx_depsolver:raw_constraint()],
providers=[] :: [providers:t()],
@@ -160,8 +162,10 @@ new(Config, CommandLineConfig, Targets)
Log = proplists:get_value(
log, CommandLineConfig,
ec_cmd_log:new(error, Caller, rlx_util:intensity())),
+ ApiCallerOverlays = proplists:get_value(api_caller_overlays, CommandLineConfig, []),
State0 = #state_t{log=Log,
config_file=Config,
+ api_caller_overlays=ApiCallerOverlays,
cli_args=CommandLineConfig,
actions=Targets,
caller=Caller,
@@ -270,6 +274,10 @@ config_file(#state_t{config_file=ConfigFiles}) ->
config_file(State, ConfigFiles) ->
State#state_t{config_file=ConfigFiles}.
+-spec api_caller_overlays(t()) -> [{atom(),string()}].
+api_caller_overlays(#state_t{api_caller_overlays = ApiCallerOverlays}) ->
+ ApiCallerOverlays.
+
-spec cli_args(t()) -> proplists:proplist().
cli_args(#state_t{cli_args=CliArgs}) ->
CliArgs.
diff --git a/test/rlx_release_SUITE.erl b/test/rlx_release_SUITE.erl
index d7340de..b6289d6 100644
--- a/test/rlx_release_SUITE.erl
+++ b/test/rlx_release_SUITE.erl
@@ -818,12 +818,15 @@ overlay_release(Config) ->
goal_app_2]}]),
VarsFile1 = filename:join([LibDir1, "vars1.config"]),
- %% tpl_var is defined in vars1, but redifined in vars2 using template.
+ ProfileString = "prod-v5",
+ %% `tpl_var' is defined in vars1, but redifined in vars2 using template.
+ %% `profile_string' is to be injected as an API caller overlay var
rlx_test_utils:write_config(VarsFile1, [{yahoo, "yahoo"},
{yahoo2, [{foo, "bar"}]},
{foo_yahoo, "foo_{{yahoo}}"},
{foo_dir, "foodir"},
- {tpl_var, "defined in vars1"}]),
+ {tpl_var, "defined in vars1"},
+ {profile_string_value, "{{profile_string}}"}]),
VarsFile2 = filename:join([LibDir1, "vars2.config"]),
rlx_test_utils:write_config(VarsFile2, [{google, "yahoo"},
@@ -851,8 +854,16 @@ overlay_release(Config) ->
OutputDir = filename:join([proplists:get_value(priv_dir, Config),
rlx_test_utils:create_random_name("relx-output")]),
- {ok, State} = relx:do(undefined, undefined, [], [LibDir1], 3,
- OutputDir, ConfigFile),
+ ApiCallerOverlays = [{profile_string, ProfileString}],
+ {ok, State} = relx:do([{relname, undefined},
+ {relvsn, undefined},
+ {goals, []},
+ {lib_dirs, [LibDir1]},
+ {log_level, 3},
+ {output_dir, OutputDir},
+ {config, ConfigFile},
+ {api_caller_overlays, ApiCallerOverlays}],
+ ["release"]),
[{{foo, "0.0.1"}, Release}] = ec_dictionary:to_list(rlx_state:realized_releases(State)),
AppSpecs = rlx_release:applications(Release),
@@ -902,7 +913,9 @@ overlay_release(Config) ->
%% This should be rendered correctly based on VarsFile2 file, regardless
%% of tpl_var defined in VarsFile1 or not.
?assertEqual("Redefined in vars2 with a template value",
- proplists:get_value(tpl_var, TemplateData)).
+ proplists:get_value(tpl_var, TemplateData)),
+ ?assertEqual(ProfileString,
+ proplists:get_value(profile_string_value, TemplateData)).
make_goalless_release(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
diff --git a/test/rlx_test_utils.erl b/test/rlx_test_utils.erl
index 5328559..dc1e0b0 100644
--- a/test/rlx_test_utils.erl
+++ b/test/rlx_test_utils.erl
@@ -186,7 +186,8 @@ test_template_contents() ->
"{google, \"{{google}}\"}.\n"
"{prop1, \"{{prop1}}\"}.\n"
"{prop2, {{prop2}}}.\n"
- "{tpl_var, \"{{tpl_var}}\"}.\n".
+ "{tpl_var, \"{{tpl_var}}\"}.\n"
+ "{profile_string_value, \"{{profile_string_value}}\"}.\n".
escript_contents() ->
"#!/usr/bin/env escript\n"