Stuff Goes Bad:Erlang In Anger

OTP Releases

For releases, the structure should be a bit different 4. Releases are collections of applications, and their structures should reflect that.
Instead of having a top-level app, applications should be nested one level deeper and divided into two categories: apps and deps. The apps directory contains your applications’ source code (say, internal business code), and the deps directory contains independently managed dependency applications.

 对于Releases,结构会有一点小小的变化。Releases是applicaitons的集合,他们的结构也应当反映出这种集合特性。
 一个applications应当拆分成apps和deps两类,deps里的依赖项又有自己的子deps的嵌套结构,而不是那些自上而下的app结构(所有依赖项都放在一个deps里面的形式是不可取的), apps文件夹里面包括你自己applicaitons的源文件(内部业务代码),deps文件夹包括独立管理依赖applications。
---------------------------------------------------------------------------------
1 apps/
2 doc/
3 deps/
4 LICENSE.txt
5 README.md
6 rebar.config
---------------------------------------------------------------------------------

This structure lends itself to generating releases. Tools such as Systool and Reltool have been covered before 5, and can allow the user plenty of power. An easier tool that recently appeared is relx 6.
A relx configuration file for the directory structure above would look like:

 这种结构有助于自动生成releases。Systool,Reltool等工具以前都会支持这种结构,用起来非常给力。相对容易上手的还有最近推出的一个简单点的工具:relx6
 relx的配置文件格式如下:
----------------------------------------------------------------------------------
1 {paths, ["apps", "deps"]}.
2 {include_erts, false}. % will use currently installed Erlang
3 {default_release, demo, "1.0.0"}.
4
5 {release, {demo, "1.0.0"},
6 [members,
7 feedstore,
8 ...
9 recon]}.
----------------------------------------------------------------------------------

Calling ./relx (if the executable is in the current directory) will build a release, to be found in the _rel/ directory.
If you really like using rebar, you can build a release as part of the project’s compilation by using a rebar hook in rebar.config:

 你可以调用./relx(在当前文件夹下调用)来创建一个release,就能在 _rel/文件夹来找到这个release.
 如果你更喜欢使用rebar创建release,可以通过rebar.config里面的rebar hook 来把创建release,这装会把构建release工作作为项目编译的一部分。
----------------------------------------------------------------------------------
1 {post_hooks,[{compile, "./relx"}]}.
----------------------------------------------------------------------------------

And every time rebar compile will be called, the release will be generated.

每次运行rebar compile时,都会新建一个release.

[4] I say should because many Erlang developers put their final system under a single top-level application (in src) and a bunch of follower ones as dependencies (in deps), which is less than ideal for distribution purposes and conflicts with assumptions on directory structures made by OTP.
People who do that tend to build from source on the production servers and run custom commands to boot their applications.
[5] http://learnyousomeerlang.com/release-is-the-word
[6] https://github.com/erlware/relx/wiki

[注4]:我说应当(should),是因为大量的Erlang开发者都会把最终的系统放在src做成单一的应用(a single top-level application),而不是在deps使用依赖项,这并不能完美地解决由于OTP文件结构引起的冲突.开发者之所以这样做,是因为他们想从源代码构建产品并使用自定义的命令来驱动(boot)他们的application.
[注5]: http://learnyousomeerlang.com/release-is-the-word
[注6]:https://github.com/erlware/relx/wiki]。