Manage application env from rebar3 profile

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Manage application env from rebar3 profile

Nyirő Gergő
Dear list,

I would like to change some constant during testing e.g.: cycle time
of a periodic job.
It would be ideal to manage it from rebar3 config, but I don't see how
should I edit
the application env variables from rebar3 profiles. Is that even
possible? Should I use
persistent_term instead of application:get_env?

Thanks for your help in advance,
Gergő
Reply | Threaded
Open this post in threaded view
|

Re: Manage application env from rebar3 profile

I Gusti Ngurah Oka Prinarjaya
Hi,

Yes it's possible. 

You can utilise sys.config with configurations content like below:

[
  {YOUR_APP_NAME, [
    {your_env_var1_defined_in_os_in_lowercase, "${YOUR_ENV_VAR1_DEFINED_IN_OS}"},
    {your_env_var2_defined_in_os_in_lowercase, "${YOUR_ENV_VAR2_DEFINED_IN_OS}"},
    {your_env_var3_defined_in_os_in_lowercase, "${YOUR_ENV_VAR3_DEFINED_IN_OS}"},
    .... you can define more here as much as you want
  ]}
].


Then, in order to be able shipping / bring sys.config into your release, you need to treat sys.config as a dynamic configuration source file. 

Follow steps below:
1. create a directory named config at root APP / project directory
2. create file sys.config inside config/ directory
3. the edit your rebar.config as below:

{shell, [
  {sys_config_src, "config/sys.config.src"},
  {apps, [APP_NAME]}
]}.

{relx, [
  {sys_config_src, "config/sys.config.src"},
  {
    release,
    {APP_NAME, "0.1.0"},
  },
  {dev_mode, true},
  {extended_start_script, true}
]}.


For further information you can read here: http://www.rebar3.org/docs/releases#section-dynamic-configuration

Hope it helps.




Pada tanggal Min, 17 Nov 2019 pukul 00.38 Nyirő Gergő <[hidden email]> menulis:
Dear list,

I would like to change some constant during testing e.g.: cycle time
of a periodic job.
It would be ideal to manage it from rebar3 config, but I don't see how
should I edit
the application env variables from rebar3 profiles. Is that even
possible? Should I use
persistent_term instead of application:get_env?

Thanks for your help in advance,
Gergő
Reply | Threaded
Open this post in threaded view
|

Re: Manage application env from rebar3 profile

I Gusti Ngurah Oka Prinarjaya
Hi,

>> Should I use persistent_term instead of application:get_env?
Use application:get_env(YOUR_APP_NAME, your_env_var1_defined_in_os_in_lowercase)

No need to use persistent_term , that's a different thing and not related to consuming-os-env-vars task. Because I assume your needs is consuming OS ENV vars.




Pada tanggal Min, 17 Nov 2019 pukul 01.41 I Gusti Ngurah Oka Prinarjaya <[hidden email]> menulis:
Hi,

Yes it's possible. 

You can utilise sys.config with configurations content like below:

[
  {YOUR_APP_NAME, [
    {your_env_var1_defined_in_os_in_lowercase, "${YOUR_ENV_VAR1_DEFINED_IN_OS}"},
    {your_env_var2_defined_in_os_in_lowercase, "${YOUR_ENV_VAR2_DEFINED_IN_OS}"},
    {your_env_var3_defined_in_os_in_lowercase, "${YOUR_ENV_VAR3_DEFINED_IN_OS}"},
    .... you can define more here as much as you want
  ]}
].


Then, in order to be able shipping / bring sys.config into your release, you need to treat sys.config as a dynamic configuration source file. 

Follow steps below:
1. create a directory named config at root APP / project directory
2. create file sys.config inside config/ directory
3. the edit your rebar.config as below:

{shell, [
  {sys_config_src, "config/sys.config.src"},
  {apps, [APP_NAME]}
]}.

{relx, [
  {sys_config_src, "config/sys.config.src"},
  {
    release,
    {APP_NAME, "0.1.0"},
  },
  {dev_mode, true},
  {extended_start_script, true}
]}.


For further information you can read here: http://www.rebar3.org/docs/releases#section-dynamic-configuration

Hope it helps.




Pada tanggal Min, 17 Nov 2019 pukul 00.38 Nyirő Gergő <[hidden email]> menulis:
Dear list,

I would like to change some constant during testing e.g.: cycle time
of a periodic job.
It would be ideal to manage it from rebar3 config, but I don't see how
should I edit
the application env variables from rebar3 profiles. Is that even
possible? Should I use
persistent_term instead of application:get_env?

Thanks for your help in advance,
Gergő
Reply | Threaded
Open this post in threaded view
|

Re: Manage application env from rebar3 profile

Tristan Sloughter-4
In reply to this post by Nyirő Gergő
If you are using Common Test you can use `ct_opts` to point to different sys.config files for test suites. The sys.config files are loaded before test suites are run:

{ct_opts, [{sys_config, "test/sys.config"}]}.

Then you can always have different profiles with different `ct_opts`pointing to different `sys.config` files.

Tristan

On Sat, Nov 16, 2019, at 10:38, Nyirő Gergő wrote:

> Dear list,
>
> I would like to change some constant during testing e.g.: cycle time
> of a periodic job.
> It would be ideal to manage it from rebar3 config, but I don't see how
> should I edit
> the application env variables from rebar3 profiles. Is that even
> possible? Should I use
> persistent_term instead of application:get_env?
>
> Thanks for your help in advance,
> Gergő
>