fix
This commit is contained in:
parent
2184149976
commit
33227d5613
@ -31,7 +31,11 @@ deploy_request(TaskId, Config) when is_integer(TaskId), is_map(Config), TaskId >
|
||||
catch
|
||||
throw:{error, Reason} ->
|
||||
{error, Reason}
|
||||
end.
|
||||
end;
|
||||
deploy_request(TaskId, _Config) when is_integer(TaskId), TaskId < 0 ->
|
||||
{error, <<"task_id must be non-negative">>};
|
||||
deploy_request(_TaskId, _Config) ->
|
||||
{error, <<"invalid deploy request">>}.
|
||||
|
||||
-spec start_request(binary()) -> map().
|
||||
start_request(ContainerName) when is_binary(ContainerName) ->
|
||||
@ -103,15 +107,15 @@ validate_deploy_config(Config) when is_map(Config) ->
|
||||
{<<"devices">>, {list, binary}},
|
||||
{<<"mem_limit">>, binary},
|
||||
{<<"mem_reservation">>, binary},
|
||||
{<<"cpu_shares">>, integer},
|
||||
{<<"cpus">>, number},
|
||||
{<<"cpu_shares">>, non_neg_integer},
|
||||
{<<"cpus">>, non_neg_number},
|
||||
{<<"ulimits">>, {map, {binary, binary}}},
|
||||
{<<"sysctls">>, {map, {binary, binary}}},
|
||||
{<<"tmpfs">>, {list, binary}},
|
||||
{<<"extra_hosts">>, {list, binary}},
|
||||
{<<"healthcheck">>, {map, {binary, any}}}
|
||||
{<<"healthcheck">>, map}
|
||||
],
|
||||
Errors = check_required(Config, Required) ++ check_optional(Config, Optional),
|
||||
Errors = check_required(Config, Required) ++ check_optional(Config, Optional) ++ check_healthcheck(Config),
|
||||
case Errors of
|
||||
[] ->
|
||||
ok;
|
||||
@ -160,8 +164,14 @@ type_name(binary) ->
|
||||
<<"string">>;
|
||||
type_name(integer) ->
|
||||
<<"integer">>;
|
||||
type_name(non_neg_integer) ->
|
||||
<<"non-negative integer">>;
|
||||
type_name(number) ->
|
||||
<<"number">>;
|
||||
type_name(non_neg_number) ->
|
||||
<<"non-negative number">>;
|
||||
type_name(duration) ->
|
||||
<<"duration string or non-negative integer">>;
|
||||
type_name(list) ->
|
||||
<<"list">>;
|
||||
type_name({list, binary}) ->
|
||||
@ -184,8 +194,14 @@ check_type(Value, binary) ->
|
||||
is_binary(Value);
|
||||
check_type(Value, integer) ->
|
||||
is_integer(Value);
|
||||
check_type(Value, non_neg_integer) ->
|
||||
is_integer(Value) andalso Value >= 0;
|
||||
check_type(Value, number) ->
|
||||
is_number(Value);
|
||||
check_type(Value, non_neg_number) ->
|
||||
is_number(Value) andalso Value >= 0;
|
||||
check_type(Value, duration) ->
|
||||
is_binary(Value) orelse (is_integer(Value) andalso Value >= 0);
|
||||
check_type(Value, list) when is_list(Value) ->
|
||||
true;
|
||||
check_type(Value, {list, binary}) when is_list(Value) ->
|
||||
@ -205,6 +221,25 @@ check_type(Value, boolean) ->
|
||||
check_type(_, _) ->
|
||||
false.
|
||||
|
||||
-spec check_healthcheck(map()) -> [binary()].
|
||||
check_healthcheck(Config) ->
|
||||
case maps:get(<<"healthcheck">>, Config, undefined) of
|
||||
undefined ->
|
||||
[];
|
||||
Healthcheck when is_map(Healthcheck) ->
|
||||
Fields = [
|
||||
{<<"test">>, {list, binary}},
|
||||
{<<"interval">>, duration},
|
||||
{<<"timeout">>, duration},
|
||||
{<<"retries">>, non_neg_integer}
|
||||
],
|
||||
KeyErrors = [<<"optional parameter: <<\"healthcheck\">>, type must be: map of string:any">> ||
|
||||
{Key, _Value} <- maps:to_list(Healthcheck), not is_binary(Key)],
|
||||
KeyErrors ++ check_optional(Healthcheck, Fields);
|
||||
_ ->
|
||||
[]
|
||||
end.
|
||||
|
||||
-spec build_container_deploy_params(map()) -> map().
|
||||
build_container_deploy_params(Config) when is_map(Config) ->
|
||||
#{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user