Skip to content

Commit 2da8c56

Browse files
committed
fix(): multiple fixes
1 parent 37a0f78 commit 2da8c56

File tree

5 files changed

+40
-50
lines changed

5 files changed

+40
-50
lines changed

src/api/process.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5657
function 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

src/app/components/app-job/app-job.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, OnDestroy } from '@angular/core';
1+
import { Component, OnInit, OnDestroy, NgZone } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
33
import { ApiService } from '../../services/api.service';
44
import { SocketService } from '../../services/socket.service';
@@ -29,7 +29,8 @@ export class AppJobComponent implements OnInit, OnDestroy {
2929
constructor(
3030
private socketService: SocketService,
3131
private apiService: ApiService,
32-
private route: ActivatedRoute
32+
private route: ActivatedRoute,
33+
private ngZone: NgZone
3334
) {
3435
this.loading = true;
3536
this.status = 'queued';
@@ -49,7 +50,7 @@ export class AppJobComponent implements OnInit, OnDestroy {
4950
this.termSub = this.socketService.outputEvents
5051
.subscribe(event => {
5152
if (event.type === 'data') {
52-
this.terminalInput = event.data;
53+
this.ngZone.run(() => this.terminalInput = event.data);
5354
} else if (event.type === 'jobStopped' && event.data === this.id) {
5455
this.processing = false;
5556
} else if (event.type === 'jobRestarted' && event.data === this.id) {

src/app/components/app-setup/app-setup.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ <h2>
9191
Setting up docker image, please wait ...
9292
</div>
9393
<hr/>
94-
<app-terminal [data]="terminalInput" (outputData)="terminalOutput($event)" [options]="terminalOptions"></app-terminal>
94+
<app-terminal [data]="terminalInput" [options]="terminalOptions"></app-terminal>
9595
</div>
9696
<div *ngIf="step === 'done'">
9797
<div class="message green">

src/app/components/app-setup/app-setup.component.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ export class AppSetupComponent implements OnInit {
9797
this.loading = false;
9898
if (!exists) {
9999
this.step = 'docker';
100+
this.socketService.onMessage().subscribe(event => {
101+
if (event.type === 'terminalOutput') {
102+
if (event.data.type === 'exit') {
103+
if (event.data.data === 0) {
104+
this.step = 'done';
105+
}
106+
} else {
107+
this.terminalInput = event.data.data;
108+
}
109+
}
110+
});
111+
this.socketService.emit({ type: 'initializeDockerImage', data: 'abstruse' });
100112
} else {
101113
this.router.navigate(['/login']);
102114
}
@@ -112,24 +124,4 @@ export class AppSetupComponent implements OnInit {
112124
}
113125
});
114126
}
115-
116-
terminalOutput(e: any): void {
117-
if (e === 'ready') {
118-
this.socketService.onMessage().subscribe(event => {
119-
if (event.type === 'terminalOutput') {
120-
if (event.data.type === 'exit') {
121-
console.log(event.data);
122-
if (event.data.data === 0) {
123-
this.step = 'done';
124-
}
125-
} else {
126-
this.terminalInput = event.data.data;
127-
}
128-
}
129-
});
130-
this.socketService.emit({ type: 'initializeDockerImage', data: 'abstruse' });
131-
} else if (e && e.type && e.type === 'resize') {
132-
this.socketService.emit({ type: 'resize', data: { cols: e.cols, rows: e.rows }});
133-
}
134-
}
135127
}

src/app/styles/terminal.sass

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
border-radius: 4px
1212
box-shadow: 1px 2px 10px rgba($background, 0.7)
1313
border: 1px solid $divider
14+
overflow: hidden
1415

1516
&.large
1617
height: 700px

0 commit comments

Comments
 (0)