1

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
Mathias Vonende
  • 1,400
  • 1
  • 18
  • 28
  • 2
    Did you check the [rebar3 dynamic configuration documentation](https://www.rebar3.org/docs/dynamic-configuration)? – Steve Vinoski Sep 10 '16 at 16:12
  • @Steve Vinoski: Thanks Steve, this seems to be exactly what I was looking for. Must have overlooked it in the documentation until now.... – Mathias Vonende Sep 11 '16 at 08:42

1 Answers1

1

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.

2240
  • 1,547
  • 2
  • 12
  • 30