From 285cdddb430a36c81795629f85bfe15b22d947b6 Mon Sep 17 00:00:00 2001 From: xiongxiao Date: Tue, 13 Jan 2026 18:06:05 +0800 Subject: [PATCH] add process --- .cnb.yml | 1 + .cnb/template.yml | 27 +++++++++++++- .gitignore | 1 + src/common/cnb-env.ts | 47 ++++++++++++++++++++++++ src/index.ts | 4 +- src/{workspace.ts => workspace/index.ts} | 2 +- test/build.ts | 2 +- test/common.ts | 12 +++--- 8 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 src/common/cnb-env.ts rename src/{workspace.ts => workspace/index.ts} (99%) diff --git a/.cnb.yml b/.cnb.yml index 7276c88..7e80fb8 100644 --- a/.cnb.yml +++ b/.cnb.yml @@ -21,6 +21,7 @@ $: # stages: # - name: pnpm install # script: pnpm install + stages: !reference [.dev_tempalte, stages] .common_sync_to_gitea: &common_sync_to_gitea - <<: *common_env diff --git a/.cnb/template.yml b/.cnb/template.yml index 2b99dfd..97beebb 100644 --- a/.cnb/template.yml +++ b/.cnb/template.yml @@ -87,4 +87,29 @@ - name: Docker build script: docker build -t ${CNB_DOCKER_REGISTRY}/${CNB_REPO_SLUG_LOWERCASE}:latest . - name: Docker push - script: docker push ${CNB_DOCKER_REGISTRY}/${CNB_REPO_SLUG_LOWERCASE}:latest \ No newline at end of file + script: docker push ${CNB_DOCKER_REGISTRY}/${CNB_REPO_SLUG_LOWERCASE}:latest + + + +.dev_tempalte: &dev_tempalte + services: + - vscode + docker: + image: docker.cnb.cool/kevisual/dev-env:latest + stages: + - name: 软链 .env 文件到工作目录(仓库根目录) + script: | + if [ -e "/root/.cnb/.env" ]; then + ln -sf /root/.cnb/.env ./.env + else + echo "文件不存在" + fi + init_stages: + - name: '安装依赖' + script: | + pnpm install + if [ -e "/root/.cnb/.env" ]; then + ln -sf /root/.cnb/.env ./.env + else + echo "文件不存在" + fi diff --git a/.gitignore b/.gitignore index 248b6c2..bd681d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env +.env.local node_modules .pnpm-store \ No newline at end of file diff --git a/src/common/cnb-env.ts b/src/common/cnb-env.ts new file mode 100644 index 0000000..193dab2 --- /dev/null +++ b/src/common/cnb-env.ts @@ -0,0 +1,47 @@ + +/** + * CNB 环境变量配置 + * 该模块定义了 CNB (Cloud Native Build) 平台提供的所有环境变量 + * 用于获取当前构建环境、仓库信息、运行器配置等元数据 + */ +import { useKey } from "@kevisual/use-config" + +export const CNB_ENV = { + // 仓库相关配置 + /** 仓库的 HTTPS 地址,如 "https://cnb.cool/kevisual/cnb" */ + CNB_REPO_URL_HTTPS: useKey('CNB_REPO_URL_HTTPS'), + + // 构建相关配置 + /** 流水线 ID,唯一标识一次构建流水线,如 "cnb-108-1jer5qekq-001" */ + CNB_PIPELINE_ID: useKey('CNB_PIPELINE_ID'), + /** 构建 ID,与流水线 ID 相关联,如 "cnb-108-1jer5qekq" */ + CNB_BUILD_ID: useKey('CNB_BUILD_ID'), + /** 构建开始时间,ISO 8601 格式,如 "2026-01-13T07:58:41.825Z" */ + CNB_BUILD_START_TIME: useKey('CNB_BUILD_START_TIME'), + /** 构建日志 Web 界面 URL,用于在浏览器中查看构建日志 */ + CNB_BUILD_WEB_URL: useKey('CNB_BUILD_WEB_URL'), + /** 触发构建的事件类型,如 "vscode" 表示由 VS Code 触发 */ + CNB_EVENT: useKey('CNB_EVENT'), + /** 当前构建对应的 Git 提交哈希值 */ + CNB_COMMIT: useKey('CNB_COMMIT'), + + // VS Code 相关配置 + /** VS Code Web 界面的访问 URL,用于在浏览器中打开 VS Code */ + CNB_VSCODE_WEB_URL: useKey('CNB_VSCODE_WEB_URL'), + /** VS Code 代理 URI,用于端口转发,{{port}} 会被替换为实际端口号, 例如: "https://1wnts22gq3-{{port}}.cnb.run"*/ + CNB_VSCODE_PROXY_URI: useKey('CNB_VSCODE_PROXY_URI'), + + // 仓库标识配置 + /** 仓库标识符,格式为 "组名/仓库名",如 "kevisual/cnb" */ + CNB_REPO_SLUG: useKey('CNB_REPO_SLUG'), + /** 组名/命名空间标识符,如 "kevisual" */ + CNB_GROUP_SLUG: useKey('CNB_GROUP_SLUG'), + + // 运行器资源配置 + /** 运行器分配的 CPU 核心数,单位为核, 例如: "8"*/ + CNB_CPUS: useKey('CNB_CPUS'), + /** 运行器分配的内存大小,单位为 GB, 例如: "16"*/ + CNB_MEMORY: useKey('CNB_MEMORY'), + /** 运行器的 IP 地址,用于网络连接和调试 */ + CNB_RUNNER_IP: useKey('CNB_RUNNER_IP'), +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 066bda1..5fe7571 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { CNBCore, CNBCoreOptions } from "./cnb-core.ts"; -import { Workspace } from "./workspace.ts"; +import { Workspace } from "./workspace/index.ts"; import { KnowledgeBase } from "./knowledge/index.ts"; import { Repo } from "./repo/index.ts"; import { User } from "./user/index.ts"; @@ -59,7 +59,7 @@ export class CNB extends CNBCore { } } -export * from './workspace.ts' +export * from './workspace/index.ts' export * from './cnb-core.ts' export * from './knowledge/index.ts' export * from './repo/index.ts' diff --git a/src/workspace.ts b/src/workspace/index.ts similarity index 99% rename from src/workspace.ts rename to src/workspace/index.ts index 2879679..cc59f79 100644 --- a/src/workspace.ts +++ b/src/workspace/index.ts @@ -6,7 +6,7 @@ */ import { Result } from "@kevisual/query/query"; -import { CNBCore } from "./cnb-core.ts"; +import { CNBCore } from "../cnb-core.ts"; /** * 工作空间列表查询参数 diff --git a/test/build.ts b/test/build.ts index fd77648..7a73ff9 100644 --- a/test/build.ts +++ b/test/build.ts @@ -15,4 +15,4 @@ const main = async () => { console.log("build", build); } -main() \ No newline at end of file +// main() \ No newline at end of file diff --git a/test/common.ts b/test/common.ts index 02a2c0a..b19eebc 100644 --- a/test/common.ts +++ b/test/common.ts @@ -1,16 +1,18 @@ import { CNB } from "../src"; import dotenv from "dotenv"; import util from 'node:util'; -dotenv.config(); -export const token = process.env.CNB_TOKEN || ""; -export const cookie = process.env.CNB_COOKIE || ""; +import { useConfig, useKey } from "@kevisual/use-config"; +const config = useConfig() +export const token = useKey("CNB_TOKEN") as string || ''; +export const cookie = useKey("CNB_COOKIE") as string || ''; +console.log('token', token) export const cnb = new CNB({ token, cookie }); export const showMore = (obj: any) => { return util.inspect(obj, { showHidden: false, depth: null, colors: true }); } -// const worksaceList = await cnb.workspace.list({ status: 'running' }); +const worksaceList = await cnb.workspace.list({ status: 'running' }); -// console.log("worksaceList", worksaceList); +console.log("worksaceList", showMore(worksaceList)); // const sn = 'cnb-o18-1jbklfuoh'