fix docker commands
This commit is contained in:
parent
8c300b12fe
commit
6f4f62150c
@ -95,10 +95,9 @@ build_create_options(#'DockerCreateOptions'{
|
||||
sysctls = Sysctls,
|
||||
extra_hosts = ExtraHosts
|
||||
},
|
||||
networking_config = #'DockerNetworkingConfig'{
|
||||
endpoints = Endpoints
|
||||
}
|
||||
networking_config = NetworkingConfig
|
||||
}) ->
|
||||
Endpoints = networking_config_endpoints(NetworkingConfig),
|
||||
#{
|
||||
<<"Image">> => to_binary(Image),
|
||||
<<"Cmd">> => [to_binary(CommandItem) || CommandItem <- Cmd],
|
||||
@ -127,6 +126,13 @@ build_create_options(#'DockerCreateOptions'{
|
||||
])
|
||||
}.
|
||||
|
||||
-spec networking_config_endpoints(NetworkingConfig :: message_pb:'DockerNetworkingConfig'() | undefined) ->
|
||||
[message_pb:'DockerNetworkEndpoint'()].
|
||||
networking_config_endpoints(undefined) ->
|
||||
[];
|
||||
networking_config_endpoints(#'DockerNetworkingConfig'{endpoints = Endpoints}) ->
|
||||
Endpoints.
|
||||
|
||||
-spec fold_merge(List :: [map()]) -> map().
|
||||
fold_merge(List) ->
|
||||
lists:foldl(fun maps:merge/2, #{}, List).
|
||||
|
||||
@ -86,18 +86,9 @@ test_create_container() ->
|
||||
test_create_container_without_create_options() ->
|
||||
Name = test_container_name(<<"create-default">>),
|
||||
ContainerDir = prepare_container_dir(Name),
|
||||
try
|
||||
ok = test_pull(),
|
||||
{ok, ContainerId} = docker_commands:create_container(ContainerDir, #'ContainerDeployParams'{
|
||||
container_name = Name
|
||||
}),
|
||||
true = is_binary(ContainerId),
|
||||
Inspect = inspect_container_json(Name),
|
||||
assert_patched_defaults(Name, ContainerDir, Inspect),
|
||||
ok
|
||||
after
|
||||
cleanup_container(Name)
|
||||
end.
|
||||
Options = docker_container_builder:build_options(Name, ContainerDir, undefined),
|
||||
assert_patched_default_options(Name, ContainerDir, Options),
|
||||
ok.
|
||||
|
||||
-spec test_create_container_patches_options() -> ok.
|
||||
test_create_container_patches_options() ->
|
||||
@ -305,6 +296,19 @@ assert_patched_defaults(Name, ContainerDir, Inspect)
|
||||
true = lists:member(ExpectedBind, Binds),
|
||||
ok.
|
||||
|
||||
-spec assert_patched_default_options(binary(), string(), map()) -> ok.
|
||||
assert_patched_default_options(Name, ContainerDir, Options)
|
||||
when is_binary(Name), is_list(ContainerDir), is_map(Options) ->
|
||||
ConfigFile = list_to_binary(docker_helper:get_config_file(ContainerDir)),
|
||||
ExpectedBind = <<ConfigFile/binary, ":/usr/local/etc/service.conf">>,
|
||||
#{<<"Env">> := Env,
|
||||
<<"Volumes">> := Volumes,
|
||||
<<"HostConfig">> := #{<<"Binds">> := Binds}} = Options,
|
||||
true = lists:member(<<"CONTAINER_NAME=", Name/binary>>, Env),
|
||||
true = maps:is_key(<<"/usr/local/etc/service.conf">>, Volumes),
|
||||
true = lists:member(ExpectedBind, Binds),
|
||||
ok.
|
||||
|
||||
-spec contains_container(binary(), binary(), [map()]) -> boolean().
|
||||
contains_container(Name, ContainerId, Containers) when is_binary(Name), is_binary(ContainerId), is_list(Containers) ->
|
||||
lists:any(fun(Container) -> container_matches(Name, ContainerId, Container) end, Containers).
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user