Skip to content

Commit

Permalink
String based nginx, one liner features, delegate pip progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Sep 17, 2024
1 parent cd9a3b0 commit 21c69d6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
31 changes: 22 additions & 9 deletions src/executor/nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
})
}
/**
Expand Down
5 changes: 4 additions & 1 deletion src/executor/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions src/executor/runnercode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/executor/runnersub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -282,15 +282,14 @@ 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');
await virtExec("generate-letsencrypt-cert", {
domain: subdomain,
'renew': 2,
'web': true,
'skip-dns-check': true,
});
subdomaindata['SSL cert expiry'] = new Date().toISOString()
}
Expand Down

0 comments on commit 21c69d6

Please sign in to comment.