Merge pull request #63 from Jannis/jannis/exit-code

Expose docker-compose exit code in results
This commit is contained in:
Alexander Zeitler 2019-04-30 20:55:42 +02:00 committed by GitHub
commit be4aa13e1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 4 deletions

5
CHANGELOG.md Normal file
View file

@ -0,0 +1,5 @@
# Next
## :tada: Enhancements
* [#58](https://github.com/PDMLab/docker-compose/issues/58): Expose docker-compose exit code in results

1
index.d.ts vendored
View file

@ -63,6 +63,7 @@ interface IDockerComposePushOptions extends IDockerComposeOptions {
}
interface IDockerComposeResult {
exitCode: ?number;
out: string;
err: string;
}

View file

@ -67,6 +67,7 @@ const execCompose = (command, args, options) => new Promise((resolve, reject) =>
});
const result = {
exitCode: null,
err: '',
out: ''
};
@ -79,7 +80,8 @@ const execCompose = (command, args, options) => new Promise((resolve, reject) =>
result.err += chunk.toString();
});
childProc.on('close', () => {
childProc.on('exit', exitCode => {
result.exitCode = exitCode;
resolve(result);
});

View file

@ -39,11 +39,12 @@ npm install --save-dev docker-compose
* `configServices(options)` - Returns list of services defined in configuration files
* `configVolumes(options)` - Returns list of volumes defined in configuration files
All commands return a `Promise({object})` with an stdout and stderr strings
All commands return a `Promise({object})` with stdout and stderr strings and an exit code:
```javascript
{
out: 'stdout contents'
err: 'stderr contents'
out: 'stdout contents',
err: 'stderr contents',
exitCode: 0, // !== 0 in case of an error
}
```

View file

@ -53,6 +53,12 @@ test('ensure container gets started', async assert => {
assert.end();
});
test('ensure exit code is returned correctly', async assert => {
assert.equal(0, (await compose.down({ cwd: path.join(__dirname), log: true })).exitCode);
assert.equal(0, (await compose.upAll({ cwd: path.join(__dirname), log: true })).exitCode);
assert.equal(1, (await compose.logs('non_existent_service', { cwd: path.join(__dirname) })).exitCode);
});
test('ensure container gets started with --build option', async assert => {
await compose.down({ cwd: path.join(__dirname), log: true, config: 'docker-compose-build.yml' });
await compose.upAll({ cwd: path.join(__dirname), log: true, config: 'docker-compose-build.yml', commandOptions: [ '--build' ]});