|
|
@@ -11,21 +11,43 @@ bcrypt() ->
|
|
|
{bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {branch, "0.6.0"}}}.
|
|
|
|
|
|
deps(Config) ->
|
|
|
- {deps, OldDpes} = lists:keyfind(deps, 1, Config),
|
|
|
+ {deps, OldDeps} = lists:keyfind(deps, 1, Config),
|
|
|
MoreDeps = case provide_bcrypt_dep() of
|
|
|
true -> [bcrypt()];
|
|
|
false -> []
|
|
|
end,
|
|
|
- lists:keystore(deps, 1, Config, {deps, OldDpes ++ MoreDeps}).
|
|
|
+ lists:keystore(deps, 1, Config, {deps, OldDeps ++ MoreDeps ++ extra_deps()}).
|
|
|
+
|
|
|
+extra_deps() ->
|
|
|
+ {ok, Proplist} = file:consult("lib-extra/plugins"),
|
|
|
+ AllPlugins = proplists:get_value(erlang_plugins, Proplist),
|
|
|
+ Filter = string:split(os:getenv("EMQX_EXTRA_PLUGINS", ""), ",", all),
|
|
|
+ filter_extra_deps(AllPlugins, Filter).
|
|
|
+
|
|
|
+filter_extra_deps(AllPlugins, ["all"]) ->
|
|
|
+ AllPlugins;
|
|
|
+filter_extra_deps(AllPlugins, Filter) ->
|
|
|
+ filter_extra_deps(AllPlugins, Filter, []).
|
|
|
+filter_extra_deps([], _, Acc) ->
|
|
|
+ lists:reverse(Acc);
|
|
|
+filter_extra_deps([{Plugin, _}=P|More], Filter, Acc) ->
|
|
|
+ case lists:member(atom_to_list(Plugin), Filter) of
|
|
|
+ true ->
|
|
|
+ filter_extra_deps(More, Filter, [P|Acc]);
|
|
|
+ false ->
|
|
|
+ filter_extra_deps(More, Filter, Acc)
|
|
|
+ end.
|
|
|
|
|
|
overrides() ->
|
|
|
[ {add, [ {extra_src_dirs, [{"etc", [{recursive,true}]}]}
|
|
|
, {erl_opts, [ deterministic
|
|
|
, {compile_info, [{emqx_vsn, get_vsn()}]}
|
|
|
- | [{d, 'EMQX_ENTERPRISE'} || is_enterprise()]
|
|
|
]}
|
|
|
]}
|
|
|
- ].
|
|
|
+ ] ++ community_plugin_overrides().
|
|
|
+
|
|
|
+community_plugin_overrides() ->
|
|
|
+ [{add, App, [ {erl_opts, [{i, "include"}]}]} || App <- relx_plugin_apps_extra()].
|
|
|
|
|
|
config() ->
|
|
|
[ {plugins, plugins()}
|
|
|
@@ -36,14 +58,14 @@ config() ->
|
|
|
is_enterprise() ->
|
|
|
filelib:is_regular("EMQX_ENTERPRISE").
|
|
|
|
|
|
-extra_lib_dir() ->
|
|
|
+alternative_lib_dir() ->
|
|
|
case is_enterprise() of
|
|
|
true -> "lib-ee";
|
|
|
false -> "lib-ce"
|
|
|
end.
|
|
|
|
|
|
project_app_dirs() ->
|
|
|
- ["apps/*", extra_lib_dir() ++ "/*", "."].
|
|
|
+ ["apps/*", alternative_lib_dir() ++ "/*", "."].
|
|
|
|
|
|
plugins() ->
|
|
|
[ {relup_helper,{git,"https://github.com/emqx/relup_helper", {branch,"master"}}},
|
|
|
@@ -80,17 +102,18 @@ test_compile_opts() ->
|
|
|
].
|
|
|
|
|
|
profiles() ->
|
|
|
+ Vsn = get_vsn(),
|
|
|
[ {'emqx', [ {erl_opts, prod_compile_opts()}
|
|
|
- , {relx, relx('emqx')}
|
|
|
+ , {relx, relx(Vsn, cloud, bin)}
|
|
|
]}
|
|
|
, {'emqx-pkg', [ {erl_opts, prod_compile_opts()}
|
|
|
- , {relx, relx('emqx-pkg')}
|
|
|
+ , {relx, relx(Vsn, cloud, pkg)}
|
|
|
]}
|
|
|
, {'emqx-edge', [ {erl_opts, prod_compile_opts()}
|
|
|
- , {relx, relx('emqx-edge')}
|
|
|
+ , {relx, relx(Vsn, edge, bin)}
|
|
|
]}
|
|
|
, {'emqx-edge-pkg', [ {erl_opts, prod_compile_opts()}
|
|
|
- , {relx, relx('emqx-edge-pkg')}
|
|
|
+ , {relx, relx(Vsn, edge, pkg)}
|
|
|
]}
|
|
|
, {check, [ {erl_opts, test_compile_opts()}
|
|
|
]}
|
|
|
@@ -99,41 +122,81 @@ profiles() ->
|
|
|
, {erl_opts, test_compile_opts() ++ erl_opts_i()}
|
|
|
, {extra_src_dirs, [{"test", [{recursive,true}]}]}
|
|
|
]}
|
|
|
- ].
|
|
|
+ ] ++ ee_profiles(Vsn).
|
|
|
|
|
|
-relx(Profile) ->
|
|
|
- Vsn = get_vsn(),
|
|
|
+%% RelType: cloud (full size) | edge (slim size)
|
|
|
+%% PkgType: bin | pkg
|
|
|
+relx(Vsn, RelType, PkgType) ->
|
|
|
+ IsEnterprise = is_enterprise(),
|
|
|
[ {include_src,false}
|
|
|
, {include_erts, true}
|
|
|
, {extended_start_script,false}
|
|
|
, {generate_start_script,false}
|
|
|
, {sys_config,false}
|
|
|
, {vm_args,false}
|
|
|
- ] ++ do_relx(Profile, Vsn).
|
|
|
+ , {release, {emqx, Vsn}, relx_apps(RelType)}
|
|
|
+ , {overlay, relx_overlay(RelType)}
|
|
|
+ , {overlay_vars, [ {built_on_arch, rebar_utils:get_arch()}
|
|
|
+ , {emqx_description, emqx_description(RelType, IsEnterprise)}
|
|
|
+ | overlay_vars(RelType, PkgType, IsEnterprise)]}
|
|
|
+ ].
|
|
|
|
|
|
-do_relx('emqx', Vsn) ->
|
|
|
- [ {release, {emqx, Vsn}, relx_apps(cloud)}
|
|
|
- , {overlay, relx_overlay(cloud)}
|
|
|
- , {overlay_vars, overlay_vars(["vars/vars-cloud.config","vars/vars-bin.config"])}
|
|
|
- ];
|
|
|
-do_relx('emqx-pkg', Vsn) ->
|
|
|
- [ {release, {emqx, Vsn}, relx_apps(cloud)}
|
|
|
- , {overlay, relx_overlay(cloud)}
|
|
|
- , {overlay_vars, overlay_vars(["vars/vars-cloud.config","vars/vars-pkg.config"])}
|
|
|
- ];
|
|
|
-do_relx('emqx-edge', Vsn) ->
|
|
|
- [ {release, {emqx, Vsn}, relx_apps(edge)}
|
|
|
- , {overlay, relx_overlay(edge)}
|
|
|
- , {overlay_vars, overlay_vars(["vars/vars-edge.config","vars/vars-bin.config"])}
|
|
|
- ];
|
|
|
-do_relx('emqx-edge-pkg', Vsn) ->
|
|
|
- [ {release, {emqx, Vsn}, relx_apps(edge)}
|
|
|
- , {overlay, relx_overlay(edge)}
|
|
|
- , {overlay_vars, overlay_vars(["vars/vars-edge.config","vars/vars-pkg.config"])}
|
|
|
+emqx_description(cloud, true) -> "EMQ X Enterprise";
|
|
|
+emqx_description(cloud, false) -> "EMQ X Broker";
|
|
|
+emqx_description(edge, _) -> "EMQ X Edge".
|
|
|
+
|
|
|
+
|
|
|
+overlay_vars(_RelType, PkgType, true) ->
|
|
|
+ ee_overlay_vars(PkgType);
|
|
|
+overlay_vars(RelType, PkgType, false) ->
|
|
|
+ overlay_vars_rel(RelType) ++ overlay_vars_pkg(PkgType).
|
|
|
+
|
|
|
+%% vars per release type, cloud or edge
|
|
|
+overlay_vars_rel(RelType) ->
|
|
|
+ VmArgs = case RelType of
|
|
|
+ cloud -> "vm.args";
|
|
|
+ edge -> "vm.args.edge"
|
|
|
+ end,
|
|
|
+ [ {enable_plugin_emqx_rule_engine, RelType =:= cloud}
|
|
|
+ , {enable_plugin_emqx_bridge_mqtt, RelType =:= edge}
|
|
|
+ , {enable_plugin_emqx_modules, false} %% modules is not a plugin in ce
|
|
|
+ , {enable_plugin_emqx_recon, true}
|
|
|
+ , {enable_plugin_emqx_retainer, true}
|
|
|
+ , {enable_plugin_emqx_telemetry, true}
|
|
|
+ , {vm_args_file, VmArgs}
|
|
|
].
|
|
|
|
|
|
-overlay_vars(Files) ->
|
|
|
- [{built_on_arch, rebar_utils:get_arch()} | Files].
|
|
|
+%% vars per packaging type, bin(zip/tar.gz/docker) or pkg(rpm/deb)
|
|
|
+overlay_vars_pkg(bin) ->
|
|
|
+ [ {platform_bin_dir, "bin"}
|
|
|
+ , {platform_data_dir, "data"}
|
|
|
+ , {platform_etc_dir, "etc"}
|
|
|
+ , {platform_lib_dir, "lib"}
|
|
|
+ , {platform_log_dir, "log"}
|
|
|
+ , {platform_plugins_dir, "plugins"}
|
|
|
+ , {runner_root_dir, "$(cd $(dirname $(readlink $0 || echo $0))/..; pwd -P)"}
|
|
|
+ , {runner_bin_dir, "$RUNNER_ROOT_DIR/bin"}
|
|
|
+ , {runner_etc_dir, "$RUNNER_ROOT_DIR/etc"}
|
|
|
+ , {runner_lib_dir, "$RUNNER_ROOT_DIR/lib"}
|
|
|
+ , {runner_log_dir, "$RUNNER_ROOT_DIR/log"}
|
|
|
+ , {runner_data_dir, "$RUNNER_ROOT_DIR/data"}
|
|
|
+ , {runner_user, ""}
|
|
|
+ ];
|
|
|
+overlay_vars_pkg(pkg) ->
|
|
|
+ [ {platform_bin_dir, ""}
|
|
|
+ , {platform_data_dir, "/var/lib/emqx"}
|
|
|
+ , {platform_etc_dir, "/etc/emqx"}
|
|
|
+ , {platform_lib_dir, ""}
|
|
|
+ , {platform_log_dir, "/var/log/emqx"}
|
|
|
+ , {platform_plugins_dir, "/var/lib/emqx/plugins"}
|
|
|
+ , {runner_root_dir, "/usr/lib/emqx"}
|
|
|
+ , {runner_bin_dir, "/usr/bin"}
|
|
|
+ , {runner_etc_dir, "/etc/emqx"}
|
|
|
+ , {runner_lib_dir, "$RUNNER_ROOT_DIR/lib"}
|
|
|
+ , {runner_log_dir, "/var/log/emqx"}
|
|
|
+ , {runner_data_dir, "/var/lib/emqx"}
|
|
|
+ , {runner_user, "emqx"}
|
|
|
+ ].
|
|
|
|
|
|
relx_apps(ReleaseType) ->
|
|
|
[ kernel
|
|
|
@@ -152,8 +215,9 @@ relx_apps(ReleaseType) ->
|
|
|
, {mnesia, load}
|
|
|
, {ekka, load}
|
|
|
, {emqx_plugin_libs, load}
|
|
|
- , emqx_modules
|
|
|
]
|
|
|
+ ++ [emqx_modules || not is_enterprise()]
|
|
|
+ ++ [emqx_license || is_enterprise()]
|
|
|
++ [bcrypt || provide_bcrypt_release(ReleaseType)]
|
|
|
++ relx_apps_per_rel(ReleaseType)
|
|
|
++ [{N, load} || N <- relx_plugin_apps(ReleaseType)].
|
|
|
@@ -182,11 +246,11 @@ relx_plugin_apps(ReleaseType) ->
|
|
|
, emqx_recon
|
|
|
, emqx_rule_engine
|
|
|
, emqx_sasl
|
|
|
- , emqx_telemetry
|
|
|
- , emqx_modules
|
|
|
]
|
|
|
+ ++ [emqx_telemetry || not is_enterprise()]
|
|
|
++ relx_plugin_apps_per_rel(ReleaseType)
|
|
|
- ++ relx_plugin_apps_enterprise(is_enterprise()).
|
|
|
+ ++ relx_plugin_apps_enterprise(is_enterprise())
|
|
|
+ ++ relx_plugin_apps_extra().
|
|
|
|
|
|
relx_plugin_apps_per_rel(cloud) ->
|
|
|
[ emqx_lwm2m
|
|
|
@@ -208,34 +272,41 @@ relx_plugin_apps_enterprise(true) ->
|
|
|
filelib:is_dir(filename:join(["lib-ee", A]))];
|
|
|
relx_plugin_apps_enterprise(false) -> [].
|
|
|
|
|
|
+relx_plugin_apps_extra() ->
|
|
|
+ [Plugin || {Plugin, _} <- extra_deps()].
|
|
|
+
|
|
|
relx_overlay(ReleaseType) ->
|
|
|
- [ {mkdir,"log/"}
|
|
|
- , {mkdir,"data/"}
|
|
|
- , {mkdir,"data/mnesia"}
|
|
|
- , {mkdir,"data/configs"}
|
|
|
- , {mkdir,"data/scripts"}
|
|
|
+ [ {mkdir, "log/"}
|
|
|
+ , {mkdir, "data/"}
|
|
|
+ , {mkdir, "data/mnesia"}
|
|
|
+ , {mkdir, "data/configs"}
|
|
|
+ , {mkdir, "data/scripts"}
|
|
|
, {template, "data/loaded_plugins.tmpl", "data/loaded_plugins"}
|
|
|
, {template, "data/loaded_modules.tmpl", "data/loaded_modules"}
|
|
|
- , {template,"data/emqx_vars","releases/emqx_vars"}
|
|
|
- , {copy,"bin/emqx","bin/emqx"}
|
|
|
- , {copy,"bin/emqx_ctl","bin/emqx_ctl"}
|
|
|
- , {copy,"bin/install_upgrade.escript", "bin/install_upgrade.escript"}
|
|
|
- , {copy,"bin/emqx","bin/emqx-{{release_version}}"} %% for relup
|
|
|
- , {copy,"bin/emqx_ctl","bin/emqx_ctl-{{release_version}}"} %% for relup
|
|
|
- , {copy,"bin/install_upgrade.escript", "bin/install_upgrade.escript-{{release_version}}"} %% for relup
|
|
|
- , {template,"bin/emqx.cmd","bin/emqx.cmd"}
|
|
|
- , {template,"bin/emqx_ctl.cmd","bin/emqx_ctl.cmd"}
|
|
|
- , {copy,"bin/nodetool","bin/nodetool"}
|
|
|
- , {copy,"bin/nodetool","bin/nodetool-{{release_version}}"}
|
|
|
- , {copy,"_build/default/lib/cuttlefish/cuttlefish","bin/cuttlefish"}
|
|
|
- , {copy,"_build/default/lib/cuttlefish/cuttlefish","bin/cuttlefish-{{release_version}}"}
|
|
|
- , {copy,"priv/emqx.schema","releases/{{release_version}}/"}
|
|
|
- ] ++ etc_overlay(ReleaseType).
|
|
|
+ , {template, "data/emqx_vars", "releases/emqx_vars"}
|
|
|
+ , {copy, "bin/emqx", "bin/emqx"}
|
|
|
+ , {copy, "bin/emqx_ctl", "bin/emqx_ctl"}
|
|
|
+ , {copy, "bin/install_upgrade.escript", "bin/install_upgrade.escript"}
|
|
|
+ , {copy, "bin/emqx", "bin/emqx-{{release_version}}"} %% for relup
|
|
|
+ , {copy, "bin/emqx_ctl", "bin/emqx_ctl-{{release_version}}"} %% for relup
|
|
|
+ , {copy, "bin/install_upgrade.escript", "bin/install_upgrade.escript-{{release_version}}"} %% for relup
|
|
|
+ , {template, "bin/emqx.cmd", "bin/emqx.cmd"}
|
|
|
+ , {template, "bin/emqx_ctl.cmd", "bin/emqx_ctl.cmd"}
|
|
|
+ , {copy, "bin/nodetool", "bin/nodetool"}
|
|
|
+ , {copy, "bin/nodetool", "bin/nodetool-{{release_version}}"}
|
|
|
+ , {copy, "_build/default/lib/cuttlefish/cuttlefish", "bin/cuttlefish"}
|
|
|
+ , {copy, "_build/default/lib/cuttlefish/cuttlefish", "bin/cuttlefish-{{release_version}}"}
|
|
|
+ , {copy, "priv/emqx.schema", "releases/{{release_version}}/"}
|
|
|
+ ] ++ case is_enterprise() of
|
|
|
+ true -> ee_etc_overlay(ReleaseType);
|
|
|
+ false -> etc_overlay(ReleaseType)
|
|
|
+ end.
|
|
|
|
|
|
etc_overlay(ReleaseType) ->
|
|
|
PluginApps = relx_plugin_apps(ReleaseType),
|
|
|
Templates = emqx_etc_overlay(ReleaseType) ++
|
|
|
- lists:append([plugin_etc_overlays(App) || App <- PluginApps]),
|
|
|
+ lists:append([plugin_etc_overlays(App) || App <- PluginApps]) ++
|
|
|
+ [community_plugin_etc_overlays(App) || App <- relx_plugin_apps_extra()],
|
|
|
[ {mkdir, "etc/"}
|
|
|
, {mkdir, "etc/plugins"}
|
|
|
, {template, "etc/BUILT_ON", "releases/{{release_version}}/BUILT_ON"}
|
|
|
@@ -275,11 +346,15 @@ plugin_etc_overlays(App0) ->
|
|
|
[{"{{base_dir}}/lib/"++ App ++"/etc/" ++ F, "etc/plugins/" ++ F}
|
|
|
|| F <- ConfFiles].
|
|
|
|
|
|
+community_plugin_etc_overlays(App0) ->
|
|
|
+ App = atom_to_list(App0),
|
|
|
+ {"{{base_dir}}/lib/"++ App ++"/etc/" ++ App ++ ".conf", "etc/plugins/" ++ App ++ ".conf"}.
|
|
|
+
|
|
|
%% NOTE: for apps fetched as rebar dependency (there is so far no such an app)
|
|
|
%% the overlay should be hand-coded but not to rely on build-time wildcards.
|
|
|
find_conf_files(App) ->
|
|
|
Dir1 = filename:join(["apps", App, "etc"]),
|
|
|
- Dir2 = filename:join([extra_lib_dir(), App, "etc"]),
|
|
|
+ Dir2 = filename:join([alternative_lib_dir(), App, "etc"]),
|
|
|
filelib:wildcard("*.conf", Dir1) ++ filelib:wildcard("*.conf", Dir2).
|
|
|
|
|
|
env(Name, Default) ->
|
|
|
@@ -294,8 +369,7 @@ get_vsn() ->
|
|
|
false -> os:cmd("./pkg-vsn.sh");
|
|
|
Vsn -> Vsn
|
|
|
end,
|
|
|
- Vsn2 = re:replace(PkgVsn, "v", "", [{return ,list}]),
|
|
|
- re:replace(Vsn2, "\n", "", [{return ,list}]).
|
|
|
+ re:replace(PkgVsn, "\n", "", [{return ,list}]).
|
|
|
|
|
|
maybe_dump(Config) ->
|
|
|
is_debug() andalso file:write_file("rebar.config.rendered", [io_lib:format("~p.\n", [I]) || I <- Config]),
|
|
|
@@ -322,7 +396,7 @@ provide_bcrypt_release(ReleaseType) ->
|
|
|
erl_opts_i() ->
|
|
|
[{i, "apps"}] ++
|
|
|
[{i, Dir} || Dir <- filelib:wildcard(filename:join(["apps", "*", "include"]))] ++
|
|
|
- [{i, Dir} || Dir <- filelib:wildcard(filename:join([extra_lib_dir(), "*", "include"]))].
|
|
|
+ [{i, Dir} || Dir <- filelib:wildcard(filename:join([alternative_lib_dir(), "*", "include"]))].
|
|
|
|
|
|
dialyzer(Config) ->
|
|
|
{dialyzer, OldDialyzerConfig} = lists:keyfind(dialyzer, 1, Config),
|
|
|
@@ -334,7 +408,7 @@ dialyzer(Config) ->
|
|
|
[ list_to_atom(App) || App <- string:tokens(Value, ",")]
|
|
|
end,
|
|
|
|
|
|
- AppNames = [emqx | list_dir("apps")] ++ list_dir(extra_lib_dir()),
|
|
|
+ AppNames = [emqx | list_dir("apps")] ++ list_dir(alternative_lib_dir()),
|
|
|
|
|
|
KnownApps = [Name || Name <- AppsToAnalyse, lists:member(Name, AppNames)],
|
|
|
|
|
|
@@ -370,3 +444,9 @@ coveralls() ->
|
|
|
list_dir(Dir) ->
|
|
|
{ok, Names} = file:list_dir(Dir),
|
|
|
[list_to_atom(Name) || Name <- Names, filelib:is_dir(filename:join([Dir, Name]))].
|
|
|
+
|
|
|
+%% ==== Enterprise supports below ==================================================================
|
|
|
+
|
|
|
+ee_profiles(_Vsn) -> [].
|
|
|
+ee_etc_overlay(_) -> [].
|
|
|
+ee_overlay_vars(_PkgType) -> [].
|