@@ -22,7 +22,7 @@ import { logger } from '@/lib/logger'
2222import { messageError , wrapError } from '@/lib/utils/error'
2323import { SshFinalConnectionInfo } from '@/app/connect-info/schemas'
2424
25- import { PackageManager } from './pm'
25+ import { DockerPackageMirrors , PackageManager , PackageMirrors } from './pm'
2626import { MxaCtl , SystemInfo } from './ssh-controller'
2727
2828const log = logger . child ( { module : 'ssh.deployer' } )
@@ -53,6 +53,11 @@ export type InstallStepFlags = {
5353 installNvidiaCtk ?: InstallFlag
5454}
5555
56+ export type InstallOptions = {
57+ packageMirror ?: PackageMirrors | 'none'
58+ dockerPackageMirror ?: DockerPackageMirrors
59+ }
60+
5661export type SshDeployerStatus = 'idle' | 'failed' | 'installing' | 'completed'
5762
5863export type SshDeployerInfo = {
@@ -242,14 +247,14 @@ echo "{\
242247 this . ee . on ( 'install:completed' , listener )
243248 }
244249
245- async install ( { onProgress } : { onProgress ?: LogListener } = { } ) {
250+ async install ( { onProgress, ... options } : { onProgress ?: LogListener } & InstallOptions = { } ) {
246251 if ( onProgress ) {
247252 this . onLog ( onProgress )
248253 }
249254 this . beforeInstall ( )
250- await this . updateSources ( )
255+ await this . updateSources ( options . packageMirror )
251256 await this . installDependencies ( )
252- await this . installDocker ( )
257+ await this . installDocker ( options . dockerPackageMirror )
253258 if ( this . installFlags . installNvidiaGpu ) {
254259 await this . installNvidiaGpu ( )
255260 }
@@ -313,20 +318,20 @@ echo "{\
313318 }
314319 }
315320
316- private async updatePmIndex ( ) {
317- await this . execInstallScript ( {
318- script : this . pm . updateIndex ( ) ,
319- flag : this . installFlags . updateSources ,
320- initLog : '更新软件包索引' ,
321- successLog : '软件包索引更新完成 ' ,
322- errorLog : '软件包索引更新失败 ' ,
323- errorMessage : '软件包索引更新失败,请检查网络连接或手动更新软件包索引 ' ,
324- } )
325- }
326-
327- private async updateSources ( ) {
321+ private async updateSources ( mirror ?: InstallOptions [ 'packageMirror' ] ) {
322+ if ( mirror === 'none' ) {
323+ await this . execInstallScript ( {
324+ script : this . pm . updateIndex ( ) ,
325+ flag : this . installFlags . updateSources ,
326+ initLog : '更新软件包索引 ' ,
327+ successLog : '软件包索引更新完成 ' ,
328+ errorLog : '软件包索引更新失败' ,
329+ errorMessage : '软件包索引更新失败,请检查网络连接或手动更新软件包索引' ,
330+ } )
331+ return
332+ }
328333 await this . execInstallScript ( {
329- script : this . pm . updateSources ( ) ,
334+ script : this . pm . updateSources ( mirror ) ,
330335 flag : this . installFlags . updateSources ,
331336 initLog : '更新软件源' ,
332337 successLog : '软件源更新完成' ,
@@ -353,9 +358,9 @@ echo "{\
353358 } )
354359 }
355360
356- private async installDocker ( ) {
361+ private async installDocker ( mirror ?: InstallOptions [ 'dockerPackageMirror' ] ) {
357362 await this . execInstallScript ( {
358- script : this . pm . installDocker ( ) ,
363+ script : this . pm . installDocker ( mirror ) ,
359364 flag : this . installFlags . installDocker ,
360365 initLog : '安装 Docker' ,
361366 successLog : 'Docker 安装完成' ,
@@ -508,17 +513,17 @@ export class SshDeployerManager {
508513 return deployer
509514 }
510515
511- async installTrigger ( host : string ) {
516+ async installTrigger ( host : string , options : InstallOptions = { } ) {
512517 const deployer = this . getDeployer ( host )
513- await deployer . install ( )
518+ await deployer . install ( options )
514519 }
515520
516- installStream ( host : string ) : EventIterator < string > {
521+ installStream ( host : string , options : InstallOptions = { } ) : EventIterator < string > {
517522 const deployer = this . getDeployer ( host )
518523 return new EventIterator < string > ( ( { push, stop, fail } ) => {
519524 deployer . getLogs ( ) . forEach ( ( log ) => push ( log ) )
520525 deployer
521- . install ( { onProgress : ( data ) => push ( data ) } )
526+ . install ( { onProgress : ( data ) => push ( data ) , ... options } )
522527 . then ( ( ) => stop ( ) )
523528 . catch ( ( err ) => fail ( err ) )
524529 } )
0 commit comments