Skip to content

Commit

Permalink
Finally docker works
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Sep 18, 2024
1 parent 3a2084f commit cbd4749
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
21 changes: 16 additions & 5 deletions src/executor/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class DockerExecutor {
} else {
throw new Error("Unknown ports format: " + name);
}
} else if (typeof port === 'object' && port.target && port.published) {
conf.published = port.published;
conf.target = port.target;
}
exposedPorts.push(conf.published);
service.ports[i] = conf;
Expand All @@ -121,26 +124,30 @@ class DockerExecutor {
nginxChanged = true;
}
let proxyPass = matchedConf.proxy_pass + "";
if (!proxyPass || !proxyPass.startsWith('docker:') || exposedPorts.includes(proxyPass.replace(/^docker:/, ''))) {
if (!proxyPass || !proxyPass.startsWith('docker:') || !exposedPorts.includes(proxyPass.replace(/^docker:/, ''))) {
if (exposedPorts.length == 0) {
throw new Error("There are no exposed ports! Need atleast one to forward it into NGINX");
}
matchedConf.proxy_pass = "docker:" + exposedPorts[exposedPorts.length - 1];
nginxChanged = true;
}
let nginxStatus = '';
if (nginxChanged) {
await nginxExec.setDirect(domain, nginx);
nginxStatus = await nginxExec.setDirect(domain, nginx);
} else {
nginxStatus = "Done unchanged";
}
return services;
return [services, nginxStatus];
}
/**
*
* @param {any} services
* @param {string} home
* @param {string} domain
* @param {(arg0: string) => Promise<void>} logWriter
* @return {Promise<string>}
*/
async executeServices(services, home, domain) {
async executeServices(services, home, domain, logWriter) {
let filename = path.join(home, 'docker-compose.yml');
let composeObject = {};
if (typeof services === 'string') {
Expand All @@ -156,7 +163,11 @@ class DockerExecutor {
} else {
composeObject.services = services;
}
composeObject.services = await this.rewriteServices(composeObject.services, domain);
let nginxStatus = '';
[composeObject.services, nginxStatus] = await this.rewriteServices(composeObject.services, domain);
if (logWriter) {
await logWriter(nginxStatus)
}
let composeFile = yaml.stringify(composeObject);
await executeLock('compose', () => {
return new Promise((resolve, reject) => {
Expand Down
22 changes: 10 additions & 12 deletions src/executor/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,21 @@ export default async function runConfig(config, domain, writer, sandbox = false)
let match = chunk.match(/\[.+?\@.+? .+?\]\$/);
if (match) {
cb = null;
chunk = chunk.replace(/\x1b.+?$/, '').trimEnd();
if (write && chunk) {
writer(chunk + "\n");
if (write) {
writer("\n");
}
resolve();
return true;
} else if (first && chunk.startsWith("<")) {
// stdin line skips
if (chunk.includes("\n")) {
first = false;
}
return false;
} else {
if (write && chunk) {
writer(chunk);
if (first) {
let pos = chunk.indexOf('\n');
if (pos >= 0) {
writer(chunk.substring(pos + 1));
}
} else {
writer(chunk);
}
}
first = false;
return false;
Expand Down Expand Up @@ -312,5 +312,3 @@ export default async function runConfig(config, domain, writer, sandbox = false)
}
}
}


3 changes: 2 additions & 1 deletion src/executor/runnersub.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,9 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec,
} else {
await sshExec(`docker compose --progress-plain quiet --remove-orphans --rmi all || true`);
}
await writeLog("$> Configuring NGINX forwarding for docker");
let d = await dockerExec.executeServices(config.services, subdomaindata['Home directory'] + '/public_html', subdomain, writeLog);
await writeLog("$> Writing docker compose services");
let d = await dockerExec.executeServices(config.services, subdomaindata['Home directory'] + '/public_html', subdomain);
await writeLog(d.split('\n').map(x => ` ${x}`).join('\n'));
await writeLog("$> Applying compose services");
if (typeof config.services == 'string') {
Expand Down

0 comments on commit cbd4749

Please sign in to comment.