@@ -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 {
@@ -434,7 +457,37 @@ export class Console extends Runner {
434457 throw error ;
435458 }
436459 }
437-
460+
461+ async assertDockerCompose ( step : Step , command : Command , result : RunResult ) {
462+ try {
463+ let assert = new Assertions ( )
464+ . noErrorCode ( result )
465+ . noException ( result ) ;
466+
467+ if ( command . parameters . length > 1 ) {
468+ if ( ! command . parameters [ 1 ] . startupTime ) {
469+ console . warn ( "No startup time for command dockerCompose has been set" )
470+ }
471+ let startupTimeInSeconds = command . parameters [ 1 ] . startupTime ? command . parameters [ 1 ] . startupTime : 0 ;
472+ await this . sleep ( command . parameters [ 1 ] . startupTime ) ;
473+
474+ if ( ! command . parameters [ 1 ] . port ) {
475+ this . killAsyncProcesses ( ) ;
476+ 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." ) ;
477+ } else {
478+ let isReachable = await assert . serverIsReachable ( command . parameters [ 1 ] . port , command . parameters [ 1 ] . path ) ;
479+ if ( ! isReachable ) {
480+ this . killAsyncProcesses ( ) ;
481+ throw new Error ( "The server has not become reachable in " + startupTimeInSeconds + " seconds: " + "http://localhost:" + command . parameters [ 1 ] . port + "/" + command . parameters [ 1 ] . path ) ;
482+ }
483+ }
484+ }
485+ } catch ( error ) {
486+ this . cleanUp ( ) ;
487+ throw error ;
488+ }
489+ }
490+
438491 async assertRunServerJava ( step : Step , command : Command , result : RunResult ) {
439492 try {
440493 let assert = new Assertions ( )
@@ -683,5 +736,6 @@ export class Console extends Runner {
683736 }
684737 }
685738
739+
686740
687- }
741+ }
0 commit comments