fix deployer
This commit is contained in:
parent
43e02a5f16
commit
6622a74cb4
@ -12,7 +12,7 @@
|
|||||||
-dialyzer([{nowarn_function, normalize_image/1}]).
|
-dialyzer([{nowarn_function, normalize_image/1}]).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_monitor/3]).
|
-export([start_link/3]).
|
||||||
-export([deploy/3]).
|
-export([deploy/3]).
|
||||||
|
|
||||||
-define(TASK_SUCCESS, <<"success">>).
|
-define(TASK_SUCCESS, <<"success">>).
|
||||||
@ -22,12 +22,12 @@
|
|||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
%% @doc Spawns the server and registers the local name (unique)
|
-spec(start_link(TaskId :: integer(), ContainerDir :: string(), Params :: message_pb:'ContainerDeployParams'()) ->
|
||||||
-spec(start_monitor(TaskId :: integer(), ContainerDir :: string(), Params :: message_pb:'ContainerDeployParams'()) ->
|
{ok, pid()}).
|
||||||
{ok, {Pid :: pid(), MRef :: reference()}}).
|
start_link(TaskId, ContainerDir, Params)
|
||||||
start_monitor(TaskId, ContainerDir, Params)
|
|
||||||
when is_integer(TaskId), is_list(ContainerDir), is_record(Params, 'ContainerDeployParams') ->
|
when is_integer(TaskId), is_list(ContainerDir), is_record(Params, 'ContainerDeployParams') ->
|
||||||
{ok, spawn_monitor(?MODULE, deploy, [TaskId, ContainerDir, Params])}.
|
Pid = spawn_link(?MODULE, deploy, [TaskId, ContainerDir, Params]),
|
||||||
|
{ok, Pid}.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
|
|||||||
57
src/docker/docker_deployer_sup.erl
Normal file
57
src/docker/docker_deployer_sup.erl
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @author anlicheng
|
||||||
|
%%% @copyright (C) 2026, <COMPANY>
|
||||||
|
%%% @doc
|
||||||
|
%%%
|
||||||
|
%%% @end
|
||||||
|
%%% Created : 20. 4月 2026
|
||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
-module(docker_deployer_sup).
|
||||||
|
-author("anlicheng").
|
||||||
|
-include("message_pb.hrl").
|
||||||
|
|
||||||
|
-behaviour(supervisor).
|
||||||
|
|
||||||
|
%% API
|
||||||
|
-export([start_link/0, start_deployer/3]).
|
||||||
|
|
||||||
|
%% Supervisor callbacks
|
||||||
|
-export([init/1]).
|
||||||
|
|
||||||
|
-define(SERVER, ?MODULE).
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% API
|
||||||
|
%%%===================================================================
|
||||||
|
|
||||||
|
-spec start_link() -> {ok, pid()} | ignore | {error, term()}.
|
||||||
|
start_link() ->
|
||||||
|
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
|
||||||
|
|
||||||
|
-spec start_deployer(integer(), string(), message_pb:'ContainerDeployParams'()) ->
|
||||||
|
{ok, pid()} | {error, term()}.
|
||||||
|
start_deployer(TaskId, ContainerDir, Params)
|
||||||
|
when is_integer(TaskId), is_list(ContainerDir), is_record(Params, 'ContainerDeployParams') ->
|
||||||
|
supervisor:start_child(?SERVER, child_spec(TaskId, ContainerDir, Params)).
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% Supervisor callbacks
|
||||||
|
%%%===================================================================
|
||||||
|
|
||||||
|
init([]) ->
|
||||||
|
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
|
||||||
|
{ok, {SupFlags, []}}.
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% Internal functions
|
||||||
|
%%%===================================================================
|
||||||
|
|
||||||
|
child_spec(TaskId, ContainerDir, Params) ->
|
||||||
|
#{
|
||||||
|
id => make_ref(),
|
||||||
|
start => {docker_deployer, start_link, [TaskId, ContainerDir, Params]},
|
||||||
|
restart => temporary,
|
||||||
|
shutdown => 5000,
|
||||||
|
type => worker,
|
||||||
|
modules => [docker_deployer]
|
||||||
|
}.
|
||||||
@ -73,7 +73,8 @@ handle_call({deploy, TaskId, Params = #'ContainerDeployParams'{
|
|||||||
}}, _From, State = #state{root_dir = RootDir, task_map = TaskMap}) ->
|
}}, _From, State = #state{root_dir = RootDir, task_map = TaskMap}) ->
|
||||||
%% 创建目录
|
%% 创建目录
|
||||||
{ok, ContainerDir} = docker_helper:ensure_container_dir(RootDir, ContainerName, ContainerDir0),
|
{ok, ContainerDir} = docker_helper:ensure_container_dir(RootDir, ContainerName, ContainerDir0),
|
||||||
{ok, {TaskPid, _Ref}} = docker_deployer:start_monitor(TaskId, ContainerDir, Params),
|
{ok, TaskPid} = docker_deployer_sup:start_deployer(TaskId, ContainerDir, Params),
|
||||||
|
_Ref = erlang:monitor(process, TaskPid),
|
||||||
logger:debug("[docker_manager] start deploy task_id: ~p, params: ~p", [TaskId, Params]),
|
logger:debug("[docker_manager] start deploy task_id: ~p, params: ~p", [TaskId, Params]),
|
||||||
{reply, ok, State#state{task_map = maps:put(TaskPid, TaskId, TaskMap)}};
|
{reply, ok, State#state{task_map = maps:put(TaskPid, TaskId, TaskMap)}};
|
||||||
|
|
||||||
|
|||||||
@ -100,6 +100,15 @@ init([]) ->
|
|||||||
modules => ['efka_task_reporter']
|
modules => ['efka_task_reporter']
|
||||||
},
|
},
|
||||||
|
|
||||||
|
#{
|
||||||
|
id => 'docker_deployer_sup',
|
||||||
|
start => {'docker_deployer_sup', start_link, []},
|
||||||
|
restart => permanent,
|
||||||
|
shutdown => 2000,
|
||||||
|
type => supervisor,
|
||||||
|
modules => ['docker_deployer_sup']
|
||||||
|
},
|
||||||
|
|
||||||
#{
|
#{
|
||||||
id => 'docker_manager',
|
id => 'docker_manager',
|
||||||
start => {'docker_manager', start_link, []},
|
start => {'docker_manager', start_link, []},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user