0

我需要你的帮助!我试图在应用程序自动启动之前(通过 Boot Hooks - https://hexdocs.pm/distillery/boot-hooks.html#content)在酒厂版本(Elixir-Application)中运行迁移。开发和生产平台必须是 Windows。

问题:我找不到任何有关 Windows (.bat) 的信息 - 引用该问题的脚本 - 我搜索“pre_start.bat”文件的脚本 - 用于调用 ERTS 节点,最后是我的 Elixir 代码。

我的酒厂配置:rel\config.exs

environment :prod do
  ...
  set pre_start_hook: "rel/hooks/pre_start"
  ...
end

所需的脚本应该调用我的代码“Elixir.MyApp.ReleaseTask.migrate”-Function 我怎样才能实现这个?

以下代码是我到目前为止所得到的..但它不起作用..

@echo off
echo Running migrations
echo.
echo.
echo.
cd %RELEASE_ROOT_DIR%

@set system_erl="<erl_directory>\erts-9.1\bin\erl.exe"
@set erl=%system_erl%
@set system_root_dir_cmd=%system_erl% -noshell -eval "io:format(\"~s\", [filename:nativename(code:root_dir())])." -s init stop
@set rootdir=%system_root%
@set system_erts_vsn_cmd=%system_erl% -noshell -eval "Ver=erlang:system_info(version),io:format(\"~s\", [Ver])" -s init stop
@set erts_vsn=%system_erts_vsn%
@set erts_dir=%rootdir%\erts-%erts_vsn%

@set rel_name="my_api"
@set rel_vsn="1.0"
@set consolidated_dir=%rootdir%\lib\%rel_name%-%rel_vsn%\consolidated

@%erl% -boot_var ERTS_LIB_DIR "%erts_dir%\..\lib" ^
       -hidden -noshell -boot start_clean ^
       -pa "%consolidated_dir%" ^
       -s "Elixir.MyApp.ReleaseTasks" "seed" -s init stop

echo Migrations run successfully

当我对此完全错误时,请纠正我。任何帮助表示赞赏!顺便说一句,它是一个凤凰应用程序。

4

1 回答 1

1

我会选择erlang的本地人escript。要构建它:

1.更新mix.exs,例如添加:

escript: [main_module: MyApp, path: "bin/migrator"]

到函数返回的数组MyApp.Mixfile.project/0并将bin目录添加到版本中:

#         ⇓⇓⇓
files: ~w|bin lib mix.exs README.md|,

到返回的数组MyApp.Mixfile.package/0

2. 创建MyApp.main/1函数:

def main(_args) do
  MyApp.ReleaseTasks.migrate
end

你都准备好了。将在其中发布escriptbin/migrator您在步骤 1 中使用的名称。)

现在你应该可以运行了bin/migrator,因为它是一个普通的旧可执行文件。

旁注: mix compile也会构建这个可执行文件,所以你可以在运行之前使用它并测试它distillery

于 2017-11-09T15:01:35.310 回答