diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml index 8faf149f..e3033820 100644 --- a/.github/workflows/build_docker_image.yml +++ b/.github/workflows/build_docker_image.yml @@ -17,7 +17,7 @@ jobs: to_gitlab: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: pixta-dev/repository-mirroring-action@v1 @@ -28,7 +28,7 @@ jobs: to_gitee: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: pixta-dev/repository-mirroring-action@v1 @@ -39,12 +39,12 @@ jobs: build-static: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2 + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v3 with: version: "8.3.1" - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: cache: "pnpm" @@ -95,7 +95,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v3 with: version: "8.3.1" - uses: actions/setup-node@v4 @@ -182,7 +182,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v3 with: version: "8.3.1" - uses: actions/setup-node@v4 diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index 59bdf357..64b3b6df 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -18,21 +18,47 @@ export default async () => { const dependenceService = Container.get(DependenceService); const systemService = Container.get(SystemService); + const installDependencies = () => { + // 初始化时安装所有处于安装中,安装成功,安装失败的依赖 + DependenceModel.findAll({ + where: {}, + order: [ + ['type', 'DESC'], + ['createdAt', 'DESC'], + ], + raw: true, + }).then(async (docs) => { + await DependenceModel.update( + { status: DependenceStatus.queued, log: [] }, + { where: { id: docs.map((x) => x.id!) } }, + ); + setTimeout(() => { + dependenceService.installDependenceOneByOne(docs); + }, 5000); + }); + }; + // 初始化更新 linux/python/nodejs 镜像源配置 const systemConfig = await systemService.getSystemConfig(); if (systemConfig.info?.pythonMirror) { systemService.updatePythonMirror({ - linuxMirror: systemConfig.info?.linuxMirror, + pythonMirror: systemConfig.info?.pythonMirror, }); } if (systemConfig.info?.linuxMirror) { - systemService.updateLinuxMirror({ - linuxMirror: systemConfig.info?.linuxMirror, - }); + systemService.updateLinuxMirror( + { + linuxMirror: systemConfig.info?.linuxMirror, + }, + undefined, + () => installDependencies(), + ); + } else { + installDependencies(); } if (systemConfig.info?.nodeMirror) { systemService.updateNodeMirror({ - linuxMirror: systemConfig.info?.linuxMirror, + nodeMirror: systemConfig.info?.nodeMirror, }); } @@ -53,24 +79,6 @@ export default async () => { // 初始化更新所有任务状态为空闲 await CrontabModel.update({ status: CrontabStatus.idle }, { where: {} }); - // 初始化时安装所有处于安装中,安装成功,安装失败的依赖 - DependenceModel.findAll({ - where: {}, - order: [ - ['type', 'DESC'], - ['createdAt', 'DESC'], - ], - raw: true, - }).then(async (docs) => { - await DependenceModel.update( - { status: DependenceStatus.queued, log: [] }, - { where: { id: docs.map((x) => x.id!) } }, - ); - setTimeout(() => { - dependenceService.installDependenceOneByOne(docs); - }, 5000); - }); - // 初始化时执行一次所有的 ql repo 任务 CrontabModel.findAll({ where: { diff --git a/back/services/system.ts b/back/services/system.ts index 09cf6ee0..26d4be54 100644 --- a/back/services/system.ts +++ b/back/services/system.ts @@ -177,7 +177,11 @@ export default class SystemService { return { code: 200, data: info }; } - public async updateLinuxMirror(info: SystemModelInfo, res?: Response) { + public async updateLinuxMirror( + info: SystemModelInfo, + res?: Response, + onEnd?: () => void, + ) { const oDoc = await this.getSystemConfig(); await this.updateAuthDb({ ...oDoc, @@ -185,8 +189,12 @@ export default class SystemService { }); let defaultDomain = 'https://dl-cdn.alpinelinux.org'; let targetDomain = 'https://dl-cdn.alpinelinux.org'; - if (oDoc.info?.linuxMirror) { - defaultDomain = oDoc.info.linuxMirror; + const content = await fs.promises.readFile('/etc/apk/repositories', { + encoding: 'utf-8', + }); + const domainMatch = content.match(/(http.*)\/alpine\/.*/); + if (domainMatch) { + defaultDomain = domainMatch[1]; } if (info.linuxMirror) { targetDomain = info.linuxMirror; @@ -211,6 +219,7 @@ export default class SystemService { type: 'updateLinuxMirror', message: 'update linux mirror end', }); + onEnd?.(); }, onError: async (message: string) => { this.sockService.sendMessage({ type: 'updateLinuxMirror', message });