From 5e4576a514d137fff1b29d5f6cdc8b3a0b08676e Mon Sep 17 00:00:00 2001 From: zeus Date: Tue, 5 Jan 2021 20:28:02 +0200 Subject: [PATCH] hybrid --- .gitignore | 1 + src-local/instance/swarmlab-sec | 1 + src-local/llo/new.js | 137 ++++++++++++------ .../mynetwork/availableservices.vue | 2 +- 4 files changed, 92 insertions(+), 49 deletions(-) create mode 160000 src-local/instance/swarmlab-sec diff --git a/.gitignore b/.gitignore index 4a3cd7b..9e835de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store node_modules +src-local/instance vimsession swarmlabdoc.js diff --git a/src-local/instance/swarmlab-sec b/src-local/instance/swarmlab-sec new file mode 160000 index 0000000..1f7e6b9 --- /dev/null +++ b/src-local/instance/swarmlab-sec @@ -0,0 +1 @@ +Subproject commit 1f7e6b9525bf44cb111d2bd27f3b975fd3b60828 diff --git a/src-local/llo/new.js b/src-local/llo/new.js index 58d4bd0..9001323 100644 --- a/src-local/llo/new.js +++ b/src-local/llo/new.js @@ -208,13 +208,48 @@ app.get('/getservicesstatus', (req, res, next) => { }); +function create_project(swarmlabname,project){ + var services_path = './instance/'+swarmlabname+'/'+project + fs.mkdir(services_path, { recursive: true }, (err) => { + + var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec create' + create = spawn(service_up, { + shell: true, + cwd: services_path, + //detached: true, + detached: false, + //stdio: [ 'ignore', logout, logerr ] + stdio: 'pipe' + }); + + create.stdout.on('data', function (data) { + var n = {} + n.data = data.toString() + io.emit('message_out', n); + }); + + create.stderr.on('data', function (data) { + var n = {} + n.data = data.toString() + io.emit('message_err', n); + }); + + create.on('close', function (code) { + var n = {} + n.data = code + io.emit('message_close', n); + }); + + }); +} let child = []; var ppid = '' io.on('connection', function(socket) { console.log('new connection'); socket.on('start', (value) => { + console.log('start') console.log('value '+JSON.stringify(value)) if(value.swarmlabname){ var service = value.swarmlabname @@ -241,8 +276,11 @@ REGISTRY_ADDR=localhost REGISTRY_PORT=5000 IMAGE_NAME=${service} SSH_PORT=${service_port} +TEST=${service} ` - fs.writeFileSync(ENV_service_file_path, ENV_service_file); + console.log('value1 '+JSON.stringify(ENV_service_file_path)) + console.log('value2 '+JSON.stringify(ENV_service_file)) + fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'w'}); var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size @@ -311,12 +349,38 @@ SSH_PORT=${service_port} socket.on('install', (value) => { if(value.swarmlabname){ + console.log('install') var service = value.swarmlabname var service_git = value.git var services_path = './instance/'+service var ENV_service_dir = services_path+'/'+service var ENV_service_file_path = services_path+'/'+service+'/'.env if (fs.existsSync(services_path)) { + const git = simpleGit( + { + baseDir: services_path, + maxConcurrentProcesses: 10 + }); + try { + git.pull() + .then((status) => { + var n = {} + n.data = 'Updated' + io.emit('message_out', n); + n.data = '...' + io.emit('message_close', n); + create_project(service,service) + }).catch((err) => { + var n = {} + n.data = err.toString() + io.emit('message_err', n); + console.log('error ' + JSON.stringify(err)) + }); + } catch (e) { + var n = {} + n.data = e.toString() + io.emit('message_err', n); + } }else{ fs.mkdir(services_path, { recursive: true }, (err) => { if (err){ @@ -326,65 +390,42 @@ SSH_PORT=${service_port} REGISTRY_ADDR=localhost REGISTRY_PORT=5000 IMAGE_NAME=${service} -SSH_PORT=${service_port} +SSH_PORT= ` - /* - const options: SimpleGitOptions = { - baseDir: process.cwd(), - binary: 'git', - maxConcurrentProcesses: 6, - }; - */ - const git = simpleGit() + const git = simpleGit( + { + baseDir: '.', + maxConcurrentProcesses: 10 + }); try { - git.init(); - git.addRemote('origin', service_git).then(result => { - var n = {} - n.data = result.toString() - io.emit('message_out', n); - }); - git.clone(service_git, services_path).then(result => { - var n = {} - n.data = result.toString() - io.emit('message_out', n); - }); + git.clone(service_git, services_path) + .then((status) => { + var n = {} + n.data = 'Installed' + io.emit('message_out', n); + n.data = '...' + io.emit('message_out', n); + fs.writeFileSync(ENV_service_file_path, ENV_service_file); + create_project(service,service) + }).catch((err) => { + var n = {} + n.data = err.toString() + io.emit('message_err', n); + console.log('error ' + JSON.stringify(err)) + }); } catch (e) { var n = {} n.data = e.toString() io.emit('message_err', n); } - //fs.writeFileSync(ENV_service_file_path, ENV_service_file); } }); } - /* - var services_path = './instance/'+service+'/'+service - var containerrm = '/bin/sh ./container-stop.sh '+id - const stop = spawn(containerrm, { - stdio: 'pipe', - shell: true, - cwd: services_path - }); - stop.stdout.on('data', function (data) { - var n = {} - n.data = data.toString() - io.emit('message_out', n); - }); - - stop.stderr.on('data', function (data) { - var n = {} - n.data = data.toString() - io.emit('message_err', n); - }); - - stop.on('close', function (code) { - var n = {} - n.data = code - io.emit('message_close', n); - }); - */ }else{ + var n = {} + n.data = 'no services' + io.emit('message_err', n); } }); diff --git a/src/components/mynetwork/availableservices.vue b/src/components/mynetwork/availableservices.vue index c018741..85bcb01 100644 --- a/src/components/mynetwork/availableservices.vue +++ b/src/components/mynetwork/availableservices.vue @@ -125,7 +125,7 @@