Skip to content

Commit

Permalink
fixes issue with docker compose not working because it requires a tty
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDiggles2 committed May 5, 2023
1 parent de2d1e4 commit 9276f4c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
32 changes: 30 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mrdiggles2/mux",
"version": "1.0.0",
"version": "1.0.1",
"bin": "main.js",
"scripts": {
"start": "MUX_DEV_MODE=true ts-node src/main.ts start",
Expand All @@ -14,6 +14,7 @@
"license": "MIT",
"dependencies": {
"chalk": "^4.1.0",
"node-pty": "^0.10.1",
"tail": "^2.2.6",
"terminal-kit": "^3.0.0",
"tree-kill": "^1.2.2",
Expand Down
30 changes: 9 additions & 21 deletions src/process.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { ChildProcess, spawn } from "child_process";
import path from "path";
import fs from 'fs';
import { Tail } from "tail";
import treeKill from "tree-kill";
import { MuxCommand, MuxProcessConfig, MuxLogger, MuxConfig } from "./config";
export namespace Mux {
export const hello = 'foo';
}
import { IPty, spawn } from 'node-pty';

export class MuxProcess {
public name: string;

private children: ChildProcess[] = [];
private children: IPty[] = [];
private logPath?: string;
private startPromise?: Promise<number>;

Expand Down Expand Up @@ -66,7 +64,7 @@ export class MuxProcess {
await this.startPromise;
}

private getLogPath(): string {
public getLogPath(): string {
if (!this.logPath) {
const logDir = path.join(this.muxConfig.rootDir, this.muxConfig.logPath);
fs.mkdirSync(logDir, { recursive: true });
Expand Down Expand Up @@ -104,35 +102,25 @@ export class MuxProcess {
});

const bin = "sh";
const args = ['-c', `'cd ${cwd} && ${exec}'`];
const args = ['-c', `cd ${cwd} && ${exec}`];

this.logger.info(`${this.name}: Executing "${bin} ${args.join(' ')}"`);
this.logger.debug(`${this.name}: Environtment variables: ${JSON.stringify(env)}`)

const child = spawn(bin, args, {
shell: true,
env: {
...process.env,
...env
},
});

child.stdout.on('data', (data: Buffer) => {
fs.appendFileSync(logFile, data);
});

child.stderr.on('data', (data: Buffer) => {
child.onData((data: string) => {
fs.appendFileSync(logFile, data);
});

child.on('exit', (code) => {
fs.appendFileSync(logFile, `exited with code ${code}`);
resolver(code);
})

child.on('close', (code) => {
fs.appendFileSync(logFile, `exited with code ${code}`);
resolver(code);
child.onExit(({ exitCode }) => {
fs.appendFileSync(logFile, `exited with code ${exitCode}`);
resolver(exitCode);
});

this.children.push(child);
Expand Down
2 changes: 1 addition & 1 deletion src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class MuxUI {
const failedProcesses = results.filter(({ exitCode }) => exitCode !== 0);
if (failedProcesses.length > 0) {
failedProcesses.forEach(({exitCode, process}) => {
this.logger.error(`process "${process.name}" failed to install. Exited with code ${exitCode}`);
this.logger.error(`process "${process.name}" failed to install (exit code ${exitCode}).\nSee logs for more details: ${process.getLogPath()}`);
});

throw new Error('Installation failed');
Expand Down

0 comments on commit 9276f4c

Please sign in to comment.