diff --git a/package-lock.json b/package-lock.json index 1221ed2..93bdf60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "domcloud-bridge", - "version": "0.57.0", + "version": "0.58.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "domcloud-bridge", - "version": "0.57.0", + "version": "0.58.0", "license": "MIT", "dependencies": { "cli": "^1.0.1", diff --git a/package.json b/package.json index fd20227..f1e1226 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "domcloud-bridge", - "version": "0.57.0", + "version": "0.58.0", "description": "Deployment runner for DOM Cloud", "main": "app.js", "engines": { diff --git a/src/executor/nginx.js b/src/executor/nginx.js index 4dcd37b..7a19d12 100644 --- a/src/executor/nginx.js +++ b/src/executor/nginx.js @@ -342,7 +342,7 @@ class NginxExecutor { set(domain, config) { return executeLock('nginx', async () => { await spawnSudoUtil('NGINX_GET', [domain]); - return await new Promise((resolve, reject) => { + const conf = await new Promise((resolve, reject) => { var src = cat(tmpFile).toString(); NginxConfFile.createFromSource(src, (err, conf) => { if (err) @@ -352,16 +352,29 @@ class NginxExecutor { return reject(new Error(`Cannot find domain ${domain}`)); } const info = this.extractInfo(node, domain); - info.config = config; - this.applyInfo(node, info); - writeTo(tmpFile, conf.toString()); - spawnSudoUtil('NGINX_SET', [domain]).then(() => { - resolve("Done updated\n" + node.toString()); - }).catch((err) => { - reject(err); - }) + if (typeof config === 'string') { + // experimental parse from string + new Promise((resolve, reject) => { + NginxConfFile.createFromSource(config, (err, rawConf) => { + if (err) + return reject(err); + const rawNode = rawConf.nginx.server?.[0] || rawConf.nginx; + const rawInfo = this.extractInfo(rawNode, domain); + info.config = rawInfo.config; + this.applyInfo(node, info); + resolve(conf); + }) + }).then(resolve).catch(reject); + } else { + info.config = config; + this.applyInfo(node, info); + resolve(conf); + } }); }); + writeTo(tmpFile, conf.toString()); + await spawnSudoUtil('NGINX_SET', [domain]); + return "Done updated\n" + conf.toString(); }) } /** diff --git a/src/executor/runner.js b/src/executor/runner.js index c600d11..0a2ee3e 100644 --- a/src/executor/runner.js +++ b/src/executor/runner.js @@ -51,6 +51,9 @@ export default async function runConfig(config, domain, writer, sandbox = false) } } await writeLog(`DOM Cloud runner v${getVersion()} ref ${getRevision()} in ${domain} at ${new Date().toISOString()}`); + if (typeof config.features === 'string') { + config.features = [config.features]; + } if (Array.isArray(config.features) && config.features.length > 0 && config.features[0].create && !sandbox) { // create new domain await writeLog("$> virtualmin create-domain"); @@ -280,7 +283,7 @@ export default async function runConfig(config, domain, writer, sandbox = false) } } await sshExec('unset HISTFILE TERM', false); // https://stackoverflow.com/a/9039154/3908409 - await sshExec(`export CI=true CONTINUOUS_INTEGRATION=true LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 PIP_PROGRESS_BAR=off`, false); + await sshExec(`export CI=true CONTINUOUS_INTEGRATION=true LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8`, false); await sshExec(`USERNAME='${domaindata['Username']}' PASSWORD='${domaindata['Password']}'`, false); const firewallOn = await firewallStatus(); if (config.subdomain) { diff --git a/src/executor/runnercode.js b/src/executor/runnercode.js index 9a43e98..19a39c3 100644 --- a/src/executor/runnercode.js +++ b/src/executor/runnercode.js @@ -53,7 +53,9 @@ export async function runConfigCodeFeatures(key, value, writeLog, domaindata, ss } else if (parg.version !== "system") { await sshExec(`pyenv install ${parg.version} -s`); } - await sshExec(`pyenv global ${parg.version.replace(":latest", "")} ; source ~/.bashrc`); + await sshExec(`pyenv global ${parg.version.replace(":latest", "")}`); + await sshExec(`[[ -z $PIP_PROGRESS_BAR ]] && echo "export PIP_PROGRESS_BAR=off" >> ~/.bashrc`) + await sshExec(`source ~/.bashrc`, false) await sshExec("python --version"); } break; @@ -73,10 +75,11 @@ export async function runConfigCodeFeatures(key, value, writeLog, domaindata, ss arg = "@" + value; } await writeLog("$> Changing Node engine to " + (value || 'lts')); - await sshExec("pathman add .local/opt/node/bin ; source ~/.config/envman/PATH.env"); + await sshExec("pathman add .local/opt/node/bin"); await sshExec(`curl -sS https://webinstall.dev/node${arg} | bash`); await sshExec("command -v corepack &> /dev/null || npm i -g corepack && corepack enable"); - await sshExec(`[[ -z $COREPACK_ENABLE_AUTO_PIN ]] && echo "COREPACK_ENABLE_AUTO_PIN=0" >> ~/.bashrc && source ~/.bashrc`) + await sshExec(`[[ -z $COREPACK_ENABLE_AUTO_PIN ]] && echo "export COREPACK_ENABLE_AUTO_PIN=0" >> ~/.bashrc`) + await sshExec("source ~/.bashrc", false); await sshExec("node --version"); } break; @@ -96,7 +99,8 @@ export async function runConfigCodeFeatures(key, value, writeLog, domaindata, ss } await writeLog("$> Changing Deno engine to " + (value || 'stable')); await sshExec(`curl -sS https://webinstall.dev/deno${arg} | bash`); - await sshExec("mkdir -p ~/.deno/bin/ && pathman add ~/.deno/bin/ ; source ~/.config/envman/PATH.env"); + await sshExec("mkdir -p ~/.deno/bin/ && pathman add ~/.deno/bin/"); + await sshExec("source ~/.bashrc", false); await sshExec("deno --version"); } break; diff --git a/src/executor/runnersub.js b/src/executor/runnersub.js index 3df44c5..f77c14a 100644 --- a/src/executor/runnersub.js +++ b/src/executor/runnersub.js @@ -230,7 +230,7 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec, let expectedSslMode = null; if (['off', 'always', 'on'].includes(value)) { expectedSslMode = value; - } else if (value == 'letsencrypt' || value == 'lets-encrypt') { + } else if (value == 'letsencrypt' || value == 'lets-encrypt' || value == 'renew') { regenerateSsl = true; } else if (value == 'selfsign' || value == 'self-sign') { selfSignSsl = true; @@ -282,7 +282,7 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec, // if force LE or remaining > 30 days, get fresh one if (!regenerateSsl && subdomaindata['Lets Encrypt renewal'] == 'Enabled' && (remaining > 30)) { await writeLog("$> SSL cert expiry is " + Math.trunc(remaining) + " days away so skipping renewal"); - await writeLog("$> To enforce renewal please use 'ssl lets-encrypt'"); + await writeLog("$> To enforce renewal please use 'ssl renew'"); } else { await writeLog("$> Generating SSL cert with Let's Encrypt"); await spawnSudoUtil('OPENSSL_CLEAN'); @@ -290,7 +290,6 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec, domain: subdomain, 'renew': 2, 'web': true, - 'skip-dns-check': true, }); subdomaindata['SSL cert expiry'] = new Date().toISOString() }