Permalink
Browse files

feat(dockerode): dockerode integration

  • Loading branch information...
jkuri committed Sep 16, 2017
1 parent b713cba commit f581320199397a9c1382ffaa9ae954b73dcbed6d

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -82,7 +82,7 @@
"@types/dockerode": "^2.5.0",
"@types/express": "^4.0.37",
"@types/express-session": "^1.15.3",
"@types/jasmine": "^2.5.54",
"@types/jasmine": "^2.6.0",
"@types/jsonwebtoken": "^7.2.3",
"@types/knex": "0.0.61",
"@types/minimist": "^1.2.0",
@@ -148,10 +148,23 @@ export function killContainer(id: string): Promise<void> {
let container = null;
try {
container = docker.getContainer(id);
container.kill()
container.inspect()
.then(containerInfo => {
if (containerInfo.State.Running) {
return container.kill();
} else {
return Promise.resolve();
}
})
.then(() => container.remove())
.then(() => resolve())
.catch(err => reject(err));
.catch(err => {
if (err.statusCode === 404) {
resolve();
} else {
console.error(err);
}
});
} catch (e) {
resolve();
}
@@ -55,17 +55,22 @@ export class SocketServer {
return this.createRxSocket(data.conn);
})
.subscribe(conn => {
this.clients.push({ connection: conn, sub: null, session: this.connectingClient });
this.clients.push({
connection: conn,
sub: null,
session: this.connectingClient,
subs: []
});

const clientIndex = this.clients.length - 1;
let statsSubIndex = null;

// send server time for sync
conn.next({ type: 'time', data: new Date().getTime() });

// send client latest status about jobs
jobEvents.subscribe(event => conn.next(event));

// subscriptions
let statsSub: Subscription;

conn.subscribe(event => {
if (event.type === 'disconnected') {
const index = this.clients.findIndex(client => client.connection === conn);
@@ -171,14 +176,15 @@ export class SocketServer {
break;

case 'subscribeToStats':
statsSub = Observable.merge(...[memory(), cpu()])
.subscribe(event => conn.next(event));

this.clients[clientIndex].subs.push({ id: 'stats', sub: null });
statsSubIndex = this.clients[clientIndex].subs.length - 1;
this.clients[clientIndex].subs[statsSubIndex] =
Observable.merge(...[memory(), cpu()])
.subscribe(event => conn.next(event));
break;

case 'unsubscribeFromStats':
if (statsSub) {
statsSub.unsubscribe();
if (!this.clients[clientIndex].subs[statsSubIndex]) {
this.clients[clientIndex].subs[statsSubIndex].unsubscribe();
}
break;
}
@@ -53,6 +53,8 @@ export class AppJobComponent implements OnInit, OnDestroy {
this.loading = true;
this.terminalOptions = { size: 'large' };
this.id = null;
this.sshd = null;
this.vnc = null;
}

ngOnInit() {
@@ -98,9 +98,13 @@ export class AppTerminalComponent implements OnInit {
t = t ? parseFloat(<any>(<any>t / 10)).toFixed(0) : null;
let time = t && parseInt(<any>t, 10);

this.commands[this.commands.length - 1].time = time ? this.getDuration(time) : null;
if (this.commands[this.commands.length - 1]) {
this.commands[this.commands.length - 1].time = time ? this.getDuration(time) : null;
}
} else {
this.commands[this.commands.length - 1].output += output;
if (this.commands[this.commands.length - 1]) {
this.commands[this.commands.length - 1].output += output;
}
}
}

0 comments on commit f581320

Please sign in to comment.