mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
opt docker
This commit is contained in:
parent
fdaa2538d8
commit
cf731a58e3
@ -157,6 +157,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
"web_port": ":9095",
|
||||
"ssh_port": ":9090",
|
||||
"username": "shy",
|
||||
"version": "2.1",
|
||||
},
|
||||
}, Help: "运行环境, host, init, boot, node, user, work"},
|
||||
"system": {Name: "system", Value: map[string]interface{}{
|
||||
|
@ -38,6 +38,16 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"vim": []interface{}{"cli.system", "vim"},
|
||||
}},
|
||||
"package": {Name: "package", Help: "软件包", Value: map[string]interface{}{
|
||||
"apk": map[string]interface{}{"update": "update", "install": "add",
|
||||
"base": []interface{}{"curl", "bash"},
|
||||
},
|
||||
"apt": map[string]interface{}{"update": "update", "install": "install -y",
|
||||
"base": []interface{}{"wget", "curl"},
|
||||
},
|
||||
"yum": map[string]interface{}{"update": "update -y", "install": "install",
|
||||
"base": []interface{}{"wget"},
|
||||
},
|
||||
|
||||
"udpate": []interface{}{"apk", "update"},
|
||||
"install": []interface{}{"apk", "add"},
|
||||
"build": []interface{}{"build-base"},
|
||||
@ -45,7 +55,8 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"product": []interface{}{"nginx", "redis", "mysql"},
|
||||
}},
|
||||
"docker": {Name: "docker", Help: "容器", Value: map[string]interface{}{
|
||||
"shy": Dockfile,
|
||||
"template": map[string]interface{}{"shy": Dockfile},
|
||||
"output": "etc/Dockerfile",
|
||||
}},
|
||||
"git": {Name: "git", Help: "记录", Value: map[string]interface{}{
|
||||
"alias": map[string]interface{}{"s": "status", "b": "branch"},
|
||||
@ -692,13 +703,13 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
m.Echo(strings.TrimSpace(m.Cmdx(prefix, "capture-pane", "-pt", target)))
|
||||
return
|
||||
}},
|
||||
"docker": {Name: "docker", Help: "容器", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"docker": {Name: "docker image|volume|network|container", Help: "容器", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
prefix := kit.Trans(m.Confv("prefix", "docker"))
|
||||
switch arg[0] {
|
||||
case "image":
|
||||
prefix = append(prefix, "image")
|
||||
pos := kit.Select("shy", arg, 1)
|
||||
tag := kit.Select("2.1", arg, 2)
|
||||
pos := kit.Select(m.Conf("runtime", "boot.ctx_app"), arg, 1)
|
||||
tag := kit.Select(m.Conf("runtime", "boot.version"), arg, 2)
|
||||
|
||||
// 查看镜像
|
||||
if m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "IMAGE ID", "IMAGE_ID"); len(arg) == 1 {
|
||||
@ -732,22 +743,43 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
// 创建镜像
|
||||
default:
|
||||
m.Option("base", pos+":"+tag)
|
||||
m.Option("name", arg[0]+":"+kit.Select("2.1", arg, 1))
|
||||
m.Option("host", "http://"+m.Conf("runtime", "boot.hostname")+".local:9095")
|
||||
m.Option("user", kit.Select("shy", arg, 2))
|
||||
m.Option("file", "etc/Dockerfile")
|
||||
pos = kit.Select(m.Conf("runtime", "boot.ctx_app"), arg, 0)
|
||||
m.Option("name", pos+":"+m.Time("20060102"))
|
||||
m.Option("file", m.Conf("docker", "output"))
|
||||
m.Option("user", kit.Select(m.Conf("runtime", "boot.username"), arg, 1))
|
||||
m.Option("host", "http://"+m.Conf("runtime", "boot.hostname")+".local"+m.Conf("runtime", "boot.web_port"))
|
||||
|
||||
if f, _, e := kit.Create(m.Option("file")); m.Assert(e) {
|
||||
defer f.Close()
|
||||
if m.Assert(ctx.ExecuteStr(m, f, m.Conf("docker", arg[0]))) {
|
||||
if m.Assert(ctx.ExecuteStr(m, f, m.Conf("docker", "template."+arg[0]))) {
|
||||
m.Cmdy(prefix, "build", "-f", m.Option("file"), "-t", m.Option("name"), ".")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case "volume":
|
||||
if prefix = append(prefix, "volume"); len(arg) == 1 {
|
||||
m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "VOLUME NAME", "VOLUME_NAME")
|
||||
break
|
||||
}
|
||||
|
||||
case "network":
|
||||
if prefix = append(prefix, "network"); len(arg) == 1 {
|
||||
m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "NETWORK ID", "NETWORK_ID")
|
||||
break
|
||||
}
|
||||
|
||||
kit.Map(kit.Chain(kit.UnMarshal(m.Cmdx(prefix, "inspect", arg[1])), "0.Containers"), "", func(key string, value map[string]interface{}) {
|
||||
m.Push("CONTAINER_ID", key[:12])
|
||||
m.Push("name", value["Name"])
|
||||
m.Push("IPv4", value["IPv4Address"])
|
||||
m.Push("IPv6", value["IPV4Address"])
|
||||
m.Push("Mac", value["MacAddress"])
|
||||
})
|
||||
m.Table()
|
||||
|
||||
case "container":
|
||||
prefix = append(prefix, "container")
|
||||
if len(arg) > 1 {
|
||||
if prefix = append(prefix, "container"); len(arg) > 1 {
|
||||
switch arg[2] {
|
||||
case "进入":
|
||||
m.Cmdy(m.Confv("prefix", "tmux"), "new-window", "-dPF", "#{session_name}:#{window_name}.1", "docker exec -it "+arg[1]+" sh")
|
||||
@ -775,36 +807,25 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
m.Cmd(prefix, "rm", arg[1])
|
||||
|
||||
default:
|
||||
if len(arg) > 2 {
|
||||
m.Cmdy(prefix, "exec", arg[1], arg[2:])
|
||||
} else {
|
||||
if len(arg) == 2 {
|
||||
m.Cmdy(prefix, "inspect", arg[1])
|
||||
return
|
||||
}
|
||||
m.Cmdy(prefix, "exec", arg[1], arg[2:])
|
||||
return
|
||||
}
|
||||
}
|
||||
m.Cmdy(prefix, "ls", "-a", "cmd_parse", "cut", "cmd_headers", "CONTAINER ID", "CONTAINER_ID")
|
||||
|
||||
case "network":
|
||||
prefix = append(prefix, "network")
|
||||
if len(arg) == 1 {
|
||||
m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "NETWORK ID", "NETWORK_ID")
|
||||
break
|
||||
}
|
||||
|
||||
kit.Map(kit.Chain(kit.UnMarshal(m.Cmdx(prefix, "inspect", arg[1])), "0.Containers"), "", func(key string, value map[string]interface{}) {
|
||||
m.Push("CONTAINER_ID", key[:12])
|
||||
m.Push("name", value["Name"])
|
||||
m.Push("IPv4", value["IPv4Address"])
|
||||
m.Push("IPv6", value["IPV4Address"])
|
||||
m.Push("Mac", value["MacAddress"])
|
||||
})
|
||||
m.Table()
|
||||
|
||||
case "volume":
|
||||
if len(arg) == 1 {
|
||||
m.Cmdy(prefix, "volume", "ls", "cmd_parse", "cut", "cmd_headers", "VOLUME NAME", "VOLUME_NAME")
|
||||
break
|
||||
case "command":
|
||||
switch arg[3] {
|
||||
case "base":
|
||||
m.Echo("\n0[%s]$ %s %s\n", time.Now().Format("15:04:05"), arg[2], m.Conf("package", arg[2]+".update"))
|
||||
m.Cmdy(prefix, "exec", arg[1], arg[2], strings.Split(m.Conf("package", arg[2]+".update"), " "))
|
||||
m.Confm("package", []string{arg[2], arg[3]}, func(index int, value string) {
|
||||
m.Echo("\n%d[%s]$ %s %s %s\n", index+1, time.Now().Format("15:04:05"), arg[2], m.Conf("package", arg[2]+".install"), value)
|
||||
m.Cmdy(prefix, "exec", arg[1], arg[2], strings.Split(m.Conf("package", arg[2]+".install"), " "), value)
|
||||
})
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -36,7 +36,7 @@ kit image "镜像" private "web.code.docker" "image" \
|
||||
text "" name pos imports plugin_REPOSITORY \
|
||||
text "" name tag imports plugin_TAG \
|
||||
exports IMAGE_ID IMAGE_ID "" REPOSITORY REPOSITORY "" TAG TAG "" \
|
||||
feature detail "运行" "删除" "清理" \
|
||||
feature detail "运行" "清理" "删除" "创建" \
|
||||
button "查看"
|
||||
|
||||
kit volume "存储" private "web.code.docker" "volume" \
|
||||
@ -49,17 +49,19 @@ kit network "网络" private "web.code.docker" "network" \
|
||||
exports NETWORK_ID NETWORK_ID \
|
||||
button "查看"
|
||||
|
||||
kit command "命令" private "web.code.docker" "container" \
|
||||
text "" name tag imports plugin_CONTAINER_ID \
|
||||
text "pwd" name cmd view long \
|
||||
button "执行"
|
||||
|
||||
kit container "容器" private "web.code.docker" "container" \
|
||||
text "" name arg imports plugin_CONTAINER_ID \
|
||||
exports CONTAINER_ID CONTAINER_ID \
|
||||
feature detail "进入" "停止" "启动" "重启" "修改" "删除" "清理" \
|
||||
feature detail "进入" "停止" "启动" "重启" "清理" "修改" "删除" \
|
||||
button "查看" action auto
|
||||
|
||||
kit command "命令" private "web.code.docker" "command" \
|
||||
text "" name tag imports plugin_CONTAINER_ID \
|
||||
select "" name pkg values "apk apt yum" \
|
||||
select "" name cmd values "base" \
|
||||
text "" name arg view long \
|
||||
button "执行"
|
||||
|
||||
kit git "记录" private "ssh._route" _ "web.code.git" \
|
||||
text "" name pod imports plugin_pod \
|
||||
text "" name dir imports plugin_path action auto \
|
||||
|
@ -1056,6 +1056,7 @@ function Plugin(page, pane, field, inits, runs) {
|
||||
switch (item.type) {
|
||||
case "upfile": item.type = "file"; break
|
||||
case "select":
|
||||
item.values = kit.Trans(item.values)
|
||||
input.type = "select", input.list = item.values.map(function(value) {
|
||||
return {type: "option", value: value, inner: value}
|
||||
})
|
||||
|
@ -533,6 +533,9 @@ kit = toolkit = (function() {var kit = {__proto__: document,
|
||||
return list
|
||||
},
|
||||
// 数据类型转换
|
||||
Trans: function(c) {
|
||||
return typeof c == "string"? c.split(" "): c
|
||||
},
|
||||
isNone: function(c) {return c === undefined || c === null},
|
||||
notNone: function(c) {return !kit.isNone(c)},
|
||||
isSpace: function(c) {return c == " " || c == "Enter"},
|
||||
|
Loading…
x
Reference in New Issue
Block a user