File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ export async function isInstallDockerCompose(args?: DockerOptions) {
111
111
*/
112
112
export async function pushImage ( imageName : string ) {
113
113
const command = `docker push ${ imageName } `
114
- await commandStandardExecutor ( command )
114
+ await dockerScriptExecutor ( command )
115
115
}
116
116
117
117
/**
@@ -144,7 +144,8 @@ export async function buildImage(args: BuildImageDockerOptions) {
144
144
vipLog . log ( `${ command } \n` , { startLabel : vipSymbols . success } )
145
145
}
146
146
vipLog . log ( args . imageName , { startLabel : '构建镜像' } )
147
- await commandStandardExecutor ( command )
147
+
148
+ await dockerScriptExecutor ( command )
148
149
149
150
if ( args . push ) {
150
151
const exist = await isExistImage ( args . imageName )
@@ -187,3 +188,20 @@ export async function createContainer(args: CreateContainerOptions) {
187
188
const command = `docker run -d --name ${ args . containerName } --restart=unless-stopped ${ networkParams } ${ args . imageName } `
188
189
await commandStandardExecutor ( command )
189
190
}
191
+
192
+ /**
193
+ * docker命令的通用执行器
194
+ */
195
+ async function dockerScriptExecutor ( command : string ) {
196
+ try {
197
+ const errorCode = await commandStandardExecutor ( command )
198
+ if ( errorCode !== 0 ) {
199
+ vipLog . error ( `Error Code: ${ errorCode } ` , { startLabel : 'commandStandardExecutor' } )
200
+ process . exit ( 1 )
201
+ }
202
+ }
203
+ catch {
204
+ // 构建镜像出错时,直接退出
205
+ process . exit ( 1 )
206
+ }
207
+ }
Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ export function commandStandardExecutor(cmd: Command) {
108
108
}
109
109
} )
110
110
111
- // 进程退出
111
+ // 考虑进程非0退出
112
112
child . on ( 'close' , ( code ) => {
113
113
resolve ( code )
114
114
} )
You can’t perform that action at this time.
0 commit comments