Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output ends up in "err" instead of "out" on macos even when exitCode equals 0 #252

Open
frankforpresident opened this issue Sep 7, 2023 · 8 comments

Comments

@frankforpresident
Copy link

When using this package on mac os I've noticed that the output of the command "compose.upAll()" returns an object where exitCode equals 0 and the content ends up in the err instead of out

{
  exitCode: 0,
  err: " Container first  Created\n Container second  Created\n Container third  Created\n Container first  Starting\n Container first  Started\n Container second  Starting\n Container second  Started\n Container third  Starting\n Container third  Started\n",
  out: "",
}

The containers start perfectly and seem the be fine.

When breaking in the code I do see childProc.stderr event handler is emitting chunks. See: line:204

I'm running on mac os 13.5.1 (22G90)
package version: ^0.24.2
node version: v18.17.1

docker-compose I've used to test this package

version: '3'
services:
  first:
    container_name: first
    image: hello-world:latest
  second:
    container_name: second
    image: hello-world:latest
    depends_on:
      - first
  third:
    container_name: third
    image: hello-world:latest
    depends_on:
      - second
@AlexZeitler
Copy link
Contributor

This is by design as the underlying docker compose / docker-compose command line tool is responsible for where the output is routed to.

Took me a while when creating this library to find this out.

@AlexZeitler
Copy link
Contributor

See this issue for example: docker/compose#7346

@AlexZeitler
Copy link
Contributor

Random thought: we could have an option to redirect to stdout with something like the workaround described here docker/compose#7346 (comment)

@frankforpresident
Copy link
Author

Well I've already implemented this on my side of the code but it would be neat if it was supported by the package itself

@AlexZeitler
Copy link
Contributor

Would you mind sharing it or sending a PR?

@frankforpresident
Copy link
Author

Well it is very basic at the moment

async up() {
    log.info('docker-compose up');
    const result = await compose.upAll();

    this._validator(result);

    log.info('docker-compose up completed with success');

    return this._parser(result);
  }

 private _parser(output?: IDockerComposeResult) {
    const outputString = output?.out || output.err || '';

    const lines = outputString.split('\n');

    const parsed = lines
      .filter((l) => l)
      .map((line) => {
        const [service, status] = line.split('  ').map((item) => item.trim());
        return { service, status };
      });

    log.debug(
      'docker-compose output parsed \n' + JSON.stringify(parsed, null, 2)
    );

    return parsed;
  }

  private _validator(output?: IDockerComposeResult) {
    const { err, exitCode } = output || {};

    if (exitCode !== 0) {
      log.error('docker-compose failed');
      log.error(err);
      throw new Error('docker-compose failed');
    }
  }

tldr; const outputString = output?.out || output.err || '';

@Crakleurs
Copy link

Hello can i have this issue ?

@AlexZeitler
Copy link
Contributor

@Crakleurs thanks, it would be great if you would take this over

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants