fix
This commit is contained in:
parent
38b46874d3
commit
929a736b17
@ -165,7 +165,23 @@ gather_output(Port, Acc) ->
|
||||
{Status, iolist_to_binary(Acc)}
|
||||
end.
|
||||
|
||||
extract_sha256(Output) when is_binary(Output) ->
|
||||
Parts = binary:split(Output, <<$\n>>, [global]),
|
||||
lager:debug("parts: ~p", [Parts]),
|
||||
case lists:search(fun(Line) -> starts_with(Line, <<"Digest:">>) end, Parts) of
|
||||
{value, Digest} ->
|
||||
Sha256 = lists:last(binary:split(Digest, <<":">>, [global])),
|
||||
{ok, Sha256};
|
||||
false ->
|
||||
error
|
||||
end.
|
||||
|
||||
starts_with(Binary, Prefix) when is_binary(Binary), is_binary(Prefix) ->
|
||||
PrefixSize = byte_size(Prefix),
|
||||
case Binary of
|
||||
<<Prefix:PrefixSize/binary, _Rest/binary>> -> true;
|
||||
_ -> false
|
||||
end.
|
||||
|
||||
%% 构建所有参数
|
||||
build_options(Config) ->
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
-author("anlicheng").
|
||||
|
||||
%% API
|
||||
-export([ensure_dir/2, get_dir/2]).
|
||||
-export([ensure_dir/2, get_dir/2, ensure_etc_dir/1]).
|
||||
|
||||
-spec ensure_dir(RootDir :: string(), ContainerName :: binary()) -> {ok, ServerRootDir :: string()}.
|
||||
ensure_dir(RootDir, ContainerName) when is_list(RootDir), is_binary(ContainerName) ->
|
||||
@ -19,6 +19,13 @@ ensure_dir(RootDir, ContainerName) when is_list(RootDir), is_binary(ContainerNam
|
||||
ok = filelib:ensure_dir(ContainerRootDir),
|
||||
{ok, ContainerRootDir}.
|
||||
|
||||
-spec ensure_etc_dir(ContainerDir :: string()) -> {ok, EtcDir :: string()}.
|
||||
ensure_etc_dir(ContainerDir) when is_list(ContainerDir) ->
|
||||
%% 根目录
|
||||
EtcDir = ContainerDir ++ "etc/",
|
||||
ok = filelib:ensure_dir(EtcDir),
|
||||
{ok, EtcDir}.
|
||||
|
||||
-spec get_dir(RootDir :: string(), ContainerName :: binary()) -> {ok, ServerRootDir :: string()} | error.
|
||||
get_dir(RootDir, ContainerName) when is_list(RootDir), is_binary(ContainerName) ->
|
||||
%% 根目录
|
||||
|
||||
@ -59,8 +59,7 @@ test() ->
|
||||
<<"tmpfs">> => [<<"/tmp">>],
|
||||
<<"extra_hosts">> => [<<"host1:192.168.0.1">>],
|
||||
<<"healthcheck">> => #{
|
||||
%<<"test">> => [<<"CMD-SHELL">>, <<"curl -f http://localhost || exit 1">>],
|
||||
<<"test">> => [<<"CMD">>, <<"ls">>, <<"-l">>],
|
||||
<<"test">> => [<<"CMD-SHELL">>, <<"curl -f http://localhost || exit 1">>],
|
||||
<<"interval">> => <<"30s">>,
|
||||
<<"timeout">> => <<"10s">>,
|
||||
<<"retries">> => 3
|
||||
@ -195,11 +194,11 @@ do_deploy(TaskId, ContainerDir, Config) when is_integer(TaskId), is_list(Contain
|
||||
|
||||
-spec try_pull_image(Image :: binary()) -> ok | {error, Reason :: any()}.
|
||||
try_pull_image(Image) when is_binary(Image) ->
|
||||
case efka_docker_command:check_image_exist(Image) of
|
||||
case docker_commands:check_image_exist(Image) of
|
||||
true ->
|
||||
ok;
|
||||
false ->
|
||||
efka_docker_command:pull_image(Image)
|
||||
docker_commands:pull_image(Image)
|
||||
end.
|
||||
|
||||
maybe_create_env_file(_ContainerDir, []) ->
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(docker_manager).
|
||||
-author("anlicheng").
|
||||
-include("message_pb.hrl").
|
||||
|
||||
-behaviour(gen_server).
|
||||
|
||||
@ -84,7 +83,7 @@ handle_call({deploy, TaskId, Config = #{<<"container_name">> := ContainerName}},
|
||||
{ok, ContainerDir} = docker_container_helper:ensure_dir(RootDir, ContainerName),
|
||||
{ok, TaskPid} = docker_deployer:start_link(TaskId, ContainerDir, Config),
|
||||
docker_deployer:deploy(TaskPid),
|
||||
lager:debug("[efka_inetd] start deploy task_id: ~p, config: ~p", [TaskId, Config]),
|
||||
lager:debug("[docker_manager] start deploy task_id: ~p, config: ~p", [TaskId, Config]),
|
||||
{reply, ok, State#state{task_map = maps:put(TaskPid, TaskId, TaskMap)}};
|
||||
|
||||
%% 处理容器关联的配置文件
|
||||
@ -92,12 +91,14 @@ handle_call({config_container, ContainerName, Config}, _From, State = #state{roo
|
||||
case docker_container_helper:get_dir(RootDir, ContainerName) of
|
||||
{ok, ContainerDir} ->
|
||||
%% 覆盖容器的配置文件
|
||||
ConfigFile = ContainerDir ++ "/etc/config",
|
||||
{ok, EtcDir} = docker_container_helper:ensure_etc_dir(ContainerDir),
|
||||
ConfigFile = EtcDir ++ "config",
|
||||
case file:write_file(ConfigFile, Config, [write, binary]) of
|
||||
ok ->
|
||||
lager:warning("[docker_manager] write config file: ~p success", [ConfigFile]),
|
||||
{reply, ok, State};
|
||||
{error, Reason} ->
|
||||
lager:warning("[docker_manager] write config file get error: ~p", [Reason]),
|
||||
lager:warning("[docker_manager] write config file: ~p, get error: ~p", [ConfigFile, Reason]),
|
||||
{reply, {error, <<"write config failed">>}, State}
|
||||
end;
|
||||
error ->
|
||||
@ -147,11 +148,11 @@ handle_info({'EXIT', TaskPid, Reason}, State = #state{task_map = TaskMap}) ->
|
||||
{TaskId, NTaskMap} ->
|
||||
case Reason of
|
||||
normal ->
|
||||
lager:debug("[efka_inetd] task_pid: ~p, exit normal", [TaskPid]),
|
||||
lager:debug("[docker_manager] task_pid: ~p, exit normal", [TaskPid]),
|
||||
%efka_inetd_task_log:flush(TaskId);
|
||||
ok;
|
||||
Error ->
|
||||
lager:notice("[efka_inetd] task_pid: ~p, exit with error: ~p", [TaskPid, Error]),
|
||||
lager:notice("[docker_manager] task_pid: ~p, exit with error: ~p", [TaskPid, Error]),
|
||||
%efka_inetd_task_log:stash(TaskId, <<"task aborted">>),
|
||||
%efka_inetd_task_log:flush(TaskId)
|
||||
ok
|
||||
|
||||
@ -71,7 +71,7 @@ init([]) ->
|
||||
shutdown => 2000,
|
||||
type => worker,
|
||||
modules => ['docker_manager']
|
||||
}
|
||||
},
|
||||
|
||||
#{
|
||||
id => 'efka_remote_agent',
|
||||
|
||||
@ -163,10 +163,10 @@ handle_info({ssl_error, Socket, Reason}, State = #state{socket = Socket}) ->
|
||||
handle_info({ssl_closed, Socket}, State = #state{socket = Socket}) ->
|
||||
{stop, normal, State};
|
||||
|
||||
%handle_info({timeout, _, ping_ticker}, State = #state{socket = Socket}) ->
|
||||
handle_info({timeout, _, ping_ticker}, State = #state{socket = Socket}) ->
|
||||
%ok = ssl:send(Socket, <<?PACKET_PING>>),
|
||||
% ping_ticker(),
|
||||
% {noreply, State};
|
||||
ping_ticker(),
|
||||
{noreply, State};
|
||||
|
||||
handle_info(Info, State = #state{}) ->
|
||||
lager:notice("[efka_transport] get unknown info: ~p", [Info]),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user