Commit fe31d0fd authored by Ryan Kuba's avatar Ryan Kuba

#18 adding better console output that will combine messages about an image layer guid

parent 7e63b41a
Pipeline #15209105 passed with stage
in 6 minutes and 3 seconds
......@@ -5,6 +5,8 @@
const uuidv4 = require('uuid/v4');
const { spawn } = require('child_process');
const si = require('systeminformation');
var AU = require('ansi_up');
var ansi_up = new AU.default;
var nunjucks = require('nunjucks');
var yaml = require('js-yaml');
var request = require('request');
......@@ -210,7 +212,7 @@ io.on('connection', function(socket){
docker.pull(image, function(err, stream) {
docker.modem.followProgress(stream, onFinished, onProgress);
function onProgress(event) {
io.sockets.in(socket.id).emit('sendpulloutput', JSON.stringify(event));
io.sockets.in(socket.id).emit('sendpulloutput', event);
}
function onFinished(err, output) {
io.sockets.in(socket.id).emit('sendpulloutputdone', 'Finished Pull process for ' + image);
......@@ -309,10 +311,10 @@ io.on('connection', function(socket){
const composeup = spawn('unbuffer', composecommand);
composeup.stdout.setEncoding('utf8');
composeup.stdout.on('data', (data) => {
socket.emit('stackupdate',data);
io.sockets.in(socket.id).emit('stackupdate',ansi_up.ansi_to_html(data).trim());
});
composeup.on('close', (code) => {
socket.emit('stacklaunched','Compose up process exited with code ' + code);
io.sockets.in(socket.id).emit('stacklaunched','Compose up process exited with code ' + code);
containerinfo('updatestacks');
});
});
......@@ -473,7 +475,7 @@ io.on('connection', function(socket){
io.sockets.in(socket.id).emit('error_popup','Could not start Guacd');
}
else{
io.sockets.in(socket.id).emit('modal_finish','Guacd launched , Restarting server Please refresh');
io.sockets.in(socket.id).emit('modal_finish','Guacd launched , Restarting page will refresh in 5 seconds');
// Exit the application supervisor will restart
process.exit();
}
......
......@@ -51,6 +51,11 @@
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
},
"ansi_up": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/ansi_up/-/ansi_up-2.0.2.tgz",
"integrity": "sha1-m1TeUIxcV59baWjmXBuGPgaAq5I="
},
"anymatch": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.2.tgz",
......
......@@ -14,6 +14,7 @@
"license": "MIT",
"homepage": "http://taisun.io",
"dependencies": {
"ansi_up": "^2.0.2",
"crypto": "^1.0.1",
"docker-hub-api": "^0.5.1",
"dockerode": "^2.5.2",
......
......@@ -129,7 +129,7 @@
<div class="modal-body">
<div id="modalloading"><i class="fa fa-refresh fa-spin" style="font-size:36px"></i></div>
<div id="modalbody"></div>
<div id="modalconsole" style="white-space: pre-wrap; font-family:monospace;"></div>
<div id="modalconsole" style="font-family:monospace;background:black;color:white;"></div>
</div>
<div class="modal-footer" id="modalfooter"></div>
</div>
......
......@@ -70,7 +70,7 @@ socket.on('renderdash', function(response){
<i class="fa fa-server"></i>\
System Stats\
</div>\
<div class="card-body card-columns">\
<div class="card-body card-deck">\
<div class="card mb-3">\
<div class="card-header">\
<i class="fa fa-microchip"></i>\
......@@ -99,7 +99,7 @@ socket.on('renderdash', function(response){
</div>\
</div>\
</div>\
<div class="card-columns">\
<div class="card-deck">\
<div class="card mb-3" style="cursor:pointer;" onclick="renderstacks()">\
<div class="card-header">\
<i class="fa fa-cubes"></i>\
......@@ -115,7 +115,7 @@ socket.on('renderdash', function(response){
</div>\
</div>\
</div>\
<div class="card-columns">\
<div class="card-deck">\
<div class="card mb-3" style="cursor:pointer;" onclick="rendervdi()">\
<div class="card-header">\
<i class="fa fa-desktop"></i>\
......@@ -131,7 +131,7 @@ socket.on('renderdash', function(response){
</div>\
</div>\
</div>\
<div class="card-columns">\
<div class="card-deck">\
<div class="card mb-3" style="cursor:pointer;" onclick="renderremote()">\
<div class="card-header">\
<i class="fa fa-sitemap"></i>\
......@@ -301,12 +301,12 @@ $('body').on('click', '.guacdlaunch', function(){
// Parse output from the server on status of launching Guacd
socket.on('modal_update', function(message) {
$('#modalconsole').show();
$('#modalconsole').append(message + '\
');
$('#modalconsole').append('<div>' + message + '</div>');
});
socket.on('modal_finish', function(message) {
$('#modalloading').hide();
$('#modalconsole').append(message);
setTimeout(location.reload.bind(location), 5000);
$('#modalconsole').append('<div>' + message + '</div>');
});
// VDI Builder modal
function vdibuildermodal(){
......@@ -713,39 +713,43 @@ $('body').on('click', '.pullimage', function(){
});
// Show console output for pull
socket.on('sendpullstart', function(output) {
$('#modalbody').show();
$('#modalbody').append('<div>' + output + '</div>');
$('#modalconsole').show();
$('#modalconsole').append(output)
});
socket.on('sendpulloutput', function(output) {
$('#modalconsole').append(output);
var status = output.status;
if (output.hasOwnProperty("id")){
var uuid = output.id;
// If the Div exists we are going to be updating it
if ($('#' + uuid).length > 0) {
if (output.hasOwnProperty("progress")){
var progress = output.progress;
$('#' + uuid).empty();
$('#' + uuid).append(uuid + ' : ' + status + ' ' + progress);
}
else{
$('#' + uuid).empty();
$('#' + uuid).append(uuid + ' : ' + status);
}
}
// Div does not exist create it and put the data in it
else{
$('#modalconsole').append('<div id="' + uuid + '">' + uuid + ' : ' + status + '</div>');
}
}
else{
$('#modalconsole').append('<div>' + status + '</div>');
}
});
socket.on('sendpulloutputdone', function(output) {
$('#modalloading').hide();
$('#modalconsole').append(output);
$('#modalbody').append('<div>' + output + '</div>');
$('#modalfooter').show();
$('#modalfooter').append('\
<button type="button" class="btn btn-success" data-dismiss="modal">Close <i class="fa fa-check"></i></button>\
');
});
// Launch a single container (just console for now)
$('body').on('click', '.launchcontainer', function(){
socket.emit('sendlaunchcommand', $(this).attr("value"));
modalpurge();
$('#modaltitle').append('Launching ' + $(this).attr("value"));
$('#modalloading').show();
$('#modalconsole').show();
});
socket.on('container_update', function(output) {
$('#modalconsole').append(output);
});
socket.on('container_finish', function(output) {
$('#modalloading').hide();
$('#modalconsole').append(output);
$('#modalfooter').show();
$('#modalfooter').append('\
<button type="button" class="btn btn-success" data-dismiss="modal">Close <i class="fa fa-check"></i></button>\
');
});
//// Taisun Stacks Rendering
// Stacks Page
......@@ -1171,12 +1175,28 @@ $('body').on('click', '#createstack', function(){
});
// Show output from launch command
socket.on('stackupdate', function(data) {
$('#modalconsole').append(data);
// If this data has a docker guid in front of it then assign it to a div for updating
if (data.split(':')[0].length == 12){
var uuid = data.split(':')[0].toString();
// If div allready exists then just update it
if ($('#' + uuid).length > 0) {
$('#' + uuid).empty();
$('#' + uuid).append(data);
}
// Div does not exist create it and put the data in it
else{
$('#modalconsole').append('<div id="' + uuid + '">' + data + '</div>');
}
}
else{
$('#modalconsole').append('<div>' + data + '</div>');
}
});
// On finish remove spinner and add close button
socket.on('stacklaunched', function(data) {
$('#modalloading').hide();
$('#modalconsole').append(data);
$('#modalbody').show();
$('#modalbody').append(data);
$('#modalfooter').show();
$('#modalfooter').append('\
<button type="button" class="btn btn-success" data-dismiss="modal">Close <i class="fa fa-check"></i></button>\
......@@ -1264,7 +1284,6 @@ function rendergateway(data) {
<p> A chrome extension for using the web proxy can be found <a href="https://chrome.google.com/webstore/detail/taisun-connect/cfikmlkjcnlbabkghfcnakfcbgnokkpd" target="_blank">here</a></p><br>\
<table id="gatewaytable" class="table table-bordered">\
<tr><td>State</td><td>' + envars.State.Status + '</td></tr>\
<tr><th>Env Variable</th><th>Value</th></tr>\
</table>\
</div>\
</div>\
......@@ -1285,7 +1304,7 @@ function rendergateway(data) {
if (key == 'SQUIDPASS'){
$('#gatewaytable').append('<tr><td>' + key + '</td><td>***********</td></tr>');
}
else {
else if (key == 'DNSKEY' || key == 'SERVERIP' || key == 'SQUIDUSER' || key == 'EMAIL' ){
$('#gatewaytable').append('<tr><td>' + key + '</td><td>' + value + '</td></tr>');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment