This commit is contained in:
anlicheng 2026-05-07 23:29:20 +08:00
parent 35e2b8d0c9
commit 94739a8a12
2 changed files with 4 additions and 9 deletions

View File

@ -50,7 +50,6 @@ HTTP body 必须是 JSON object。`http_protocol` 会使用 `json:decode/1` 解
"container_name": "my_nginx",
"command": ["nginx", "-g", "daemon off;"],
"restart": "always",
"container_dir": "/data/apps/my_nginx",
"entrypoint": ["/docker-entrypoint.sh"],
"envs": ["ENV=prod", "TZ=Asia/Shanghai"],
"expose": ["80", "443/tcp", "53/udp"],
@ -115,7 +114,6 @@ HTTP body 必须是 JSON object。`http_protocol` 会使用 `json:decode/1` 解
| 字段 | JSON 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `container_dir` | string | `""` | 容器工作目录在 efka 主机上的应用目录,传给 efka 部署逻辑。 |
| `entrypoint` | string[] | `[]` | Docker create config 的 `entrypoint`。 |
| `envs` | string[] | `[]` | 环境变量列表,例如 `["A=1"]`,对应 Docker create config 的 `env`。 |
| `expose` | string[] | `[]` | 容器暴露端口,只表示容器端口,不支持宿主机端口绑定。 |
@ -145,8 +143,9 @@ HTTP body 必须是 JSON object。`http_protocol` 会使用 `json:decode/1` 解
| 字段 | 当前行为 | 说明 |
| --- | --- | --- |
| `ports` | 明确拒绝 | 如果传入会返回 `unsupported container config keys: ports`。当前只支持 `expose`,不支持宿主机端口绑定。 |
| `container_dir` | 明确拒绝 | 容器目录由 efka 按系统默认规则管理HTTP 调用方不能指定 efka 主机上的部署目录。 |
| `env_file` | 忽略 | 当前校验不会识别该字段,后续构造 Docker create options 时也不会使用。 |
| 其他未知字段 | 忽略 | 除 `ports` 外,未知字段不会报错,也不会进入内部部署参数。 |
| 其他未知字段 | 忽略 | 除 `ports` `container_dir` 外,未知字段不会报错,也不会进入内部部署参数。 |
## 5. 校验规则
@ -160,7 +159,7 @@ HTTP body 必须是 JSON object。`http_protocol` 会使用 `json:decode/1` 解
第二层在 `docker_container_builder:deploy_request/2`
- 先拒绝不支持的 `ports` 字段。
- 先拒绝不支持的 `ports` `container_dir` 字段。
- 检查必填字段是否存在。
- 检查已知字段类型。
- 构造内部部署 map。
@ -191,7 +190,6 @@ miss requied parameter: <<"image">>
task_id => TaskId,
params => #{
container_name => ContainerName,
container_dir => ContainerDir,
create => #{
config => ContainerConfig,
host_config => HostConfig,
@ -564,7 +562,6 @@ nano_cpus => 1500000000
task_id => 1001,
params => #{
container_name => <<"my_nginx">>,
container_dir => <<>>,
create => #{
config => #{
image => <<"docker.io/library/nginx:latest">>,

View File

@ -68,7 +68,7 @@ container_ref(ContainerName) when is_binary(ContainerName) ->
-spec ensure_supported_deploy_config(map()) -> ok.
ensure_supported_deploy_config(Config) when is_map(Config) ->
UnsupportedKeys = [Key || Key <- [<<"ports">>], maps:is_key(Key, Config)],
UnsupportedKeys = [Key || Key <- [<<"ports">>, <<"container_dir">>], maps:is_key(Key, Config)],
case UnsupportedKeys of
[] ->
ok;
@ -97,7 +97,6 @@ validate_deploy_config(Config) when is_map(Config) ->
{<<"user">>, binary},
{<<"working_dir">>, binary},
{<<"hostname">>, binary},
{<<"container_dir">>, binary},
{<<"network_mode">>, binary},
{<<"cap_add">>, {list, binary}},
{<<"cap_drop">>, {list, binary}},
@ -210,7 +209,6 @@ check_type(_, _) ->
build_container_deploy_params(Config) when is_map(Config) ->
#{
container_name => maps:get(<<"container_name">>, Config),
container_dir => maps:get(<<"container_dir">>, Config, <<>>),
create => build_docker_create_options(Config)
}.