Browse Source

Enhancements for createinstance

master
guest 3 years ago
parent
commit
39e8284b55
1 changed files with 48 additions and 20 deletions
  1. 48
    20
      index.js

+ 48
- 20
index.js View File

} }


var acquireConfig = function(slections){ var acquireConfig = function(slections){
var configPriority = [ 'clusterNodeInstance', 'ownerInstnace', 'commonInstance', 'genericChessInstance' ]
var configPriority = [ 'clusterNodeInstance', 'ownerInstnace', 'commonInstance' /*, 'genericChessInstance'*/ ]
return any(configPriority.map(cfg => { return function() { return configs[cfg](slections) } } ), true, true) return any(configPriority.map(cfg => { return function() { return configs[cfg](slections) } } ), true, true)
} }


return cli.prompt( choices return cli.prompt( choices
, 'Config for instance not found. Would you like to ', 'e' ).then(propValue => { , 'Config for instance not found. Would you like to ', 'e' ).then(propValue => {
if(propValue === 't') return createInstance()
if(propValue === 't') {
selectedinstance.local = true; return createInstance(selectedinstance)
}
if(propValue === 'i') return eNotImplemented() if(propValue === 'i') return eNotImplemented()
if(propValue === 'f') return eNotImplemented() if(propValue === 'f') return eNotImplemented()
if(propValue === 'o') return eNotImplemented() if(propValue === 'o') return eNotImplemented()
return GIT return GIT
})(); })();


function createInstance(selectedinstance) {
function createInstance(target, source) {


console.dir(selectedinstance)
if(selectedinstance.local) {
selectedinstance
var args = {
remotebase : selectedinstance.reposerver + '/chess/'
, sourcerepo : 'chess-config'
, targetrepo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`
}
var sourceinstance = source || target;
console.dir(sourceinstance)
var args = {
remotebase : sourceinstance.reposerver + '/chess/'
, sourcerepo : sourceinstance.repo || 'chess-config'
, targetrepo : `${target.instanceName}-config-${target.instanceType}${target.nodeName ? ('-' + target.nodeName) : ''}`
}

if(sourceinstance.local) {


var options = {
inherit: true, shell: true,
env: process.env
, cwd : instanceroot
, runas: processedArgs.runas
}
cmdseq = ['git', ['clone', `${args.remotebase}${args.sourcerepo}`, `${args.targetrepo}`], options] cmdseq = ['git', ['clone', `${args.remotebase}${args.sourcerepo}`, `${args.targetrepo}`], options]


return any(cmdseq.map(getshelltask)).then(() => { return any(cmdseq.map(getshelltask)).then(() => {
else { else {
// http://try.gitea.io/api/v1/org/{org}/repos // http://try.gitea.io/api/v1/org/{org}/repos
var server = new URL(selectedinstance.reposerver);
if(source.reposerver !== target.reposerver && source.username !== target.username) {
throw 'createInstance is possible only within the same repository server.'
}

var server = new URL(target.reposerver);
return GITEA.repository.fork( { hostname : server.host, protocol : server.protocol return GITEA.repository.fork( { hostname : server.host, protocol : server.protocol
, username : selectedinstance.username, password : selectedinstance.password
, username : target.username, password : target.password
} }
// , { repo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`} // , { repo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`}
, { repo : `chess-config`, owner : 'chess' }, {}, function( repository ){
, { repo : `${args.sourcerepo}`, owner : `${target.username}` }, {}, function( repository ){
return GITEA.repository.updateattributes( { return GITEA.repository.updateattributes( {
hostname : server.host, protocol : server.protocol hostname : server.host, protocol : server.protocol
, username : selectedinstance.username, password : selectedinstance.password
, username : target.username, password : target.password
} }
, { repo : `chess-config`, owner : selectedinstance.username }
, { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`}
, { repo : `${args.sourcerepo}`, owner : `${target.username}` }
, { name : `${args.targetrepo}`}
) )
} }
) )
var e = { message : 'verifyAndInstall', success : true} var e = { message : 'verifyAndInstall', success : true}
var inittasks = [] var inittasks = []
if(!detection_state.localInstanceDetected) { if(!detection_state.localInstanceDetected) {
inittasks.push(createInstance(selectedinstance).then(() => { preworkerconfig(); return elxrworker(true) }))
var specifictask = ()=>{ return createInstance(selectedinstance) }
var commantask = () => { preworkerconfig(); return elxrworker(true) }
if(!__isElevated) {
}
else {
specifictask = ()=>{ Promise.resolve(true) }
}
inittasks.push(specifictask().then( commantask ))
} }
else { else {
inittasks.push(acquireConfig(selectedinstance).catch((err) => {
var specifictask = ()=>{ return acquireConfig(selectedinstance) }
var commantask = () => { preworkerconfig(); return elxrworker(true) }
if(!__isElevated) {
}
else {
specifictask = ()=>{ Promise.resolve(true) }
}
inittasks.push( specifictask().catch((err) => {
e = err; e = err;
console.error('Chosen cofiguraton failed or not found. Fix config and rerun or chose another.') console.error('Chosen cofiguraton failed or not found. Fix config and rerun or chose another.')
console.error(err) console.error(err)
}).then(() => { preworkerconfig(); return elxrworker(true) })
}).then( commantask )
// .finally(()=>{ // .finally(()=>{
// fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' }) // fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' })
// if(!e.success) fs.writeFileSync('run.done', 'error'); // if(!e.success) fs.writeFileSync('run.done', 'error');

Loading…
Cancel
Save