- Updated package version in package.json from 0.0.40 to 0.0.42. - Added getCNBVersion function to fetch CNB version information from the API. - Enhanced Issue class with methods for managing comments (list, create, get, update). - Introduced new NPC and comment environment hooks for better context management. - Implemented Docker image synchronization route for CNB. - Added tests for version fetching and issue comment functionalities.
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { execSync } from 'child_process';
|
|
import { app, notCNBCheck } from '../../app.ts'
|
|
import { z } from 'zod'
|
|
import { title } from 'process';
|
|
|
|
app.route({
|
|
path: 'cnb',
|
|
key: 'docker-sync',
|
|
middleware: ['auth'],
|
|
metadata: {
|
|
tag: ['opencode'],
|
|
skill: 'cnb-docker-sync',
|
|
title: 'CNB Docker 镜像同步',
|
|
args: {
|
|
image: z.string().describe('Docker 同步的具体的镜像名称.'),
|
|
toVersion: z.string().optional().describe('修改后的版本号.'),
|
|
}
|
|
}
|
|
}).define(async (ctx) => {
|
|
const { image, toVersion } = ctx.args;
|
|
notCNBCheck(ctx);
|
|
if (!image) {
|
|
ctx.body = {
|
|
message: '请提供 Docker 镜像名称.',
|
|
data: null,
|
|
}
|
|
return;
|
|
}
|
|
const config = {
|
|
registry: 'docker.cnb.cool/kevisual/dev-env',
|
|
dockers: [{ image, toVersion }]
|
|
}
|
|
// docker tag ghcr.io/esm-dev/esm.sh:v137 docker.cnb.cool/kevisual/dev-env/esm.sh:v137
|
|
// docker push docker.cnb.cool/kevisual/dev-env/esm.sh:v137
|
|
const run = async () => {
|
|
const dockers = config.dockers;
|
|
for (const { image, toVersion } of dockers) {
|
|
const imageName = image.split(':')[0].split('/').slice(-1)[0]
|
|
const tag = image.split(':')[1]
|
|
const newImage = `${config.registry}/${imageName}:${toVersion || tag}`
|
|
// console.log(`docker tag ${image} ${newImage}`)
|
|
// console.log(`docker push ${newImage}`)
|
|
const shell = `docker pull ${image} && docker tag ${image} ${newImage} && docker push ${newImage}`
|
|
console.log(shell)
|
|
|
|
console.log('\n-------------new---------------------------------\n')
|
|
console.log(`${newImage}`)
|
|
console.log('\n--------------------------------------------------\n')
|
|
try {
|
|
execSync(shell, { stdio: 'inherit' })
|
|
} catch (error) {
|
|
console.error(`Error: ${error}`)
|
|
}
|
|
}
|
|
}
|
|
run().then(() => {
|
|
// TODO: 通知用户同步完成
|
|
});;
|
|
ctx.body = {
|
|
message: 'Docker 镜像同步任务中,请稍后在目标仓库查看.',
|
|
data: {
|
|
registry: config.registry,
|
|
dockers: config.dockers,
|
|
}
|
|
}
|
|
}).addTo(app); |