Merge branch 'terrencehan-fix_upgrade_error'

This commit is contained in:
Fred Hebert 2014-11-21 10:11:53 -05:00
commit 899d60cdb0
3 changed files with 52 additions and 14 deletions

View file

@ -35,6 +35,7 @@
get_rel_apps/2, get_rel_apps/2,
get_previous_release_path/1, get_previous_release_path/1,
get_rel_file_path/2, get_rel_file_path/2,
get_rel_file_path/3,
load_config/2, load_config/2,
get_sys_tuple/1, get_sys_tuple/1,
get_excl_lib_tuple/1, get_excl_lib_tuple/1,
@ -106,9 +107,18 @@ get_rel_apps(Name, Path) ->
%% Get rel file path from name and path %% Get rel file path from name and path
get_rel_file_path(Name, Path) -> get_rel_file_path(Name, Path) ->
[RelFile] = filelib:wildcard(filename:join([Path, "releases", "*", PVer = get_permanent_version(Path),
Name ++ ".rel"])), get_rel_file_path(Name, Path, PVer).
RelFile.
get_rel_file_path(Name, Path, Version) ->
Dir = filename:join([Path, "releases", Version]),
Path1 = filename:join([Dir, Name ++ "_" ++ Version ++".rel"]),
Path2 = filename:join([Dir, Name ++ ".rel"]),
case {filelib:is_file(Path1), filelib:is_file(Path2)} of
{true, _} -> Path1;
{_, true} -> Path2;
_ -> ?ABORT("can not find .rel file for version ~p~n", [Version])
end.
%% Get the previous release path from a global variable %% Get the previous release path from a global variable
get_previous_release_path(Config) -> get_previous_release_path(Config) ->
@ -128,7 +138,7 @@ load_config(Config, ReltoolFile) ->
{ok, Terms} -> {ok, Terms} ->
expand_version(Config, Terms, filename:dirname(ReltoolFile)); expand_version(Config, Terms, filename:dirname(ReltoolFile));
Other -> Other ->
?ABORT("Failed to load expected config from ~s: ~p\n", ?ABORT("Failed to load expected config from ~s: ~p~n",
[ReltoolFile, Other]) [ReltoolFile, Other])
end. end.
@ -141,7 +151,7 @@ get_sys_tuple(ReltoolConfig) ->
{sys, _} = SysTuple -> {sys, _} = SysTuple ->
SysTuple; SysTuple;
false -> false ->
?ABORT("Failed to find {sys, [...]} tuple in reltool.config.", []) ?ABORT("Failed to find {sys, [...]} tuple in reltool.config~n", [])
end. end.
%% %%
@ -244,3 +254,16 @@ expand_rel_version(Config, {rel, Name, Version, Apps}, Dir) ->
{NewConfig, {rel, Name, VsnString, Apps}}; {NewConfig, {rel, Name, VsnString, Apps}};
expand_rel_version(Config, Other, _Dir) -> expand_rel_version(Config, Other, _Dir) ->
{Config, Other}. {Config, Other}.
%% get permanent version from start_erl.data
get_permanent_version(Path) ->
DataFile = filename:join([Path, "releases", "start_erl.data"]),
case file:read_file(DataFile) of
{ok, DataBin} ->
[_, Version] = string:tokens(
string:strip(binary_to_list(DataBin), right, $\n),
" "),
Version;
{error, enoent} ->
?ABORT("~s is missing~n", [DataFile])
end.

View file

@ -52,9 +52,10 @@
OldVerPath = filename:join([TargetParentDir, PrevRelPath]), OldVerPath = filename:join([TargetParentDir, PrevRelPath]),
%% Run checks to make sure that building a package is possible %% Run checks to make sure that building a package is possible
{NewVerPath, NewName, NewVer} = run_checks(Config, OldVerPath, {NewVerPath, NewName, NewVer, OldVer} = run_checks(Config, OldVerPath,
ReltoolConfig), ReltoolConfig),
NameVer = NewName ++ "_" ++ NewVer, NameVer = NewName ++ "_" ++ NewVer,
OldRelName = get_old_rel_name(OldVerPath, OldVer, NewName),
%% Save the code path prior to doing anything %% Save the code path prior to doing anything
OrigPath = code:get_path(), OrigPath = code:get_path(),
@ -63,7 +64,7 @@
ok = setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer), ok = setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer),
%% Build the package %% Build the package
run_systools(NameVer, NewName), run_systools(NameVer, OldRelName),
%% Boot file changes %% Boot file changes
{ok, _} = boot_files(TargetDir, NewVer, NewName), {ok, _} = boot_files(TargetDir, NewVer, NewName),
@ -122,7 +123,7 @@ run_checks(Config, OldVerPath, ReltoolConfig) ->
rebar_utils:prop_check(Ver == NewVer, rebar_utils:prop_check(Ver == NewVer,
"Reltool and .rel versions do not match~n", []), "Reltool and .rel versions do not match~n", []),
{NewVerPath, NewName, NewVer}. {NewVerPath, NewName, NewVer, OldVer}.
setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer) -> setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer) ->
Src = filename:join([NewVerPath, "releases", Src = filename:join([NewVerPath, "releases",
@ -139,9 +140,9 @@ setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer) ->
"lib", "*", "ebin"])) "lib", "*", "ebin"]))
])). ])).
run_systools(NewVer, Name) -> run_systools(NewVer, OldRelName) ->
Opts = [silent], Opts = [silent],
NameList = [Name], NameList = [OldRelName],
case systools:make_relup(NewVer, NameList, NameList, Opts) of case systools:make_relup(NewVer, NameList, NameList, Opts) of
{error, _, Msg} -> {error, _, Msg} ->
?ABORT("Systools [systools:make_relup/4] aborted with: ~p~n", ?ABORT("Systools [systools:make_relup/4] aborted with: ~p~n",
@ -264,3 +265,7 @@ file_info(Path) ->
Error -> Error ->
Error Error
end. end.
get_old_rel_name(OldVerPath, OldVer, Name) ->
OldRelFile = rebar_rel_utils:get_rel_file_path(Name, OldVerPath, OldVer),
filename:basename(OldRelFile, ".rel").

View file

@ -1,7 +1,9 @@
#### Building version 0.1 #### Building version 0.1
rebar compile rebar compile
cd rel
rebar generate rebar generate
mv rel/dummy rel/dummy_0.1 mv dummy dummy_0.1
cd ..
rebar clean rebar clean
# start the release: # start the release:
cd rel/dummy_0.1 cd rel/dummy_0.1
@ -20,15 +22,17 @@
$EDITOR rel/reltool.config $EDITOR rel/reltool.config
rebar compile rebar compile
cd rel
rebar generate rebar generate
# previous_release path is relative to your rel directory # previous_release path is relative to your rel directory
rebar generate-appups previous_release=dummy_0.1 rebar generate-appups previous_release=dummy_0.1
rebar generate-upgrade previous_release=dummy_0.1 rebar generate-upgrade previous_release=dummy_0.1
tar -zvtf rel/dummy_0.2.tar.gz tar -zvtf dummy_0.2.tar.gz
mv dummy dummy_0.2
#### Deploying with release_handler #### Deploying with release_handler
mv rel/dummy_0.2.tar.gz rel/dummy_0.1/releases/ mv dummy_0.2.tar.gz dummy_0.1/releases/
# Now use release_handler in the running erlang console for the deploy: # Now use release_handler in the running erlang console for the deploy:
@ -38,3 +42,9 @@
erl> release_handler:which_releases(). erl> release_handler:which_releases().
erl> dummy_server:get_state(). erl> dummy_server:get_state().
#### Building version 0.3
rm -r rel/dummy
# Now repeat steps in 'Building version 0.2' and 'Deploying with release_handler'
# while replacing '0.2' by '0.3' and '0.1' by '0.2'.