docker-compose
docker-compose copied to clipboard
Output ends up in "err" instead of "out" on macos even when exitCode equals 0
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
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.
See this issue for example: https://github.com/docker/compose/issues/7346
Random thought: we could have an option to redirect to stdout with something like the workaround described here https://github.com/docker/compose/issues/7346#issuecomment-1236305767
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
Would you mind sharing it or sending a PR?
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 || '';
Hello can i have this issue ?
@Crakleurs thanks, it would be great if you would take this over