Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new install options: sshDir and extraEnvs #1422

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nice-baboons-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/cli": patch
---

增加新的install.yaml配置`sshDir`and`extraEnvs`
8 changes: 8 additions & 0 deletions apps/cli/assets/init-full/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 15 additions & 5 deletions apps/cli/src/compose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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, ":"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
},
});
Expand Down Expand Up @@ -326,7 +336,7 @@ export const createComposeSpec = (config: InstallConfigSchema) => {
volumes: {
"/etc/hosts": "/etc/hosts",
"./config": "/etc/scow",
"~/.ssh": "/root/.ssh",
[SSH_DIR]: "/root/.ssh",
},
});

Expand Down Expand Up @@ -425,7 +435,7 @@ export const createComposeSpec = (config: InstallConfigSchema) => {
volumes: {
"/etc/hosts": "/etc/hosts",
"./config": "/etc/scow",
"~/.ssh": "/root/.ssh",
[SSH_DIR]: "/root/.ssh",
},
});

Expand Down
13 changes: 9 additions & 4 deletions apps/cli/src/config/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 相关配置" })),
Expand Down