mirror of
https://shylinux.com/x/icebergs
synced 2025-04-25 17:18:05 +08:00
106 lines
4.2 KiB
Go
106 lines
4.2 KiB
Go
package compose
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
|
|
"shylinux.com/x/ice"
|
|
"shylinux.com/x/icebergs/base/cli"
|
|
"shylinux.com/x/icebergs/base/ctx"
|
|
"shylinux.com/x/icebergs/base/lex"
|
|
"shylinux.com/x/icebergs/base/mdb"
|
|
"shylinux.com/x/icebergs/base/nfs"
|
|
"shylinux.com/x/icebergs/base/tcp"
|
|
"shylinux.com/x/icebergs/base/web"
|
|
kit "shylinux.com/x/toolkits"
|
|
)
|
|
|
|
type insight struct {
|
|
serveStart string `name:"serveStart path* port* repos binary" help:"启动服务" icon:"bi bi-plus-square-dotted"`
|
|
loadConfig string `name:"load path*=etc/compose/compose.shy type" help:"加载配置" icon:"bi bi-folder-plus"`
|
|
saveConfig string `name:"save path*=etc/compose/compose.shy type" help:"保存配置" icon:"bi bi-floppy"`
|
|
list string `name:"list list" help:"云游"`
|
|
}
|
|
|
|
func (s insight) Inputs(m *ice.Message, arg ...string) {
|
|
switch arg[0] {
|
|
case nfs.PATH:
|
|
m.Cmdy(nfs.DIR, "etc/compose/", arg[0])
|
|
case mdb.TYPE:
|
|
m.Push(arg[0], "local", "cluster", "docker", "kubectl")
|
|
}
|
|
}
|
|
func (s insight) ServeStart(m *ice.Message, arg ...string) {
|
|
pwd, _ := os.Getwd()
|
|
dir := path.Join(path.Dir(pwd), m.Option(nfs.PATH))
|
|
bin := path.Join(dir, ice.BIN_ICE_BIN)
|
|
if m.Echo(bin); bin == os.Args[0] {
|
|
return
|
|
}
|
|
if !nfs.Exists(m.Message, dir) {
|
|
m.Cmd(cli.SYSTEM, cli.GIT, "clone", m.OptionDefault(nfs.REPOS, ice.Info.Make.Remote), dir)
|
|
}
|
|
if !nfs.Exists(m.Message, bin) {
|
|
nfs.MkdirAll(m.Message, path.Dir(bin))
|
|
m.Cmd(cli.SYSTEM, cli.CP, os.Args[0], bin)
|
|
}
|
|
m.Info("serve start %v", bin)
|
|
m.Cmd(cli.DAEMON, bin, cli.FOREVER, cli.START, ice.DEV, m.Option(ice.MSG_USERHOST), tcp.NODENAME, path.Base(dir), m.OptionSimple(tcp.PORT), arg[4:], kit.Dict(cli.CMD_DIR, dir))
|
|
m.WaitEvent(web.OPS_SERVER_OPEN, func(msg *ice.Message, arg ...string) bool { return msg.Option(mdb.NAME) == path.Base(dir) })
|
|
}
|
|
func (s insight) LoadConfig(m *ice.Message, arg ...string) {
|
|
bin := ""
|
|
defer m.ToastProcess()()
|
|
cache := map[string][]string{}
|
|
m.Cmd(lex.SPLIT, m.Option(nfs.PATH), func(deep int, ls []string) {
|
|
switch deep {
|
|
case 1:
|
|
m.ToastProcess(ls[0] + " 服务启动中...")
|
|
bin = m.Cmdx("", s.ServeStart, nfs.PATH, ls[0], tcp.PORT, ls[1], cache["serve"], ls[2:])
|
|
cache["serve"] = append(cache["serve"], ls[2:]...)
|
|
case 2:
|
|
m.Info("dream start %v", bin)
|
|
m.Cmd(cli.SYSTEM, bin, web.ADMIN, web.DREAM, mdb.CREATE, "--", mdb.NAME, ls[0], cache[ls[0]], ls[1:], kit.Dict(cli.CMD_DIR, path.Dir(path.Dir(bin))))
|
|
// cache[ls[0]] = ls[1:]
|
|
cache[ls[0]] = append(cache[ls[0]], ls[1:]...)
|
|
}
|
|
})
|
|
}
|
|
func (s insight) SaveConfig(m *ice.Message, arg ...string) {
|
|
m.Cmd(nfs.SAVE, m.Option(nfs.PATH), kit.Format("%s %s username %q usernick %q language %q avatar %q\n", path.Base(kit.Pwd()), m.Option(tcp.PORT),
|
|
m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERNICK), m.Option(ice.MSG_LANGUAGE), m.Option(ice.MSG_AVATAR)))
|
|
m.Cmd(web.DREAM).Table(func(value ice.Maps) {
|
|
if value[mdb.TYPE] == web.WORKER {
|
|
m.Cmd(nfs.PUSH, m.Option(nfs.PATH), kit.Format(" %s repos %q binary %q\n", value[mdb.NAME], value[nfs.REPOS], value[nfs.BINARY]))
|
|
}
|
|
if value[mdb.TYPE] == web.SERVER {
|
|
msg := m.Cmd(web.SPACE, value[mdb.NAME], web.SERVE)
|
|
m.Cmd(nfs.PUSH, m.Option(nfs.PATH), kit.Format("%s %s repos %q binary %q\n", value[mdb.NAME], msg.Append(tcp.PORT), value[nfs.REPOS], value[nfs.BINARY]))
|
|
m.Cmd(web.SPACE, value[mdb.NAME], web.DREAM).Table(func(value ice.Maps) {
|
|
if value[mdb.TYPE] == web.WORKER {
|
|
m.Cmd(nfs.PUSH, m.Option(nfs.PATH), kit.Format(" %s repos %q binary %q\n", value[mdb.NAME], value[nfs.REPOS], value[nfs.BINARY]))
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
func (s insight) List(m *ice.Message, arg ...string) {
|
|
if len(arg) == 0 {
|
|
m.Cmd(web.SPACE).Table(func(value ice.Maps) {
|
|
if value[mdb.TYPE] == web.SERVER {
|
|
m.PushRecord(value, mdb.NAME, mdb.ICONS, nfs.MODULE, nfs.VERSION)
|
|
}
|
|
})
|
|
m.Action(s.ServeStart, s.LoadConfig, s.SaveConfig)
|
|
m.Display("/plugin/story/spides.js?split=.").Option(nfs.DIR_ROOT, ice.Info.NodeName)
|
|
kit.If(m.Length() == 0, func() { m.EchoInfoButton("请加载配置创建集群", s.LoadConfig) })
|
|
} else {
|
|
m.Cmdy(web.SPACE, arg[0], m.PrefixKey()).Table(func(value ice.Maps) {
|
|
m.Push(nfs.FILE, kit.Keys(arg[0], value[mdb.NAME]))
|
|
})
|
|
kit.If(m.Length() == 0, func() { m.Push(web.SPACE, arg[0]).Push(ctx.INDEX, web.DESKTOP) })
|
|
}
|
|
}
|
|
|
|
func init() { ice.Cmd("web.code.compose.insight", insight{}) }
|