fix helper
This commit is contained in:
parent
5c8ec6479b
commit
bdd124376b
@ -35,7 +35,7 @@ check_image_exist(Image) when is_binary(Image) ->
|
||||
create_container(ContainerName, ContainerDir, Config) when is_binary(ContainerName), is_list(ContainerDir), is_map(Config) ->
|
||||
Url = lists:flatten(io_lib:format("/containers/create?name=~s", [binary_to_list(ContainerName)])),
|
||||
%% 挂载预留的目录,用来作为配置文件的存放
|
||||
ConfigFile = list_to_binary(docker_container_helper:get_config_file(ContainerDir)),
|
||||
ConfigFile = list_to_binary(docker_helper:get_config_file(ContainerDir)),
|
||||
|
||||
%% 增加自定义的用来放配置文件的目录
|
||||
Volumes0 = maps:get(<<"volumes">>, Config, []),
|
||||
|
||||
@ -80,7 +80,7 @@ deploy(TaskId, ContainerDir, Config) when is_integer(TaskId), is_list(ContainerD
|
||||
case docker_commands:create_container(ContainerName, ContainerDir, Config) of
|
||||
{ok, ContainerId} ->
|
||||
%% 创建容器对应的配置文件
|
||||
ConfigFile = docker_container_helper:get_config_file(ContainerDir),
|
||||
ConfigFile = docker_helper:get_config_file(ContainerDir),
|
||||
case file:open(ConfigFile, [write, exclusive]) of
|
||||
{ok, FD} ->
|
||||
ok = file:write(FD, <<>>),
|
||||
|
||||
@ -6,14 +6,14 @@
|
||||
%%% @end
|
||||
%%% Created : 17. 9月 2025 14:50
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(docker_container_helper).
|
||||
-module(docker_helper).
|
||||
-author("anlicheng").
|
||||
|
||||
%% API
|
||||
-export([ensure_dir/2, get_dir/2, get_config_file/1]).
|
||||
-export([ensure_container_dir/2, get_container_dir/2, get_config_file/1]).
|
||||
|
||||
-spec ensure_dir(RootDir :: string(), ContainerName :: binary()) -> {ok, ServerRootDir :: string()}.
|
||||
ensure_dir(RootDir, ContainerName) when is_list(RootDir), is_binary(ContainerName) ->
|
||||
-spec ensure_container_dir(RootDir :: string(), ContainerName :: binary()) -> {ok, ServerRootDir :: string()}.
|
||||
ensure_container_dir(RootDir, ContainerName) when is_list(RootDir), is_binary(ContainerName) ->
|
||||
%% 根目录
|
||||
ContainerRootDir = RootDir ++ "/" ++ binary_to_list(ContainerName) ++ "/",
|
||||
ok = filelib:ensure_dir(ContainerRootDir),
|
||||
@ -24,8 +24,8 @@ get_config_file(ContainerDir) when is_list(ContainerDir) ->
|
||||
%% 根目录
|
||||
ContainerDir ++ "service.conf".
|
||||
|
||||
-spec get_dir(RootDir :: string(), ContainerName :: binary()) -> {ok, ServerRootDir :: string()} | error.
|
||||
get_dir(RootDir, ContainerName) when is_list(RootDir), is_binary(ContainerName) ->
|
||||
-spec get_container_dir(RootDir :: string(), ContainerName :: binary()) -> {ok, ServerRootDir :: string()} | error.
|
||||
get_container_dir(RootDir, ContainerName) when is_list(RootDir), is_binary(ContainerName) ->
|
||||
%% 根目录
|
||||
ContainerRootDir = RootDir ++ "/" ++ binary_to_list(ContainerName) ++ "/",
|
||||
case filelib:is_dir(ContainerRootDir) of
|
||||
@ -93,17 +93,17 @@ init([]) ->
|
||||
{stop, Reason :: term(), NewState :: #state{}}).
|
||||
handle_call({deploy, TaskId, Config = #{<<"container_name">> := ContainerName}}, _From, State = #state{root_dir = RootDir, task_map = TaskMap}) ->
|
||||
%% 创建目录
|
||||
{ok, ContainerDir} = docker_container_helper:ensure_dir(RootDir, ContainerName),
|
||||
{ok, ContainerDir} = docker_helper:ensure_container_dir(RootDir, ContainerName),
|
||||
{ok, {TaskPid, _Ref}} = docker_deployer:start_monitor(TaskId, ContainerDir, 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)}};
|
||||
|
||||
%% 处理容器关联的配置文件
|
||||
handle_call({config_container, ContainerName, Config}, _From, State = #state{root_dir = RootDir}) ->
|
||||
case docker_container_helper:get_dir(RootDir, ContainerName) of
|
||||
case docker_helper:get_container_dir(RootDir, ContainerName) of
|
||||
{ok, ContainerDir} ->
|
||||
%% 覆盖容器的配置文件
|
||||
ConfigFile = docker_container_helper:get_config_file(ContainerDir),
|
||||
ConfigFile = docker_helper:get_config_file(ContainerDir),
|
||||
case file:write_file(ConfigFile, Config, [write, binary]) of
|
||||
ok ->
|
||||
lager:warning("[docker_manager] write config file: ~p success", [ConfigFile]),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user