Mathias Vonende
Mathias Vonende

Reputation: 1380

How to use OS environment variables in rebar3

I currently have a rebar3 based erlang application, it consists of an erlang backend and a javascript frontend. To combine the frontend and backend build systems I use a makefile. My rebar.config looks like this:

rebar.config:

...
{relx, [{release, {pgserver_dev, "0.1.0"},[pgserver]}
       ]},
       {dev_mode, true},
       {include_erts, false},
       {extended_start_script, true}
]}.

Makefile:

...
release:
    @echo "creating release"
    rebar3 release
    ln -sf _build/$(PROFILE)/rel/$(APP)_dev/bin/$(APP)_dev /.run-$(APP)-$(PROFILE)

I'd like to use environment variables in the rebar.config file to control parameters like e.g. the version -- {pgserver_dev, "0.1.0"} when creating a release. If I specify a variable: VERSION the build could look like this:

rebar.config:

...
{relx, [{release, {pgserver_dev, os:getenv("VERSION")},[pgserver]}
       ]},
       {dev_mode, true},
       {include_erts, false},
       {extended_start_script, true}
]}.

So, is it possible to use linux environment variables in relx/rebar3?

P.S.: It is not possible with os:getenv(), the build fails with:

===> Error reading file rebar.config: 15: bad term

Upvotes: 1

Views: 1987

Answers (1)

2240
2240

Reputation: 1710

You can make a dynamic configuration by using a rebar.config.script. It will give you an Erlang script where you can update or add terms inside the rebar.config. You can search for rebar.config.script on Github to find examples. I found one here.

Upvotes: 1

Related Questions