@@ -36,6 +36,7 @@ export class Console extends Runner {
3636 }
3737 this . setVariable ( this . workspaceDirectory , path . join ( this . getWorkingDirectory ( ) ) ) ;
3838 this . env = process . env ;
39+
3940 }
4041
4142 destroy ( playbook : Playbook ) : void {
@@ -204,6 +205,27 @@ export class Console extends Runner {
204205 return result ;
205206 }
206207
208+
209+ runDockerCompose ( step : Step , command : Command ) : RunResult {
210+ let result = new RunResult ( ) ;
211+ result . returnCode = 0 ;
212+
213+ let filepath = path . join ( this . getVariable ( this . workspaceDirectory ) , command . parameters [ 0 ] ) ;
214+
215+ let process = this . executeCommandAsync ( "docker-compose up" , filepath , result ) ;
216+ process . on ( 'close' , ( code ) => {
217+ if ( code !== 0 ) {
218+ result . returnCode = code ;
219+ }
220+ } ) ;
221+ if ( process . pid && command . parameters . length == 2 ) {
222+ this . asyncProcesses . push ( { pid : process . pid , name : "dockerCompose" , port : command . parameters [ 1 ] . port } ) ;
223+ }
224+
225+ return result ;
226+
227+ }
228+
207229 runRunServerJava ( step : Step , command : Command ) : RunResult {
208230 let result = new RunResult ( ) ;
209231 result . returnCode = 0 ;
@@ -231,6 +253,7 @@ export class Console extends Runner {
231253 this . executeCommandSync ( "git clone " + command . parameters [ 1 ] , directorypath , result ) ;
232254
233255 return result ;
256+
234257 }
235258
236259 runNpmInstall ( step : Step , command : Command ) : RunResult {
@@ -423,7 +446,37 @@ export class Console extends Runner {
423446 throw error ;
424447 }
425448 }
426-
449+
450+ async assertDockerCompose ( step : Step , command : Command , result : RunResult ) {
451+ try {
452+ let assert = new Assertions ( )
453+ . noErrorCode ( result )
454+ . noException ( result ) ;
455+
456+ if ( command . parameters . length > 1 ) {
457+ if ( ! command . parameters [ 1 ] . startupTime ) {
458+ console . warn ( "No startup time for command dockerCompose has been set" )
459+ }
460+ let startupTimeInSeconds = command . parameters [ 1 ] . startupTime ? command . parameters [ 1 ] . startupTime : 0 ;
461+ await this . sleep ( command . parameters [ 1 ] . startupTime ) ;
462+
463+ if ( ! command . parameters [ 1 ] . port ) {
464+ this . killAsyncProcesses ( ) ;
465+ throw new Error ( "Missing arguments for command dockerCompose. You have to specify a port and a path for the server. For further information read the function documentation." ) ;
466+ } else {
467+ let isReachable = await assert . serverIsReachable ( command . parameters [ 1 ] . port , command . parameters [ 1 ] . path ) ;
468+ if ( ! isReachable ) {
469+ this . killAsyncProcesses ( ) ;
470+ throw new Error ( "The server has not become reachable in " + startupTimeInSeconds + " seconds: " + "http://localhost:" + command . parameters [ 1 ] . port + "/" + command . parameters [ 1 ] . path ) ;
471+ }
472+ }
473+ }
474+ } catch ( error ) {
475+ this . cleanUp ( ) ;
476+ throw error ;
477+ }
478+ }
479+
427480 async assertRunServerJava ( step : Step , command : Command , result : RunResult ) {
428481 try {
429482 let assert = new Assertions ( )
@@ -658,5 +711,6 @@ export class Console extends Runner {
658711 }
659712 }
660713
714+
661715
662- }
716+ }
0 commit comments