fix(relup): inject relup instructions to the end of relup file
This commit is contained in:
parent
9ef760aff9
commit
91c46de4aa
|
@ -129,7 +129,8 @@ prod_overrides() ->
|
|||
[{add, [ {erl_opts, [deterministic]}]}].
|
||||
|
||||
relup_deps(Profile) ->
|
||||
{post_hooks, [{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", compile, "scripts/inject-deps.escript " ++ atom_to_list(Profile)}]}.
|
||||
{post_hooks, [{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", release,
|
||||
"scripts/inject-relup.escript " ++ filename:join(["_build", Profile, "rel", "emqx"])}]}.
|
||||
|
||||
profiles() ->
|
||||
Vsn = get_vsn(),
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/env escript
|
||||
|
||||
%% This script injects implicit relup instructions for emqx applications.
|
||||
|
||||
-mode(compile).
|
||||
|
||||
-define(ERROR(FORMAT, ARGS), io:format(standard_error, "[inject-relup] " ++ FORMAT ++"~n", ARGS)).
|
||||
-define(INFO(FORMAT, ARGS), io:format(user, "[inject-relup] " ++ FORMAT ++"~n", ARGS)).
|
||||
|
||||
usage() ->
|
||||
"Usage: " ++ escript:script_name() ++ " <path-to-release-dir>".
|
||||
|
||||
main([Dir]) ->
|
||||
case filelib:is_dir(Dir) of
|
||||
true ->
|
||||
ok = inject(Dir);
|
||||
false ->
|
||||
?ERROR("not a valid dir: ~p", [Dir]),
|
||||
erlang:halt(1)
|
||||
end;
|
||||
main(_Args) ->
|
||||
?ERROR("~s", [usage()]),
|
||||
erlang:halt(1).
|
||||
|
||||
inject(Dir) ->
|
||||
RelupFiles = filelib:wildcard(filename:join([Dir, "releases", "*", "relup"])),
|
||||
lists:foreach(fun(File) ->
|
||||
case file:consult(File) of
|
||||
{ok, [{CurrRelVsn, UpVsnRUs, DnVsnRUs}]} ->
|
||||
?INFO("injecting instructions to: ~p", [File]),
|
||||
UpdatedContent = [{CurrRelVsn, inject_relup_instrs(CurrRelVsn, UpVsnRUs),
|
||||
inject_relup_instrs(CurrRelVsn, DnVsnRUs)}],
|
||||
file:write_file("/tmp/" ++ filename:basename(File), term_to_text(UpdatedContent));
|
||||
{ok, _BadFormat} ->
|
||||
?ERROR("bad formatted relup file: ~p", [File]);
|
||||
{error, Reason} ->
|
||||
?ERROR("read relup file ~p failed: ~p", [File, Reason])
|
||||
end
|
||||
end, RelupFiles).
|
||||
|
||||
inject_relup_instrs(CurrRelVsn, RUs) ->
|
||||
[{Vsn, Desc, append_emqx_relup_instrs(CurrRelVsn, Vsn, Instrs)} || {Vsn, Desc, Instrs} <- RUs].
|
||||
|
||||
%% The `{apply, emqx_relup, post_release_upgrade, []}` will be appended to the end of
|
||||
%% the instruction lists.
|
||||
append_emqx_relup_instrs(CurrRelVsn, Vsn, Instrs) ->
|
||||
case lists:reverse(Instrs) of
|
||||
[{apply, {emqx_relup, post_release_upgrade, _}} | _] ->
|
||||
Instrs;
|
||||
RInstrs ->
|
||||
lists:reverse([instr_post_release_upgrade(CurrRelVsn, Vsn) | RInstrs])
|
||||
end.
|
||||
|
||||
instr_post_release_upgrade(CurrRelVsn, Vsn) ->
|
||||
{apply, {emqx_relup, post_release_upgrade, [CurrRelVsn, Vsn]}}.
|
||||
|
||||
term_to_text(Term) ->
|
||||
io_lib:format("~p.", [Term]).
|
Loading…
Reference in New Issue