简体   繁体   English

如何在 rebar3 中使用操作系统环境变量

[英]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.我目前有一个基于 rebar3 的 erlang 应用程序,它由一个 erlang 后端和一个 javascript 前端组成。 To combine the frontend and backend build systems I use a makefile.为了结合前端和后端构建系统,我使用了一个 makefile。 My rebar.config looks like this:我的 rebar.config 看起来像这样:

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 eg the version -- {pgserver_dev, "0.1.0"} when creating a release.我想在rebar.config文件中使用环境变量来控制参数,例如在创建版本时版本 -- {pgserver_dev, "0.1.0"} If I specify a variable: VERSION the build could look like this:如果我指定一个变量: VERSION ,构建可能如下所示:

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?那么,是否可以在 relx/rebar3 中使用 linux 环境变量?

PS: It is not possible with os:getenv() , the build fails with: PS: os:getenv()是不可能的,构建失败:

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

You can make a dynamic configuration by using a rebar.config.script .您可以使用rebar.config.script进行动态配置 It will give you an Erlang script where you can update or add terms inside the rebar.config .它将为您提供一个 Erlang 脚本,您可以在其中更新或添加rebar.config术语。 You can search for rebar.config.script on Github to find examples.您可以在 Github 上搜索rebar.config.script以查找示例。 I found one here .我在这里找到了一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM