From 35f3b60b6b30c17de977f0aec9fe8bfbca9c95e4 Mon Sep 17 00:00:00 2001 From: link89 Date: Tue, 10 Sep 2024 21:32:42 +0800 Subject: [PATCH] feat: new install options: sshDir and extraEnvs (#1422) close https://github.com/PKUHPC/SCOW/issues/1421 and https://github.com/PKUHPC/SCOW/issues/1423 --------- Co-authored-by: Chen Junda --- .changeset/nice-baboons-give.md | 5 +++++ apps/cli/assets/init-full/install.yaml | 8 ++++++++ apps/cli/src/compose/index.ts | 20 +++++++++++++++----- apps/cli/src/config/install.ts | 13 +++++++++---- 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 .changeset/nice-baboons-give.md diff --git a/.changeset/nice-baboons-give.md b/.changeset/nice-baboons-give.md new file mode 100644 index 0000000000..567cc495e4 --- /dev/null +++ b/.changeset/nice-baboons-give.md @@ -0,0 +1,5 @@ +--- +"@scow/cli": patch +--- + +增加新的install.yaml配置`sshDir`and`extraEnvs` diff --git a/apps/cli/assets/init-full/install.yaml b/apps/cli/assets/init-full/install.yaml index 08b3f58233..cf6ff47fba 100644 --- a/apps/cli/assets/init-full/install.yaml +++ b/apps/cli/assets/init-full/install.yaml @@ -7,6 +7,14 @@ # SCOW的镜像的tag。默认:master # imageTag: master +# 指定挂载到容器内 /root/.ssh 的目录。默认为 ~/.ssh (即当前用户家目录下的.ssh目录) +# sshDir: ./scow-ssh + +# 为每个服务指定额外的环境变量。默认为空。 +# extraEnvs: +# - SSH_PRIVATE_KEY_PATH=~/.ssh/id_ed25519 +# - SSH_PUBLIC_KEY_PATH=~/.ssh/id_ed25519.pub + # 门户相关配置。默认不部署 # 如果不部署,请删除或者注释整个部分 # portal: diff --git a/apps/cli/src/compose/index.ts b/apps/cli/src/compose/index.ts index 1edc6ec589..c287002531 100644 --- a/apps/cli/src/compose/index.ts +++ b/apps/cli/src/compose/index.ts @@ -48,6 +48,9 @@ export const createComposeSpec = (config: InstallConfigSchema) => { const AI_PATH = config.ai?.basePath || "/ai"; checkPathFormat("ai.basePath", AI_PATH); + const SSH_DIR = config.sshDir || "~/.ssh"; + checkPathFormat("sshDir", SSH_DIR); + const serviceLogEnv = { LOG_LEVEL: config.log.level, LOG_PRETTY: String(config.log.pretty), @@ -87,9 +90,16 @@ export const createComposeSpec = (config: InstallConfigSchema) => { return Object.entries(dict).map(([from, to]) => `${from}${splitter}${to}`); } + let extraEnvs: string[] = []; + if (config.extraEnvs) { + extraEnvs = Array.isArray(config.extraEnvs) ? config.extraEnvs : toStringArray(config.extraEnvs, "="); + } + + const environment = Array.isArray(options.environment) ? options.environment : toStringArray(options.environment, "="); + composeSpec.services[name] = { restart: "unless-stopped", - environment: Array.isArray(options.environment) ? options.environment : toStringArray(options.environment, "="), + environment: [...environment, ...extraEnvs], ports: Array.isArray(options.ports) ? options.ports : toStringArray(options.ports, ":"), image: options.image, volumes: Array.isArray(options.volumes) ? options.volumes : toStringArray(options.volumes, ":"), @@ -160,7 +170,7 @@ export const createComposeSpec = (config: InstallConfigSchema) => { const authVolumes = { "/etc/hosts": "/etc/hosts", "./config": "/etc/scow", - "~/.ssh": "/root/.ssh", + [SSH_DIR]: "/root/.ssh", }; const authUrl = config.auth.custom?.type === AuthCustomType.external @@ -272,7 +282,7 @@ export const createComposeSpec = (config: InstallConfigSchema) => { volumes: { "/etc/hosts": "/etc/hosts", "./config": configPath, - "~/.ssh": "/root/.ssh", + [SSH_DIR]: "/root/.ssh", "portal_data":"/var/lib/scow/portal", }, }); @@ -326,7 +336,7 @@ export const createComposeSpec = (config: InstallConfigSchema) => { volumes: { "/etc/hosts": "/etc/hosts", "./config": "/etc/scow", - "~/.ssh": "/root/.ssh", + [SSH_DIR]: "/root/.ssh", }, }); @@ -425,7 +435,7 @@ export const createComposeSpec = (config: InstallConfigSchema) => { volumes: { "/etc/hosts": "/etc/hosts", "./config": "/etc/scow", - "~/.ssh": "/root/.ssh", + [SSH_DIR]: "/root/.ssh", }, }); diff --git a/apps/cli/src/config/install.ts b/apps/cli/src/config/install.ts index b7b8f1eb22..1d3c8e1510 100644 --- a/apps/cli/src/config/install.ts +++ b/apps/cli/src/config/install.ts @@ -25,17 +25,22 @@ export const InstallConfigSchema = Type.Object({ basePath: Type.String({ description: "整个系统的部署路径", default: "/" }), image: Type.Optional(Type.String({ description: "镜像", default: "mirrors.pku.edu.cn/pkuhpc-icode/scow" })), imageTag: Type.String({ description: "镜像tag", default: "master" }), + sshDir: Type.String({ description: "ssh目录", default: "~/.ssh" }), + extraEnvs: Type.Optional(Type.Union([ + Type.Array(Type.String({ description: "格式:变量名=变量值" })), + Type.Record(Type.String(), Type.String(), { description: "格式:字符串: 字符串" }), + ], { description: "额外的全局环境变量配置" })), scowd: Type.Optional(Type.Object({ ssl: Type.Optional(Type.Object({ enabled: Type.Boolean({ description: "到 SCOWD 的连接是否启动SSL", default: false }), caCertPath: Type.String({ description: "SCOWD CA根证书路径, 相对 config 的默认目录", default: "./scowd/certs/ca.crt" }), - scowCertPath: Type.String({ - description: "SCOWD CA签名的 SCOW 证书路径, 相对 config 的默认目录", + scowCertPath: Type.String({ + description: "SCOWD CA签名的 SCOW 证书路径, 相对 config 的默认目录", default: "./scowd/certs/scow.crt", }), - scowPrivateKeyPath: Type.String({ - description: "SCOWD CA签名的 SCOW 私钥路径, 相对 config 的默认目录", + scowPrivateKeyPath: Type.String({ + description: "SCOWD CA签名的 SCOW 私钥路径, 相对 config 的默认目录", default: "./scowd/certs/scow.key", }), }, { description: "scowd 全局 ssl 相关配置" })),