@@ -45,6 +45,7 @@ export function startBuildProcess(buildId: number, jobId: number,
4545 } , err => {
4646 observer . next ( { type : 'data' , data : err } ) ;
4747 observer . error ( err ) ;
48+ observer . complete ( ) ;
4849 stopContainer ( name ) . subscribe ( ( event : ProcessOutput ) => observer . next ( event ) ) ;
4950 } , ( ) => {
5051 observer . complete ( ) ;
@@ -55,40 +56,35 @@ export function startBuildProcess(buildId: number, jobId: number,
5556
5657function executeInContainer ( name : string , command : string ) : Observable < ProcessOutput > {
5758 return new Observable ( observer => {
58- let executed = false ;
5959 const start = nodePty . spawn ( 'docker' , [ 'start' , name ] ) ;
6060
6161 start . on ( 'exit' , ( ) => {
6262 let exitCode = 255 ;
63- const attach = nodePty . spawn ( 'docker' , [ 'attach' , '--detach-keys=D' , name ] ) ;
63+ let executed = false ;
64+ let attach = null ;
65+ let detachKey = null ;
66+
67+ if ( command . includes ( 'init.d' ) && command . includes ( 'start' ) ) {
68+ attach = nodePty . spawn ( 'docker' , [ 'attach' , '--detach-keys=D' , name ] ) ;
69+ detachKey = 'D' ;
70+ } else {
71+ attach = nodePty . spawn ( 'docker' , [ 'exec' , '-it' , '--privileged' , name , 'bash' , '-l' ] ) ;
72+ }
6473
6574 attach . on ( 'data' , data => {
66- data = data . toString ( ) ;
75+ const trimmed = data . trim ( ) ;
76+
6777 if ( ! executed ) {
6878 executed = true ;
69- attach . write ( command + ' && echo EXECOK || echo EXECNOK\r' ) ;
70- } else {
71- if ( ( data . includes ( 'EXECNOK' ) || data . includes ( 'EXECOK' ) ) && ! data . includes ( command ) ) {
72- if ( data . includes ( 'EXECOK' ) ) {
73- exitCode = 0 ;
74- }
75-
76- attach . write ( 'D' ) ;
77- return ;
78- }
79-
80- if ( data . includes ( '> read escape sequence' ) ) {
81- return ;
82- }
83-
84- if ( data . includes ( command ) ) {
85- data = bold ( yellow ( command ) ) + '\n' ;
86- }
87-
88- if ( ! data . trim ( ) . includes ( 'logout' ) && ! data . trim ( ) . includes ( 'exit' ) &&
89- ! data . trim ( ) . includes ( 'read escape sequence' ) ) {
90- observer . next ( { type : 'data' , data : data } ) ;
91- }
79+ attach . write ( command + ' && echo EXECOK || echo EXECNOK\r\n' ) ;
80+ observer . next ( { type : 'data' , data : bold ( yellow ( command ) ) + '\r\n' } ) ;
81+ } else if ( data . includes ( 'EXECOK' ) && ! data . includes ( command ) ) {
82+ exitCode = 0 ;
83+ attach . write ( detachKey ? detachKey : 'exit $?\r\n' ) ;
84+ } else if ( data . includes ( 'EXECNOK' ) && ! data . includes ( command ) ) {
85+ attach . write ( detachKey ? detachKey : 'exit $?\r\n' ) ;
86+ } else if ( ! data . includes ( command ) ) {
87+ observer . next ( { type : 'data' , data : data } ) ;
9288 }
9389 } ) ;
9490
0 commit comments