From 76a8c812b204c184b04bfac6fe615a5e5aeb0bf4 Mon Sep 17 00:00:00 2001 From: shy Date: Wed, 13 Mar 2024 16:15:48 +0800 Subject: [PATCH] add some --- base/cli/runtime.go | 16 +++++++++------ base/nfs/template.go | 9 ++++---- core/code/publish.go | 49 ++++++++++++++++++-------------------------- 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/base/cli/runtime.go b/base/cli/runtime.go index d32b0316..679d6524 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -148,17 +148,21 @@ const ( TZ = "TZ" ) const ( - CTX_SHY = "ctx_shy" - CTX_DEV = "ctx_dev" - CTX_OPS = "ctx_ops" - CTX_DEMO = "ctx_demo" - CTX_MAIL = "ctx_mail" - CTX_ROOT = "ctx_root" + CTX_SHY = "ctx_shy" + CTX_DEV = "ctx_dev" + CTX_DEV_IP = "ctx_dev_ip" + CTX_REPOS = "ctx_repos" + CTX_OPS = "ctx_ops" + CTX_DEMO = "ctx_demo" + CTX_MAIL = "ctx_mail" + CTX_ROOT = "ctx_root" CTX_PID = "ctx_pid" CTX_LOG = "ctx_log" CTX_POD = "ctx_pod" CTX_ENV = "ctx_env" + CTX_CLI = "ctx_cli" + CTX_ARG = "ctx_arg" ) var ENV_LIST = []string{TZ, LANG, TERM, SHELL, CTX_SHY, CTX_DEV, CTX_OPS, CTX_DEMO, CTX_MAIL, CTX_ROOT, CTX_PID} diff --git a/base/nfs/template.go b/base/nfs/template.go index 60fe9b9c..50da6e26 100644 --- a/base/nfs/template.go +++ b/base/nfs/template.go @@ -39,14 +39,13 @@ func init() { func init() { ice.Info.Template = Template } func Template(m *ice.Message, p string, data ...ice.Any) string { - text := TemplateText(m, p) - if text == "" { + if text := TemplateText(m, p); text == "" { return "" - } - if len(data) == 0 { + } else if len(data) == 0 { return kit.Renders(text, m) + } else { + return kit.Renders(text, data[0]) } - return kit.Renders(text, data[0]) } var TemplateText = func(m *ice.Message, p string) string { diff --git a/core/code/publish.go b/core/code/publish.go index 0165e374..003ec116 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -45,44 +45,35 @@ func _publish_file(m *ice.Message, file string, arg ...string) string { return m.Cmdx(nfs.LINK, path.Join(ice.USR_PUBLISH, kit.Select(path.Base(file), arg, 0)), file) } func _publish_contexts(m *ice.Message, arg ...string) { - m.Options(nfs.DIR_ROOT, "").OptionDefault(ice.MSG_USERNAME, ice.DEMO) - - host := tcp.PublishLocalhost(m, web.UserHost(m)) - m.Option(ice.TCP_DOMAIN, kit.ParseURL(host).Hostname()) - m.Option("tcp_localhost", strings.ToLower(ice.Info.Hostname)) - m.OptionDefault(web.DOMAIN, host) - - env := []string{} - // m.Option("ctx_dev_ip", tcp.PublishLocalhost(m, web.SpideOrigin(m, ice.OPS))) - m.Option("ctx_dev_ip", web.HostPort(m, web.AdminCmd(m, tcp.HOST).Append(aaa.IP), web.AdminCmd(m, web.SERVE).Append(tcp.PORT))) - // kit.If(m.Option("ctx_dev_ip"), func(p string) { env = append(env, "ctx_dev_ip", p) }) - kit.If(m.Option(ice.MSG_USERPOD), func(p string) { env = append(env, cli.CTX_POD, p) }) - kit.If(len(env) > 0, func() { m.Options(cli.CTX_ENV, lex.SP+kit.JoinKV(mdb.EQ, lex.SP, env...)) }) - m.OptionDefault("ctx_cli", "temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL $ctx_dev; else wget -O $temp -q $ctx_dev; fi; source $temp") - m.OptionDefault("ctx_arg", kit.JoinCmds( - aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERNICK, m.Option(ice.MSG_USERNICK), - aaa.LANGUAGE, m.Option(ice.MSG_LANGUAGE), - )) - + m.Options(nfs.DIR_ROOT, "") + m.OptionDefault(web.DOMAIN, tcp.PublishLocalhost(m, web.UserHost(m))) + m.OptionDefault(cli.CTX_CLI, "temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL $ctx_dev; else wget -O $temp -q $ctx_dev; fi; source $temp") + m.OptionDefault(cli.CTX_ARG, kit.JoinCmds(aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.LANGUAGE, m.Option(ice.MSG_LANGUAGE))) for _, k := range kit.Default(arg, ice.MISC) { + env := []string{} switch k { - case INSTALL: - m.Option("format", "raw") - case ice.BASE: - m.Option(web.DOMAIN, web.SpideOrigin(m, ice.SHY)) - case ice.CORE: - m.Option(web.DOMAIN, web.SpideOrigin(m, ice.DEV)) case nfs.SOURCE, ice.DEV: - if m.Option(ice.MSG_USERPOD) == "" { + if ice.Info.NodeType == web.SERVER { + m.Options(nfs.SOURCE, ice.Info.Make.Remote) + } else if m.Option(ice.MSG_USERPOD) == "" { m.Option(nfs.SOURCE, web.AdminCmd(m, cli.RUNTIME, "make.remote").Result()) } else { - m.Option(nfs.SOURCE, web.AdminCmd(m, web.SPACE, m.Option(ice.MSG_USERPOD), cli.RUNTIME, "make.remote").Result()) + m.Option(nfs.SOURCE, web.AdminCmd(m, web.SPACE, kit.KeyBase(m.Option(ice.MSG_USERPOD)), cli.RUNTIME, "make.remote").Result()) } + env = append(env, cli.CTX_REPOS, m.Option(nfs.SOURCE)) + fallthrough case nfs.BINARY, ice.APP: + if host := web.HostPort(m, web.AdminCmd(m, tcp.HOST).Append(aaa.IP), web.AdminCmd(m, web.SERVE).Append(tcp.PORT)); m.Option(web.DOMAIN) != host { + env = append(env, cli.CTX_DEV_IP, host) + } + if ice.Info.NodeType == web.WORKER && m.Option(ice.MSG_USERPOD) != "" { + env = append(env, cli.CTX_POD, m.Option(ice.MSG_USERPOD)) + } else if name := web.AdminCmd(m, cli.RUNTIME, "boot.pathname").Result(); !kit.IsIn(name, path.Base(m.Option(nfs.SOURCE)), ice.CONTEXTS) { + env = append(env, "ctx_name", name) + } case cli.CURL, cli.WGET: - case "manual": - m.Option(nfs.BINARY, "ice.linux.amd64") } + kit.If(len(env) > 0, func() { m.Options(cli.CTX_ENV, lex.SP+kit.JoinKV(mdb.EQ, lex.SP, env...)) }) if template := strings.TrimSpace(nfs.Template(m, kit.Keys(k, SH))); m.Option("format") == "raw" { m.Echo(template) } else {