36 lines
1.3 KiB
Erlang
36 lines
1.3 KiB
Erlang
%%%-------------------------------------------------------------------
|
|
%%% @author anlicheng
|
|
%%% @copyright (C) 2025, <COMPANY>
|
|
%%% @doc
|
|
%%%
|
|
%%% @end
|
|
%%% Created : 17. 9月 2025 14:50
|
|
%%%-------------------------------------------------------------------
|
|
-module(docker_container_helper).
|
|
-author("anlicheng").
|
|
|
|
%% API
|
|
-export([ensure_dir/2, get_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) ->
|
|
%% 根目录
|
|
ContainerRootDir = RootDir ++ "/" ++ binary_to_list(ContainerName) ++ "/",
|
|
ok = filelib:ensure_dir(ContainerRootDir),
|
|
{ok, ContainerRootDir}.
|
|
|
|
-spec get_config_file(ContainerDir :: string()) -> ConfigFile :: string().
|
|
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) ->
|
|
%% 根目录
|
|
ContainerRootDir = RootDir ++ "/" ++ binary_to_list(ContainerName) ++ "/",
|
|
case filelib:is_dir(ContainerRootDir) of
|
|
true ->
|
|
{ok, ContainerRootDir};
|
|
false ->
|
|
error
|
|
end. |