fix build options
This commit is contained in:
parent
2ec28bfc6e
commit
df1741af8a
@ -217,36 +217,34 @@ gather_output(Port, Acc) ->
|
|||||||
|
|
||||||
%% 构建最终 JSON Map
|
%% 构建最终 JSON Map
|
||||||
build_options(Config) when is_map(Config) ->
|
build_options(Config) when is_map(Config) ->
|
||||||
maps:merge(
|
#{
|
||||||
#{
|
<<"Image">> => maps:get(<<"image">>, Config, <<>>),
|
||||||
<<"Image">> => maps:get(<<"image">>, Config, <<>>),
|
<<"Cmd">> => maps:get(<<"command">>, Config, []),
|
||||||
<<"Cmd">> => maps:get(<<"command">>, Config, []),
|
<<"Entrypoint">> => maps:get(<<"entrypoint">>, Config, []),
|
||||||
<<"Entrypoint">> => maps:get(<<"entrypoint">>, Config, []),
|
<<"Env">> => maps:get(<<"envs">>, Config, []),
|
||||||
<<"Env">> => maps:get(<<"envs">>, Config, []),
|
<<"Labels">> => maps:get(<<"labels">>, Config, #{}),
|
||||||
<<"HostConfig">> => fold_merge([
|
<<"Volumes">> => build_volumes(Config),
|
||||||
build_volumes(Config),
|
<<"User">> => maps:get(<<"user">>, Config, <<>>),
|
||||||
build_restart(Config),
|
<<"WorkingDir">> => maps:get(<<"working_dir">>, Config, <<>>),
|
||||||
build_privileged(Config),
|
<<"Hostname">> => maps:get(<<"hostname">>, Config, <<>>),
|
||||||
build_cap_add_drop(Config),
|
<<"ExposedPorts">> => build_expose(Config),
|
||||||
build_devices(Config),
|
<<"NetworkingConfig">> => build_networks(Config),
|
||||||
build_memory(Config),
|
<<"Healthcheck">> => build_healthcheck(Config),
|
||||||
build_cpu(Config),
|
<<"HostConfig">> => fold_merge([
|
||||||
build_ulimits(Config),
|
build_binds(Config),
|
||||||
build_tmpfs(Config),
|
|
||||||
build_extra_hosts(Config)
|
|
||||||
])
|
|
||||||
},
|
|
||||||
fold_merge([
|
|
||||||
build_expose(Config),
|
|
||||||
build_volumes(Config),
|
build_volumes(Config),
|
||||||
build_networks(Config),
|
build_restart(Config),
|
||||||
build_labels(Config),
|
build_privileged(Config),
|
||||||
build_user(Config),
|
build_cap_add_drop(Config),
|
||||||
build_working_dir(Config),
|
build_devices(Config),
|
||||||
build_hostname(Config),
|
build_memory(Config),
|
||||||
build_healthcheck(Config)
|
build_cpu(Config),
|
||||||
|
build_ulimits(Config),
|
||||||
|
build_tmpfs(Config),
|
||||||
|
build_sysctls(Config),
|
||||||
|
build_extra_hosts(Config)
|
||||||
])
|
])
|
||||||
).
|
}.
|
||||||
|
|
||||||
%% 工具函数
|
%% 工具函数
|
||||||
fold_merge(List) ->
|
fold_merge(List) ->
|
||||||
@ -258,26 +256,28 @@ build_expose(Config) ->
|
|||||||
case Ports of
|
case Ports of
|
||||||
[] -> #{};
|
[] -> #{};
|
||||||
_ ->
|
_ ->
|
||||||
Exposed = maps:from_list([{<<P/binary, "/tcp">>, #{}} || P <- Ports]),
|
maps:from_list([{<<P/binary, "/tcp">>, #{}} || P <- Ports])
|
||||||
#{<<"ExposedPorts">> => Exposed}
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
build_volumes(Config) ->
|
build_volumes(Config) ->
|
||||||
Vols = maps:get(<<"volumes">>, Config, []),
|
Vols = maps:get(<<"volumes">>, Config, []),
|
||||||
case Vols of
|
case Vols of
|
||||||
[] -> #{};
|
[] ->
|
||||||
|
#{};
|
||||||
_ ->
|
_ ->
|
||||||
HostBinds = Vols,
|
maps:from_list(lists:map(fun(V) ->
|
||||||
VolMap = maps:from_list(lists:map(fun(V) ->
|
|
||||||
[_Host, Cont] = binary:split(V, <<":">>, []),
|
[_Host, Cont] = binary:split(V, <<":">>, []),
|
||||||
{Cont, #{}}
|
{Cont, #{}}
|
||||||
end, Vols)),
|
end, Vols))
|
||||||
#{
|
end.
|
||||||
<<"HostConfig">> => #{
|
|
||||||
<<"Binds">> => HostBinds
|
build_binds(Config) ->
|
||||||
},
|
Vols = maps:get(<<"volumes">>, Config, []),
|
||||||
<<"Volumes">> => VolMap
|
case Vols of
|
||||||
}
|
[] ->
|
||||||
|
#{};
|
||||||
|
_ ->
|
||||||
|
#{<<"Binds">> => Vols}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
build_networks(Config) ->
|
build_networks(Config) ->
|
||||||
@ -289,37 +289,6 @@ build_networks(Config) ->
|
|||||||
#{<<"NetworkingConfig">> => #{<<"EndpointsConfig">> => NetCfg}}
|
#{<<"NetworkingConfig">> => #{<<"EndpointsConfig">> => NetCfg}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
build_labels(Config) ->
|
|
||||||
Labels = maps:get(<<"labels">>, Config, #{}),
|
|
||||||
case maps:size(Labels) of
|
|
||||||
0 -> #{};
|
|
||||||
_ -> #{<<"Labels">> => Labels}
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
build_user(Config) ->
|
|
||||||
case maps:get(<<"user">>, Config, undefined) of
|
|
||||||
undefined ->
|
|
||||||
#{};
|
|
||||||
U ->
|
|
||||||
#{<<"User">> => U}
|
|
||||||
end.
|
|
||||||
|
|
||||||
build_working_dir(Config) ->
|
|
||||||
case maps:get(<<"working_dir">>, Config, undefined) of
|
|
||||||
undefined ->
|
|
||||||
#{};
|
|
||||||
D ->
|
|
||||||
#{<<"WorkingDir">> => D}
|
|
||||||
end.
|
|
||||||
|
|
||||||
build_hostname(Config) ->
|
|
||||||
case maps:get(<<"hostname">>, Config, undefined) of
|
|
||||||
undefined ->
|
|
||||||
#{};
|
|
||||||
H ->
|
|
||||||
#{<<"Hostname">> => H}
|
|
||||||
end.
|
|
||||||
|
|
||||||
parse_mem(Val) ->
|
parse_mem(Val) ->
|
||||||
case binary:last(Val) of
|
case binary:last(Val) of
|
||||||
@ -333,20 +302,18 @@ parse_mem(Val) ->
|
|||||||
list_to_integer(binary_to_list(Val))
|
list_to_integer(binary_to_list(Val))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
build_healthcheck(Config) ->
|
build_healthcheck(Config) ->
|
||||||
HC = maps:get(<<"healthcheck">>, Config, #{}),
|
HC = maps:get(<<"healthcheck">>, Config, #{}),
|
||||||
case maps:size(HC) of
|
case maps:size(HC) of
|
||||||
0 -> #{};
|
0 ->
|
||||||
|
#{};
|
||||||
_ ->
|
_ ->
|
||||||
HCMap = #{
|
#{
|
||||||
<<"Test">> => maps:get(<<"test">>, HC, []),
|
<<"Test">> => maps:get(<<"test">>, HC, []),
|
||||||
<<"Interval">> => parse_duration(maps:get(<<"interval">>, HC, <<"0s">>)),
|
<<"Interval">> => parse_duration(maps:get(<<"interval">>, HC, <<"0s">>)),
|
||||||
<<"Timeout">> => parse_duration(maps:get(<<"timeout">>, HC, <<"0s">>)),
|
<<"Timeout">> => parse_duration(maps:get(<<"timeout">>, HC, <<"0s">>)),
|
||||||
<<"Retries">> => maps:get(<<"retries">>, HC, 0)
|
<<"Retries">> => maps:get(<<"retries">>, HC, 0)
|
||||||
},
|
}
|
||||||
#{<<"Healthcheck">> => HCMap}
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
parse_duration(Bin) ->
|
parse_duration(Bin) ->
|
||||||
@ -387,7 +354,7 @@ build_restart(Config) ->
|
|||||||
undefined ->
|
undefined ->
|
||||||
#{};
|
#{};
|
||||||
Policy ->
|
Policy ->
|
||||||
#{<<"RestartPolicy">> => #{<<"Name">> => Policy}}
|
#{<<"RestartPolicy">> => #{<<"Name">> => Policy}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
build_privileged(Config) ->
|
build_privileged(Config) ->
|
||||||
@ -496,5 +463,5 @@ build_extra_hosts(Config) ->
|
|||||||
[] ->
|
[] ->
|
||||||
#{};
|
#{};
|
||||||
_ ->
|
_ ->
|
||||||
#{<<"ExtraHosts">> => Hosts}
|
#{<<"ExtraHosts">> => Hosts}
|
||||||
end.
|
end.
|
||||||
Loading…
x
Reference in New Issue
Block a user