Permalink
Browse files

fix(): multiple fixes

  • Loading branch information...
jkuri committed Aug 2, 2017
1 parent 37a0f78 commit 2da8c56f7b7dc66f332825cc9f10205d49729cde
@@ -45,6 +45,7 @@ export function startBuildProcess(buildId: number, jobId: number,
}, err => {
observer.next({ type: 'data', data: err });
observer.error(err);
observer.complete();
stopContainer(name).subscribe((event: ProcessOutput) => observer.next(event));
}, () => {
observer.complete();
@@ -55,40 +56,35 @@ export function startBuildProcess(buildId: number, jobId: number,

function executeInContainer(name: string, command: string): Observable<ProcessOutput> {
return new Observable(observer => {
let executed = false;
const start = nodePty.spawn('docker', ['start', name]);

start.on('exit', () => {
let exitCode = 255;
const attach = nodePty.spawn('docker', ['attach', '--detach-keys=D', name]);
let executed = false;
let attach = null;
let detachKey = null;

if (command.includes('init.d') && command.includes('start')) {
attach = nodePty.spawn('docker', ['attach', '--detach-keys=D', name]);
detachKey = 'D';
} else {
attach = nodePty.spawn('docker', ['exec', '-it', '--privileged', name, 'bash', '-l']);
}

attach.on('data', data => {
data = data.toString();
const trimmed = data.trim();

if (!executed) {
executed = true;
attach.write(command + ' && echo EXECOK || echo EXECNOK\r');
} else {
if ((data.includes('EXECNOK') || data.includes('EXECOK')) && !data.includes(command)) {
if (data.includes('EXECOK')) {
exitCode = 0;
}

attach.write('D');
return;
}

if (data.includes('> read escape sequence')) {
return;
}

if (data.includes(command)) {
data = bold(yellow(command)) + '\n';
}

if (!data.trim().includes('logout') && !data.trim().includes('exit') &&
!data.trim().includes('read escape sequence')) {
observer.next({ type: 'data', data: data });
}
attach.write(command + ' && echo EXECOK || echo EXECNOK\r\n');
observer.next({ type: 'data', data: bold(yellow(command)) + '\r\n' });
} else if (data.includes('EXECOK') && !data.includes(command)) {
exitCode = 0;
attach.write(detachKey ? detachKey : 'exit $?\r\n');
} else if (data.includes('EXECNOK') && !data.includes(command)) {
attach.write(detachKey ? detachKey : 'exit $?\r\n');
} else if (!data.includes(command)) {
observer.next({ type: 'data', data: data });
}
});

@@ -1,4 +1,4 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Component, OnInit, OnDestroy, NgZone } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ApiService } from '../../services/api.service';
import { SocketService } from '../../services/socket.service';
@@ -29,7 +29,8 @@ export class AppJobComponent implements OnInit, OnDestroy {
constructor(
private socketService: SocketService,
private apiService: ApiService,
private route: ActivatedRoute
private route: ActivatedRoute,
private ngZone: NgZone
) {
this.loading = true;
this.status = 'queued';
@@ -49,7 +50,7 @@ export class AppJobComponent implements OnInit, OnDestroy {
this.termSub = this.socketService.outputEvents
.subscribe(event => {
if (event.type === 'data') {
this.terminalInput = event.data;
this.ngZone.run(() => this.terminalInput = event.data);
} else if (event.type === 'jobStopped' && event.data === this.id) {
this.processing = false;
} else if (event.type === 'jobRestarted' && event.data === this.id) {
@@ -91,7 +91,7 @@ <h2>
Setting up docker image, please wait ...
</div>
<hr/>
<app-terminal [data]="terminalInput" (outputData)="terminalOutput($event)" [options]="terminalOptions"></app-terminal>
<app-terminal [data]="terminalInput" [options]="terminalOptions"></app-terminal>
</div>
<div *ngIf="step === 'done'">
<div class="message green">
@@ -97,6 +97,18 @@ export class AppSetupComponent implements OnInit {
this.loading = false;
if (!exists) {
this.step = 'docker';
this.socketService.onMessage().subscribe(event => {
if (event.type === 'terminalOutput') {
if (event.data.type === 'exit') {
if (event.data.data === 0) {
this.step = 'done';
}
} else {
this.terminalInput = event.data.data;
}
}
});
this.socketService.emit({ type: 'initializeDockerImage', data: 'abstruse' });
} else {
this.router.navigate(['/login']);
}
@@ -112,24 +124,4 @@ export class AppSetupComponent implements OnInit {
}
});
}

terminalOutput(e: any): void {
if (e === 'ready') {
this.socketService.onMessage().subscribe(event => {
if (event.type === 'terminalOutput') {
if (event.data.type === 'exit') {
console.log(event.data);
if (event.data.data === 0) {
this.step = 'done';
}
} else {
this.terminalInput = event.data.data;
}
}
});
this.socketService.emit({ type: 'initializeDockerImage', data: 'abstruse' });
} else if (e && e.type && e.type === 'resize') {
this.socketService.emit({ type: 'resize', data: { cols: e.cols, rows: e.rows }});
}
}
}
@@ -11,6 +11,7 @@
border-radius: 4px
box-shadow: 1px 2px 10px rgba($background, 0.7)
border: 1px solid $divider
overflow: hidden

&.large
height: 700px

0 comments on commit 2da8c56

Please sign in to comment.