mirror of
https://github.com/danbulant/docker-compose
synced 2026-06-24 09:22:08 +00:00
Merge pull request #63 from Jannis/jannis/exit-code
Expose docker-compose exit code in results
This commit is contained in:
commit
be4aa13e1f
5 changed files with 19 additions and 4 deletions
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal 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
1
index.d.ts
vendored
|
|
@ -63,6 +63,7 @@ interface IDockerComposePushOptions extends IDockerComposeOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IDockerComposeResult {
|
interface IDockerComposeResult {
|
||||||
|
exitCode: ?number;
|
||||||
out: string;
|
out: string;
|
||||||
err: string;
|
err: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
index.js
4
index.js
|
|
@ -67,6 +67,7 @@ const execCompose = (command, args, options) => new Promise((resolve, reject) =>
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
|
exitCode: null,
|
||||||
err: '',
|
err: '',
|
||||||
out: ''
|
out: ''
|
||||||
};
|
};
|
||||||
|
|
@ -79,7 +80,8 @@ const execCompose = (command, args, options) => new Promise((resolve, reject) =>
|
||||||
result.err += chunk.toString();
|
result.err += chunk.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
childProc.on('close', () => {
|
childProc.on('exit', exitCode => {
|
||||||
|
result.exitCode = exitCode;
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,12 @@ npm install --save-dev docker-compose
|
||||||
* `configServices(options)` - Returns list of services defined in configuration files
|
* `configServices(options)` - Returns list of services defined in configuration files
|
||||||
* `configVolumes(options)` - Returns list of volumes 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
|
```javascript
|
||||||
{
|
{
|
||||||
out: 'stdout contents'
|
out: 'stdout contents',
|
||||||
err: 'stderr contents'
|
err: 'stderr contents',
|
||||||
|
exitCode: 0, // !== 0 in case of an error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,12 @@ test('ensure container gets started', async assert => {
|
||||||
assert.end();
|
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 => {
|
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.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' ]});
|
await compose.upAll({ cwd: path.join(__dirname), log: true, config: 'docker-compose-build.yml', commandOptions: [ '--build' ]});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue