Browse Source

hybrid

master
zeus 3 years ago
parent
commit
5e4576a514
  1. 1
      .gitignore
  2. 1
      src-local/instance/swarmlab-sec
  3. 137
      src-local/llo/new.js
  4. 2
      src/components/mynetwork/availableservices.vue

1
.gitignore

@ -1,5 +1,6 @@
.DS_Store
node_modules
src-local/instance
vimsession
swarmlabdoc.js

1
src-local/instance/swarmlab-sec

@ -0,0 +1 @@
Subproject commit 1f7e6b9525bf44cb111d2bd27f3b975fd3b60828

137
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);
}
});

2
src/components/mynetwork/availableservices.vue

@ -125,7 +125,7 @@
<button
v-if="testactionrowindex[props.rowData.swarmlabname] != props.rowIndex && testactionrowindex[props.rowIndex] == props.rowIndex"
class="ti-thumb-down btn btn-secondary btn-sm"
title="Stop Lan_Instance"
title="Start Lan_Instance"
round
@click="onAction('run-item', props.rowData, props.rowIndex)"
>

Loading…
Cancel
Save