mirror of
https://github.com/danbulant/docker-compose
synced 2026-05-19 12:28:43 +00:00
implement logs command including support for --follow flag
This commit is contained in:
parent
c53c0884f9
commit
2b117d216e
4 changed files with 34 additions and 1 deletions
5
index.d.ts
vendored
5
index.d.ts
vendored
|
|
@ -11,6 +11,7 @@ declare module "docker-compose" {
|
|||
restartOne(service:String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
rm(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
exec(container:String, command:String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
logs(container:String, command:String, options: IDockerComposeLogOptions): Promise<IDockerComposeResult>;
|
||||
run(service:String, command:String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
buildAll(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
buildMany(services:String[], options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
|
|
@ -24,6 +25,10 @@ declare module "docker-compose" {
|
|||
log?: boolean;
|
||||
}
|
||||
|
||||
interface IDockerComposeLogOptions extends IDockerComposeOptions{
|
||||
follow: boolean;
|
||||
}
|
||||
|
||||
interface IDockerComposeResult {
|
||||
out: string;
|
||||
err: string;
|
||||
|
|
|
|||
21
index.js
21
index.js
|
|
@ -268,4 +268,23 @@ const restartOne = function (service, options) {
|
|||
return restartMany([ service ], options);
|
||||
};
|
||||
|
||||
module.exports = { upAll, upMany, upOne, kill, down, stop, rm, exec, restartAll, restartMany, restartOne, run, buildAll, buildMany, buildOne, ps };
|
||||
/**
|
||||
* @param {string} service
|
||||
* @param {object} options
|
||||
* @param {string} options.cwd
|
||||
* @param {boolean} [options.log]
|
||||
* @param {boolean} [options.follow]
|
||||
* @param {?(string|string[])} [options.config]
|
||||
* @param {?object} [options.env]
|
||||
*/
|
||||
const logs = function (service, options) {
|
||||
let args = [ service ];
|
||||
|
||||
if (options.follow) {
|
||||
args = [ '--follow', ...args ];
|
||||
}
|
||||
|
||||
return execCompose('logs', args, options);
|
||||
};
|
||||
|
||||
module.exports = { upAll, upMany, upOne, kill, down, stop, rm, exec, logs, restartAll, restartMany, restartOne, run, buildAll, buildMany, buildOne, ps };
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ npm install --save-dev docker-compose
|
|||
* `stop(options)` - Stop running containers without removing them
|
||||
* `rm(options)` - Remove stopped service containers - always uses the `-f` flag due to non interactive mode
|
||||
* `exec(container, command, options)` - Exec `command` inside `container`, uses `-T` to properly handle stdin & stdout
|
||||
* `logs(container, command, options)` - Show logs of service. Use `options.follow` `true|false` to turn on `--follow` flag.
|
||||
* `run(service, command, options)` - Run a one-off `command` on a service, uses `-T` to properly handle stdin & stdout
|
||||
* `buildAll(options)` - Build or rebuild services
|
||||
* `buildMany(services, options)` - Build or rebuild services
|
||||
|
|
|
|||
|
|
@ -269,3 +269,11 @@ test('restartOne does restart container', async assert => {
|
|||
assert.true(await isContainerRunning('/compose_test_mongodb'));
|
||||
assert.end();
|
||||
});
|
||||
|
||||
test('logs does follow service logs', async assert => {
|
||||
await compose.upAll({ cwd: path.join(__dirname), log: true });
|
||||
await compose.logs('db', { cwd: path.join(__dirname), log: true });
|
||||
|
||||
assert.true(await isContainerRunning('/compose_test_mongodb'));
|
||||
assert.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue