From afb9501e21e9adc02cba637afeb120b5e4dfcfdb Mon Sep 17 00:00:00 2001 From: William Mantly Date: Wed, 17 Dec 2025 13:59:45 -0500 Subject: [PATCH 1/2] Fix for wildcard certs --- nodejs/conf/production.js | 2 +- nodejs/controller/codeland.js | 2 +- nodejs/lib/codeland.js | 10 +- nodejs/public/lib/js/jq-repeat_new.js | 138 +++++++++++++++++++------- nodejs/views/runner.ejs | 2 +- 5 files changed, 107 insertions(+), 47 deletions(-) diff --git a/nodejs/conf/production.js b/nodejs/conf/production.js index 88dac39..7606a56 100644 --- a/nodejs/conf/production.js +++ b/nodejs/conf/production.js @@ -24,6 +24,6 @@ module.exports = { runnerTemplate: 'crunner0', memTarget: 15, minAvailableRunners: 10, - domian: 'prod.718it.codeland.us', + domian: 'cl-worker-3.718it.codeland.us', }, }; diff --git a/nodejs/controller/codeland.js b/nodejs/controller/codeland.js index 91e90b6..8df9cb1 100644 --- a/nodejs/controller/codeland.js +++ b/nodejs/controller/codeland.js @@ -42,7 +42,7 @@ const clworker = new CodelandController({ssh, ...conf.clworker}); clworker.__log('memory', await clworker.ssh.memory()) }catch{} }, 2000, clworker) - await clworker.deleteUntracedRunners(); + await clworker.deleteUntrackedRunners(); await clworker.runnerOven(10*1000); clworker.__log('df', (await clworker.ssh.df())['/']) diff --git a/nodejs/lib/codeland.js b/nodejs/lib/codeland.js index e2d6cbf..5fc2342 100644 --- a/nodejs/lib/codeland.js +++ b/nodejs/lib/codeland.js @@ -110,8 +110,6 @@ class CodeLandWorker{ instances. */ async init(){ - - this.runnerTemplate = await LXC.get({ name: this.runnerTemplate, execInstance: this.ssh @@ -129,7 +127,6 @@ class CodeLandWorker{ environment: conf.environment, }), 1000) - return this; } @@ -168,12 +165,13 @@ class CodeLandWorker{ } /* - getCurrentCopies and deleteUntracedRunners clean up zombie runners from + getCurrentCopies and deleteUntrackedRunners clean up zombie runners from old instances of Codeland */ async getCurrentCopies(){ let containers = await this.runnerTemplate.list(); let runners = {}; + for(let container of containers){ if(container.name.startsWith(this.runnerPrefix ) ){ if(container.name === this.runnerTemplate) continue; @@ -187,7 +185,7 @@ class CodeLandWorker{ return runners; } - async deleteUntracedRunners(){ + async deleteUntrackedRunners(){ for(let [name, runner] of Object.entries(await this.getCurrentCopies())){ if(!this.__runners[name]){ (async ()=>{ @@ -455,7 +453,7 @@ if (require.main === module){(async function(){try{ // await clworker.ssh.exec('bash ~/clean_crunners.sh'); - // await clworker.deleteUntracedRunners(); + // await clworker.deleteUntrackedRunners(); await clworker.runnerOven(); console.log('mem info:', await clworker.memory()) diff --git a/nodejs/public/lib/js/jq-repeat_new.js b/nodejs/public/lib/js/jq-repeat_new.js index 97f5871..9a4f32d 100644 --- a/nodejs/public/lib/js/jq-repeat_new.js +++ b/nodejs/public/lib/js/jq-repeat_new.js @@ -10,7 +10,7 @@ MIT license $.scope = {}; } - var make = function(element){ + var make = function(element, template){ var result = []; result.splice = function(inputValue, ...args){ @@ -82,7 +82,7 @@ MIT license //figure out new elements index var key = I + index; // apply values to template - var render = Mustache.render(this.__jqTemplate, toAdd[I]); + var render = Mustache.render(this.__jqTemplate, this.__buildData(i, toAdd[I])); //set call name and index keys to DOM element var $render = $( render ).addClass( 'jq-repeat-'+ this.__jqRepeatId ).attr( 'jq-repeat-index', key ); @@ -216,10 +216,8 @@ MIT license return []; } this[index] = $.extend( true, this[index], data ); - - console.log('this', this[index]) - var $render = $(Mustache.render(this.__jqTemplate, this[index])); + var $render = $(Mustache.render(this.__jqTemplate, this.__buildData(index, this[index]))); $render.attr('jq-repeat-index', index); this.__update(this[index].__jq_$el, $render, this[index], this); @@ -230,6 +228,8 @@ MIT license return this[this.indexOf(key, value)]; } + // User definable helper methods + result.__put = function($el, item, list){ $el.show(); }; @@ -243,37 +243,72 @@ MIT license $el.show(); }; - result.__setPut = function(fn) { - Object.defineProperty(this, '__put', { - value: fn, - writable: true, - enumerable: false, - configurable: true - }); - }; + result.__parseData = function(data){ + return data; + } - result.__setTake = function(fn) { - Object.defineProperty(this, '__take', { - value: fn, - writable: true, - enumerable: false, - configurable: true - }); + // internal helper methods + + result.__buildData = function(index, data){ + + return { + ...this.__parseData(data), + nestedTemplates: this.__parseNestedTemplates(index, data), + _parent: this.__jqParent ? $.scope[this.__jqParent][this.__jqParentIndex] : undefined, + }; }; - result.__setUpdate = function(fn) { - Object.defineProperty(this, '__update', { - value: fn, - writable: true, + result.__parseNestedTemplates = function(index, data){ + let templates = [] + let tempData = { + ...data, + _parent: data, + }; + + for(let idx in this.nestedTemplates){ + let $el = $(`${this.nestedTemplates[idx]}`); + + $el.attr('jq-repeat', Mustache.render($el.attr('jq-repeat'), tempData)); + $el.attr('jq-repeat-index', Mustache.render($el.attr('jq-repeat-index'), tempData)); + $el.attr('jq-repeat-parent', this.__jqRepeatId); + $el.attr('jq-repeat-parent-index', index); + templates[idx] = $el[0].outerHTML; + } + + return templates; + } + + for(let prop of ['put', 'take', 'update', 'parseData']){ + Object.defineProperty(result, prop, { enumerable: false, - configurable: true + get(){ + return this[`__${prop}`] + }, + set(value) { + this[`__${prop}`] = value; + }, }); - }; + } - var $this = $( element ); + var $this = $(element); + result.nestedTemplates = []; result.__jqRepeatId = $this.attr( 'jq-repeat' ); $this.removeAttr('jq-repeat'); result.__index = $this.attr('jq-repeat-index'); + + if($this.attr('jq-repeat-parent')){ + result.__jqParent = $this.attr('jq-repeat-parent'); + result.__jqParentIndex = $this.attr('jq-repeat-parent-index'); + } + + + $this.find('[jq-repeat]').each((idx, el)=>{ + let templateIdx = result.nestedTemplates.length; + let template = `${el.outerHTML}`; + result.nestedTemplates.push(template); + $(el).replaceWith(`{{{ nestedTemplates.${templateIdx} }}}`); + }); + result.__jqTemplate = $this[0].outerHTML; $this.replaceWith( '