Kaynağa Gözat

manifest format detection and upgrade

pull/5/head
asasasasasas 3 yıl önce
ebeveyn
işleme
5cb5bbd334
1 değiştirilmiş dosya ile 57 ekleme ve 43 silme
  1. 57
    43
      index.js

+ 57
- 43
index.js Dosyayı Görüntüle

@@ -148,7 +148,7 @@ var getPullCmd = (repo, branch) => {
, { cwd: instanceroot + '/' + repo, title : 'pull all origins for ' + branch + ' ' + repo + ' ' + parameters.join(' ') }]
}
else {
console.warn('No branch was specified detecting from working client.')
// console.warn('No branch was specified detecting from working client.')
// First check if working client exits.
// if (existsSync(instanceroot + '/' + repo)) {
var pullCmd = gitops.getdiscoverbranchcmd(repo)
@@ -258,7 +258,6 @@ var acquireElevationState = () => {
}


var repomanifest = null;
var currentGitAuthUser; // nodeShellExec('git', ['config', 'user.email']) ... PB : TODO-- get the current gittea username
var defaultRepoOwner = 'chess';
var elevatedRunasRepos = null
@@ -282,7 +281,6 @@ var dbForLabel = function (label) {
var gitbash = "C:\\Program Files\\Git\\bin\\sh.exe"
// var gitbash = "G:\\Installed\\Git\\bin\\sh.exe"
// Relevant git repos
// var repomanifest = require('../'+repomanifest.instanceName+'-config-'+ nodeenv +'/repo-manifest')()
var exludeMergeRepos = [];
var useGitPull = processedArgs.useGitPull || false;
var configPromise = null
@@ -1279,12 +1277,12 @@ var op = {
4) Iterates all repos and checkout to the ENV specified. 'git', ['checkout', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV]
5) Iterates all repos and merge from source configured in mergesource. 'git', ['merge', mergesource],
*/
var runconfig = { NODE_ENV: repomanifest.node_env }
var runconfig = { NODE_ENV: selectedinstance.node_env }
try { runconfig = Object.assign(runconfig, require(instanceroot + '/run.js')) } catch (e) { }
// We no longer need to check ruans.. ??? if we were initiated from self invoked privileged shell ?
if (( /*processedArgs.runas && processedArgs.runas !== 'self' &&*/ !processedArgs.force) &&
runconfig.NODE_ENV && runconfig.NODE_ENV === (repomanifest.node_env || runconfig.NODE_ENV) &&
repomanifest.instanceName && runconfig.use === repomanifest.instanceName) {
runconfig.NODE_ENV && runconfig.NODE_ENV === (selectedinstance.node_env || runconfig.NODE_ENV) &&
selectedinstance.instanceName && runconfig.use === selectedinstance.instanceName) {

console.log(`No change detected. Already using requested specs : ${runconfig.NODE_ENV} ${runconfig.use}`)
if (processedArgs.runas) { fs.writeFileSync('run.done', 'success') }
@@ -1699,8 +1697,8 @@ var elxr = {


def = def || {
repos : repomanifest.repos,
elevated : repomanifest.elevated
repos : selectedinstance.repos,
elevated : selectedinstance.elevated
}

var elevatedpulltasks = null;
@@ -1769,13 +1767,13 @@ var elxr = {

function preworkerconfig(){
// Everything runs after this check is completed. Elevation occurs out of process when needed.
gitRepos = repomanifest.repos
gitRepos = selectedinstance.repos
// gitRepos = ['chess-server-lib'];
// Repositiories that have symlinks that require elevated priviletes in windows to create symlinks
elevatedRunasRepos = repomanifest.elevated
elevatedRunasRepos = selectedinstance.elevated
// Repos that should excluded from merge for releases...
exludeMergeRepos = repomanifest.exludeMergeRepos
exludeMergeRepos = selectedinstance.exludeMergeRepos

// mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' ) > drop_all_tables.sql
// mysql -u root -p db_name < drop_all_tables.sql
@@ -1805,14 +1803,6 @@ function elxrworker() {
else return __runcmd(processedArgs.label || processedArgs._[0] || 'h');
}

var getManifest = function () {
// Once choices are made we need to load config according to those choices.

// No trace of a previous run...
// Default Config...
return repomanifest = selectedinstance;
}

function acquireChoices(selectedinstance) {

var hasconfig = false;
@@ -1852,8 +1842,6 @@ We will run your choice at the next prompt.
selectedinstance.instanceName = processedArgs._[1] = processedArgs._[1] || 'chess'
selectedinstance.node_env = processedArgs.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env || 'development'
selectedinstance.reposerver = 'https://git.bbh.org.in'
getManifest() // PB : TODO -- acquire the manifest directly from http url instead of clone before cloning the config. Since
// This is because the manifest at any server location can redirect to the preferred server..
}
else if (choice === 'h') {
processedArgs._[0] = 'h'
@@ -1931,25 +1919,26 @@ var cacheWriteInstanceConfig = function(chessinstances){
fs.writeFileSync(instanceroot + '/chessinstances.js', 'module.exports = ' + JSON.stringify(chessinstances, null, 2) + '', { 'flag': 'w' })
}

var acquireConfig = function (selected, chessinstances) {
var acquireConfig = function (selected) {

var configrepo = selected.instanceName + '-config-' + selected.node_env;

return performPull(configrepo).then(() => {
var manifestpath = path.normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest');
repomanifest = require(manifestpath)()
chessinstances = chessinstances || {};
chessinstances[selected.instanceName] = chessinstances[selected.instanceName] || {}
chessinstances[selected.instanceName][selected.node_env] = chessinstances[selected.instanceName][selected.node_env] || {}
chessinstances['current_run'] = { instanceName: selected.instanceName, node_env: selected.node_env }
selectedinstance = require(manifestpath)()
// Config from server always override merges into selection ecept for the current selection.
// PB : TODO -- utils.assign Array merges are non-distinct...
selectedinstance = utils.assign(chessinstances[selected.instanceName][selected.node_env], selected, repomanifest)
// chessinstances[selectedinstance.instanceName][selectedinstance.node_env] = selectedinstance;
cacheWriteInstanceConfig(chessinstances)
selectedinstance = chessinstances[selected.instanceName][selected.node_env]
// PB : TODO -- We should probably write the new server config also...
if(!selectedinstance.repos[0].repo) {
console.warn('repo manifest has obsolete format. Attempting upgrade.')
selectedinstance.repos = selectedinstance.repos.map(function(repo){ return { repo } })
}
if(selectedinstance.elevated[0] && !selectedinstance.elevated[0].repo) {
console.warn('elevated repo manifest has obsolete format. Attempting upgrade.')
selectedinstance.elevated = selectedinstance.elevated.map(function(repo){ return { repo } })
}
chessinstances[selected.instanceName][selected.node_env] = selectedinstance = utils.assign(selected, selectedinstance)
selectedinstance.reposerver = selectedinstance.reposerver || selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online...
cacheWriteInstanceConfig(chessinstances)
ENV.NODE_ENV = selectedinstance.node_env;
})
.catch((e) => {
@@ -2317,20 +2306,45 @@ var chessinstances = { current_run : {} };
acquireElevationState().then(() => {
var skipprerequisites = false;
var clioverrides = { }
function initinstances(chessinstances, selected) {
chessinstances.current_run.instanceName = processedArgs._[1] = processedArgs._[1] || chessinstances.current_run.instanceName || selected.instanceName;
chessinstances.current_run.node_env = processedArgs.node_env = processedArgs.node_env || chessinstances.current_run.node_env || selected.node_env;
chessinstances[chessinstances.current_run.instanceName] = chessinstances[chessinstances.current_run.instanceName] || {}
function initinstances(selected) {
// PB : TODO -- processedArgs should already be part of selected.
var instanceName = processedArgs._[1] = processedArgs._[1] || chessinstances.current_run.instanceName || selected.instanceName;
var node_env = processedArgs.node_env = processedArgs.node_env || chessinstances.current_run.node_env || selected.node_env;
chessinstances['current_run'] = chessinstances[instanceName][selected.node_env] ?
{ instanceName: instanceName, node_env: node_env } : chessinstances['current_run']
// chessinstances[chessinstances.current_run.instanceName] = chessinstances[chessinstances.current_run.instanceName] || {}

if(path.normalize(selected.root) !== path.normalize(chessinstances[instanceName][node_env].root)) {
throw "Mismatched chessinstances config found " + chessinstances[instanceName][node_env].root + ' does not match ' + selected.root
}
// Override sequence.
// __default, chessinstances[current_run], instanceName-config-development, cliargs, interactve_promts
selectedinstance = Object.assign(
selected
, chessinstances[chessinstances.current_run.instanceName][chessinstances.current_run.node_env]
, chessinstances[instanceName][node_env]
, clioverrides
// , __interactve_promts -- Cant just override. Also need selectedinstance to be ready...
);
repomanifest = selectedinstance

chessinstances[instanceName] = chessinstances[instanceName] || {}
chessinstances[instanceName][node_env] = chessinstances[instanceName][node_env] || {}
if(!selectedinstance.repos[0].repo) {
console.warn('repo manifest has obsolete format. Attempting upgrade.')
selectedinstance.repos = selectedinstance.repos.map(function(repo){ return { repo } })
}
if(selectedinstance.elevated[0] && !selectedinstance.elevated[0].repo) {
console.warn('elevated repo manifest has obsolete format. Attempting upgrade.')
selectedinstance.elevated = selectedinstance.elevated.map(function(repo){ return { repo } })
}
// Config from server always override merges into selection except for the current selection.
// PB : TODO -- utils.assign Array merges are non-distinct...
chessinstances[instanceName][node_env] = selectedinstance = utils.assign(selected, selectedinstance)
// chessinstances[selectedinstance.instanceName][selectedinstance.node_env] = selectedinstance;
cacheWriteInstanceConfig(chessinstances)
// PB : TODO -- We should probably write the new server config also...
selectedinstance.reposerver = selectedinstance.reposerver || selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online...

return chessinstances
}
function acquirelocalinstances(selected){
@@ -2348,14 +2362,14 @@ acquireElevationState().then(() => {
// Default cmd to run !
processedArgs._[0] === processedArgs._[0] || 'pull';
// selectedinstance.reposerver = repomanifest.reposervers[0] // PB : TODO -- Attempt first one that is available and online from all that are available...
// selectedinstance.reposerver = selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online from all that are available.
if(!noprerequisites[processedArgs._[0]]
&& !skipprereqs[processedArgs._[0]]
) {
return prerequisites.git.verifyAndInstall().then(()=>{
var e = { message : 'verifyAndInstall', success : true}
return acquireConfig(selectedinstance, chessinstances).catch((err) => {
return acquireConfig(selectedinstance).catch((err) => {
e = err;
console.error('Chosen cofiguraton failed or not found. Fix config and rerun or chose another.')
console.error(err)
@@ -2418,7 +2432,7 @@ acquireElevationState().then(() => {
}
try {
chessinstances = acquirelocalinstances(selectedinstance);
initinstances(chessinstances, selectedinstance)
initinstances(selectedinstance)
var instanceNameChoices = new Set(Object.keys( chessinstances) )
instanceNameChoices.delete('current_run')
@@ -2441,7 +2455,7 @@ acquireElevationState().then(() => {
catch (e) {
console.error(e) // Missing chessinstances is not an error...
initinstances(chessinstances, selectedinstance)
initinstances(selectedinstance)
var instanceNameChoices = new Set(Object.keys( chessinstances) )
instanceNameChoices.delete('current_run')
@@ -2466,7 +2480,7 @@ acquireElevationState().then(() => {
todo = todo.then(() => {
try {
chessinstances = acquirelocalinstances(selectedinstance)
initinstances(chessinstances, selectedinstance)
initinstances(selectedinstance)
}
catch (e) {
console.error(e)

Loading…
İptal
Kaydet