feat(backend): build identity в health, VERSION bake и auto stage по sha-*
CI / test (push) Successful in 28m3s
CI / test (push) Successful in 28m3s
This commit is contained in:
@@ -119,6 +119,7 @@ start_admin_http() ->
|
||||
{'_', [
|
||||
% ================== БАЗОВЫЕ ==================
|
||||
{"/admin/health", admin_handler_health, []},
|
||||
{"/v1/admin/health", admin_handler_health, []},
|
||||
{"/v1/admin/stats", admin_handler_stats, []},
|
||||
{"/v1/admin/nodes/metrics", admin_handler_node_metrics, []},
|
||||
{"/v1/admin/login", admin_handler_login, []},
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
init(Req, _State) ->
|
||||
case cowboy_req:method(Req) of
|
||||
<<"GET">> ->
|
||||
handler_utils:send_json(Req, 200, #{status => <<"ok">>});
|
||||
handler_utils:send_json(Req, 200, eventhub_build_info:info());
|
||||
_ ->
|
||||
handler_utils:send_error(Req, 405, <<"Method not allowed">>)
|
||||
end.
|
||||
@@ -19,7 +19,7 @@ trails() ->
|
||||
#{
|
||||
path => <<"/admin/health">>,
|
||||
method => <<"GET">>,
|
||||
description => <<"Admin API health check">>,
|
||||
description => <<"Admin API health check with build identity">>,
|
||||
tags => [<<"Health">>],
|
||||
responses => #{
|
||||
200 => #{
|
||||
@@ -27,10 +27,14 @@ trails() ->
|
||||
content => #{<<"application/json">> => #{schema => #{
|
||||
type => object,
|
||||
properties => #{
|
||||
status => #{type => string}
|
||||
status => #{type => string},
|
||||
service => #{type => string},
|
||||
version => #{type => string},
|
||||
git_sha => #{type => string},
|
||||
built_at => #{type => string}
|
||||
}
|
||||
}}}
|
||||
}
|
||||
}
|
||||
}
|
||||
].
|
||||
].
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @doc Обработчик проверки здоровья клиентского API.
|
||||
%%% GET – возвращает статус сервера.
|
||||
%%% GET – возвращает статус сервера и build identity.
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(handler_health).
|
||||
@@ -21,7 +21,7 @@ trails() ->
|
||||
#{
|
||||
path => <<"/health">>,
|
||||
method => <<"GET">>,
|
||||
description => <<"API health check">>,
|
||||
description => <<"API health check with build identity">>,
|
||||
tags => [<<"Health">>],
|
||||
responses => #{
|
||||
200 => #{
|
||||
@@ -29,7 +29,11 @@ trails() ->
|
||||
content => #{<<"application/json">> => #{schema => #{
|
||||
type => object,
|
||||
properties => #{
|
||||
status => #{type => string}
|
||||
status => #{type => string},
|
||||
service => #{type => string},
|
||||
version => #{type => string},
|
||||
git_sha => #{type => string},
|
||||
built_at => #{type => string}
|
||||
}
|
||||
}}}
|
||||
}
|
||||
@@ -46,7 +50,7 @@ trails() ->
|
||||
handle(Req, _Opts) ->
|
||||
case cowboy_req:method(Req) of
|
||||
<<"GET">> ->
|
||||
handler_utils:send_json(Req, 200, #{status => <<"ok">>});
|
||||
handler_utils:send_json(Req, 200, eventhub_build_info:info());
|
||||
_ ->
|
||||
handler_utils:send_error(Req, 405, <<"Method not allowed">>)
|
||||
end.
|
||||
end.
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
-module(eventhub_build_info).
|
||||
-export([info/0, version/0, git_sha/0, built_at/0]).
|
||||
|
||||
%% @doc Runtime build identity from env (baked at image build or set in compose).
|
||||
-spec info() -> map().
|
||||
info() ->
|
||||
#{
|
||||
status => <<"ok">>,
|
||||
service => <<"eventhub">>,
|
||||
version => version(),
|
||||
git_sha => git_sha(),
|
||||
built_at => built_at()
|
||||
}.
|
||||
|
||||
-spec version() -> binary().
|
||||
version() -> env("EVENTHUB_VERSION", <<"0.0">>).
|
||||
|
||||
-spec git_sha() -> binary().
|
||||
git_sha() -> env("EVENTHUB_GIT_SHA", <<"unknown">>).
|
||||
|
||||
-spec built_at() -> binary().
|
||||
built_at() -> env("EVENTHUB_BUILT_AT", <<"">>).
|
||||
|
||||
env(Name, Default) ->
|
||||
case os:getenv(Name) of
|
||||
false -> Default;
|
||||
[] -> Default;
|
||||
Value -> unicode:characters_to_binary(Value)
|
||||
end.
|
||||
Reference in New Issue
Block a user