原文链接 https://erlang.mk/guide/relx.html
Chapter 9. Releases
Erlang.mk relies on Relx for generating releases. This chapter covers the Erlang.mk-specific bits. Consult the Relx website for more information.
Erlang.mk依靠Relx来生成发行版。 本章只介绍与Erlang.mk相关的Relx知识。 更多信息请访问Relx网站。
9.1. Setup
9.1. 设置
Erlang.mk will create a release if it detects a Relx configuration file in the $(RELX_CONFIG) location. This defaults to $(CURDIR)/relx.config. You can override it by defining the variable before including Erlang.mk:
如果Erlang.mk检测到 $(RELX_CONFIG) 处的Relx配置文件,它将创建一个发行版。$(RELX_CONFIG) 默认是 $(CURDIR)/relx.config,你可以在包含 Erlang.mk 前通过RELX_CONFIG变量来更改它。
RELX_CONFIG = $(CURDIR)/webchat.config
Relx does not need to be installed. Erlang.mk will download and build it automatically.
Relx不需要安装,Erlang.mk会自动下载并构建它。
The Relx executable will be saved in the $(RELX) file. This location defaults to $(CURDIR)/relx and can be overriden.
Relx执行文件被保存在 $(RELX) ,这个位置默认是 $(CURDIR)/relx,但可以被重写。
9.2. Configuration
9.2. 配置
You can specify additional Relx options using the RELX_OPTS
variable. For example, to enable dev_mode
:
你可以使用 RELX_OPTS 变量来指定其他的Relx选项。例如,要启用 dev_mode:
RELX_OPTS = -d true
While you can specify the output directory for the release in the Relx options directly, Erlang.mk provides a specific variable for it: RELX_OUTPUT_DIR
. It defaults to the _reldirectory. You can also override it:
你可以直接在Relx选项中指定发行版的输出目录,Erlang.mk 为此专门提供了 RELX_OUTPUT_DIR 变量,它的默认值是_reldirectory,你也可以覆盖它。
RELX_OUTPUT_DIR = /path/to/staging/directory
9.3. Generating the release
9.3. 生成发行版
Now that you’re all set, all you need to do is generate the release. As mentioned before, Erlang.mk will automatically generate it when it detects the $(RELX_CONFIG) file. This means the following command will also build the release:
现在所有设置都已完成,你只需要生成版本。就像前面讲的,Erlang.mk会在检测到$(RELX_CONFIG)文件时自动生成,这意味着下面的命令也能构建版本。
$ make
If you need to generate the release, and only the release, the rel
target can be used:
如果你仅仅只需要生成版本,则可以使用 rel
目标。
$ make rel
Erlang.mk always generates a tarball alongside the release, which can be directly uploaded to a server. The tarball is located at $(RELX_OUTPUT_DIR)/<name>/<name>-<vsn>.tar.gz
.
Erlang.mk总是在生成版本时生成一个tarball,以供直接上传到服务器。tarball的路径为$(RELX_OUTPUT_DIR)/<name>/<name>-<vsn>.tar.gz
。
9.4. Running the release
9.4. 运行发行版
Erlang.mk provides a convenience function for running the release with one simple command:
Erlang.mk通过一个简单的命令提供了运行发行版的便捷功能:
$ make run
This command will also build the project and generate the release if they weren’t already. It starts the release in console mode, meaning you will also have a shell ready to use to check things as needed.
如果还没有发行版,那么这个命令会先构建这个项目并生成发行版。这个命令以控制台模式启动版本,这意味着你也可以准备一个shell脚本来作必要的检查。
9.5. Upgrading a release
9.5. 升级发行版
Erlang.mk provides a relup
target for generating release upgrades. Release upgrades allow updating the code and the state of a running release without restarting it.
Erlang.mk为生成发行版的升级提供了一个叫 relup
的标记。这种发行版升级的方式,允许在不重启的情况下更新代码和正在运行的发行版的状态。
Once your changes are done, you need to update the version of the application(s) that will be updated. You also need to update the version of the release.
一旦你的更改完成,你需要更新即将升级的应用程序的版本号,你还需要更新发行版的版本号。
For each application that needs to be updated, an appup file must be written. Refer to the Erlang/OTP documentation for more details.
对于你需要更新的每一个应用程序,都必须写一个 appup文件。更多详细信息,请参阅 Erlang/OTP文档。
For the purpose of this section, assume the initial release version was 1
, and the new version is 2
. The name of the release will be example
.
就本节而言,假设初始版本为1,新版本为2。版本的名字叫 example
。
Once all this is done, you can build the tarball for the release upgrade:
一旦完成了这一切,你就可以构建一个用于版本升级的tarball:
$ make relup
This will create an archive at the root directory of the release, $RELX_OUTPUT_DIR/example/example-2.tar.gz
.
这将在版本的根目录下创建一个存档(压缩文件),$RELX_OUTPUT_DIR/example/example-2.tar.gz
.
Move the archive to the correct location on the running node. From the release’s root directory:
从版本的根目录中,将该存档移动到正在运行的节点上的正确位置。
$ mkdir releases/2/ $ mv path/to/example-2.tar.gz releases/2/
Finally, upgrade the release:
最后,升级版本:
$ bin/example_release upgrade "2/example_release"
Or on Windows:
对于windwos系统:
$ bin/example_release.cmd upgrade "2/example_release"
Your release was upgraded!
你的版本已经升级!
9.6. Getting Relx semver value
9.6. 获取Relx语义化版本值
There is a workaround to get the semver value which is generated by Relx based on VCS history.
有一种变通的方法可以获取由Relx基于VCS历史生成的语义化版本值。
Create a file rel/version with only one line inside:
创建一个里面只有一行内容的文件rel/version:
{{ release_version }}
Add/Update the overlay
section of your relx.config
:
添加或者更新 relx.config
文件中的 overlay
部分:
{overlay, [ {template, "rel/version", "version"} ]}.
When you run make rel
it creates the file $(RELX_OUTPUT_DIR)/example/version which contains the version value generated by Relx.
当你运行 make rel
时,会创建一个文件 $(RELX_OUTPUT_DIR)/example/version,其中包含Relx生成的版本值。
$ cat _rel/app/release 1.0.0+build.11.ref5612aa0
In your Makefile
you can use this simple snippet to get the version, but please keep in mind that this should depend on the rel
target:
在你的 Makefile
中,你可以使用这个简单的代码段来获取版本号,但请记住,这取决于 rel
目标:
$(shell cat $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/version)
For example:
例如:
include erlang.mk APP_VERSION = $(shell cat $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/version) myrecipe: all echo APP_VERSION = $(APP_VERSION)
Would output:
会输出:
$ make myrecipe ... ===> Starting relx build process ... ===> Resolving OTP Applications from directories: /home/username/example/apps /home/username/example/deps /usr/lib/erlang/lib /home/username/example/_rel ===> Resolved example-0.3.10+build.11.ref5612aa0 ===> Including Erts from /usr/lib/erlang ===> release successfully created! ===> tarball /home/username/example/_rel/example/example-0.3.10+build.11.ref5612aa0.tar.gz successfully created! echo APP_VERSION = 0.3.10+build.11.ref5612aa0 APP_VERSION = 0.3.10+build.11.ref5612aa0