Просмотр исходного кода

Enhancements for createinstance

master
guest 3 лет назад
Родитель
Сommit
39e8284b55
1 измененных файлов: 48 добавлений и 20 удалений
  1. 48
    20
      index.js

+ 48
- 20
index.js Просмотреть файл

@@ -2269,7 +2269,7 @@ var eNotImplemented = function(){
}

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

@@ -2312,7 +2312,9 @@ var __acquireConfig = function (selected, owner, clusternodename, configrepo, er
return cli.prompt( choices
, '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 === 'f') return eNotImplemented()
if(propValue === 'o') return eNotImplemented()
@@ -3314,17 +3316,24 @@ const GIT = (function(){
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]

return any(cmdseq.map(getshelltask)).then(() => {
@@ -3334,18 +3343,22 @@ function createInstance(selectedinstance) {
else {
// 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
, username : selectedinstance.username, password : selectedinstance.password
, username : target.username, password : target.password
}
// , { 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( {
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}`}
)
}
)
@@ -3454,14 +3467,29 @@ var maintask = () => {
var e = { message : 'verifyAndInstall', success : true}
var inittasks = []
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 {
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;
console.error('Chosen cofiguraton failed or not found. Fix config and rerun or chose another.')
console.error(err)
}).then(() => { preworkerconfig(); return elxrworker(true) })
}).then( commantask )
// .finally(()=>{
// fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' })
// if(!e.success) fs.writeFileSync('run.done', 'error');

Загрузка…
Отмена
Сохранить