Compare commits
5 Commits
57660d2d9c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e43eb2db7 | |||
| 1644310bf5 | |||
| 501ceede27 | |||
| 780172e9b4 | |||
| 3cb666bc8f |
13
.cnb.yaml
13
.cnb.yaml
@@ -1,13 +0,0 @@
|
||||
# .cnb.yml
|
||||
$:
|
||||
vscode:
|
||||
- docker:
|
||||
image: docker.cnb.cool/kevisual/node24:latest
|
||||
services:
|
||||
- vscode
|
||||
- docker
|
||||
imports: https://cnb.cool/kevisual/env/-/blob/main/env.yml
|
||||
# 开发环境启动后会执行的任务
|
||||
# stages:
|
||||
# - name: pnpm install
|
||||
# script: pnpm install
|
||||
43
.cnb.yml
Normal file
43
.cnb.yml
Normal file
@@ -0,0 +1,43 @@
|
||||
# .cnb.yml
|
||||
$:
|
||||
vscode:
|
||||
- docker:
|
||||
image: docker.cnb.cool/kevisual/node24:latest
|
||||
services:
|
||||
- vscode
|
||||
- docker
|
||||
imports: https://cnb.cool/kevisual/env/-/blob/main/env.yml
|
||||
# 开发环境启动后会执行的任务
|
||||
# stages:
|
||||
# - name: pnpm install
|
||||
# script: pnpm install
|
||||
|
||||
|
||||
main:
|
||||
web_trigger_sync_to_gitea:
|
||||
- services:
|
||||
- docker
|
||||
imports:
|
||||
- https://cnb.cool/kevisual/env/-/blob/main/env.yml
|
||||
stages:
|
||||
- name: 'show username'
|
||||
script: echo "GITEA_USERNAME is ${GITEA_USERNAME} and GITEA_PASSWORD is ${GITEA_PASSWORD}"
|
||||
- name: sync to gitea
|
||||
image: tencentcom/git-sync
|
||||
settings:
|
||||
target_url: https://git.xiongxiao.me/kevisual/cnb.git
|
||||
auth_type: https
|
||||
username: "oauth2"
|
||||
password: ${GITEA_TOKEN}
|
||||
git_user: "abearxiong"
|
||||
git_email: "xiongxiao@xiongxiao.me"
|
||||
sync_mode: rebase
|
||||
branch: main
|
||||
|
||||
|
||||
|
||||
"**":
|
||||
web_trigger_test:
|
||||
- stages:
|
||||
- name: 执行任务
|
||||
script: echo "job"
|
||||
11
.cnb/web_trigger.yml
Normal file
11
.cnb/web_trigger.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
# .cnb/web_trigger.yml
|
||||
branch:
|
||||
# 如下按钮在分支名以 release 开头的分支详情页面显示
|
||||
- reg: "^main"
|
||||
buttons:
|
||||
- name: 同步代码到gitea
|
||||
desc: 同步代码到gitea
|
||||
event: web_trigger_sync_to_gitea
|
||||
- name: 同步gitea代码到当前仓库
|
||||
desc: 同步gitea代码到当前仓库
|
||||
event: web_trigger_sync_from_gitea
|
||||
1
docs/index.html
Normal file
1
docs/index.html
Normal file
@@ -0,0 +1 @@
|
||||
this is a test page
|
||||
@@ -3,4 +3,9 @@
|
||||
### 代码同步
|
||||
|
||||
1. 从cnb同步到本地gitea
|
||||
2. 从本地gitea同步到cnb
|
||||
2. 从本地gitea同步到cnb
|
||||
|
||||
|
||||
|
||||
## 启动环境
|
||||
https://docs.cnb.cool/zh/workspaces/custom-dev-env.html
|
||||
@@ -27,6 +27,10 @@ export interface ListParams {
|
||||
status?: 'running' | 'closed';
|
||||
}
|
||||
|
||||
/**
|
||||
* 云原生开发环境管理模块
|
||||
* https://api.cnb.cool/#/operations/GetWorkspaceDetail
|
||||
*/
|
||||
export class Workspace extends CNBCore {
|
||||
constructor(token: string) {
|
||||
super({ token });
|
||||
@@ -137,8 +141,10 @@ export type ResultList<T> = {
|
||||
export interface WorkspaceInfo {
|
||||
/** 分支名,例如:main */
|
||||
branch: string;
|
||||
/** 业务 ID */
|
||||
business_id: string;
|
||||
/** 备份的 commit 数 */
|
||||
commit_count: number;
|
||||
commit_count: number | null;
|
||||
/** 开发环境创建时间,例如:2024-12-02T03:20:22.000Z */
|
||||
create_time: string;
|
||||
/** 开发环境持续时间,单位:ms(非实时更新) */
|
||||
@@ -147,24 +153,36 @@ export interface WorkspaceInfo {
|
||||
file_count: number;
|
||||
/** 备份的文件列表,仅前五个备份文件相对路径 */
|
||||
file_list: string;
|
||||
/** 是否为预览环境,0: 否,1: 是 */
|
||||
is_preview: number;
|
||||
/** JetBrains IDE 列表 */
|
||||
jetbrainsList: any[];
|
||||
/** 环境销毁时远程最新的 commit short hash */
|
||||
latest_sha: string;
|
||||
latest_sha: string | null;
|
||||
/** 创建环境的子流水线 id */
|
||||
pipeline_id: string;
|
||||
/** 备份的 stash 数 */
|
||||
remote_stash_count: number;
|
||||
remote_stash_count: number | null;
|
||||
/** 仓库 ID */
|
||||
repo_id: string;
|
||||
/** 仓库地址 */
|
||||
repo_url: string;
|
||||
/** 恢复备份代码的流水线 id,如果有值表示备份代码已被恢复(重建环境时会恢复备份代码) */
|
||||
restore_id: string;
|
||||
restore_id: string | null;
|
||||
/** 单个 stash 标识,1: 是,0: 否 */
|
||||
single_stash: number;
|
||||
/** 仓库路径,例如:groupname/reponame */
|
||||
slug: string;
|
||||
/** 创建开发环境的流水线 sn */
|
||||
sn: string;
|
||||
/** 开发环境是否支持 ssh 链接 */
|
||||
ssh: boolean;
|
||||
/** 本地 stash 数 */
|
||||
stash_count: number;
|
||||
/** 工作区状态,running: 开发环境已启动,closed:开发环境已关闭 */
|
||||
status: string;
|
||||
/** 用户名 */
|
||||
user_name: string;
|
||||
/** 开发环境默认工作区路径 */
|
||||
workspace: string;
|
||||
}
|
||||
|
||||
15781
swagger.json
15781
swagger.json
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,26 @@
|
||||
import { CNB } from "../src";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
const cnb = new CNB(process.env.CNB_TOKEN || "");
|
||||
export const cnb = new CNB(process.env.CNB_TOKEN || "");
|
||||
|
||||
const worksaceList = await cnb.workspace.list();
|
||||
// const worksaceList = await cnb.workspace.list({ status: 'running' });
|
||||
|
||||
// console.log("worksaceList", worksaceList);
|
||||
|
||||
const sn = 'cnb-0eg-1jbkjj615-001'
|
||||
// const sn = 'cnb-o18-1jbklfuoh'
|
||||
|
||||
const worksace = await cnb.workspace.getDetail('kevisual/node24', sn)
|
||||
|
||||
console.log("worksace", worksace);
|
||||
// const worksace = await cnb.workspace.getDetail('kevisual/cnb', sn)
|
||||
|
||||
// console.log("worksace", worksace);
|
||||
|
||||
// const stop = await cnb.workspace.stopWorkspace({ sn })
|
||||
|
||||
// console.log("stop", stop);
|
||||
|
||||
// exebqzp8sc
|
||||
// const start = await cnb.workspace.startWorkspace('kevisual/cnb', {
|
||||
// branch: 'main',
|
||||
// });
|
||||
|
||||
// console.log("start", start);
|
||||
47
test/timeout-start.ts
Normal file
47
test/timeout-start.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { cnb } from "./common"
|
||||
|
||||
async function runWorkspaceStart() {
|
||||
const startTime = Date.now();
|
||||
const duration = 30 * 60 * 1000; // 30 minutes in milliseconds
|
||||
const interval = 5 * 60 * 1000; // 5 minutes in milliseconds
|
||||
let attemptCount = 0;
|
||||
|
||||
console.log(`Starting workspace start test at ${new Date().toLocaleString()}`);
|
||||
console.log(`Will run every 5 minutes for 30 minutes total`);
|
||||
|
||||
const runInterval = async () => {
|
||||
const currentTime = Date.now();
|
||||
const elapsed = currentTime - startTime;
|
||||
attemptCount++;
|
||||
|
||||
console.log(`\n=== Attempt ${attemptCount} at ${new Date().toLocaleString()} ===`);
|
||||
|
||||
try {
|
||||
const start = await cnb.workspace.startWorkspace('kevisual/cnb', {
|
||||
branch: 'main',
|
||||
});
|
||||
console.log(`Success: ${JSON.stringify(start, null, 2)}`);
|
||||
} catch (error) {
|
||||
console.error(`Error: ${error}`);
|
||||
}
|
||||
|
||||
// Check if we should continue
|
||||
if (elapsed + interval < duration) {
|
||||
setTimeout(runInterval, interval);
|
||||
} else {
|
||||
console.log(`\nTest completed at ${new Date().toLocaleString()}`);
|
||||
console.log(`Total attempts: ${attemptCount}`);
|
||||
}
|
||||
};
|
||||
|
||||
// Set timeout to stop after 30 minutes
|
||||
setTimeout(() => {
|
||||
console.log(`\nTimeout reached at ${new Date().toLocaleString()}`);
|
||||
console.log(`Test terminated after 30 minutes`);
|
||||
}, duration);
|
||||
|
||||
// Start the first run immediately
|
||||
runInterval();
|
||||
}
|
||||
|
||||
runWorkspaceStart().catch(console.error);
|
||||
Reference in New Issue
Block a user