diff --git a/index.d.ts b/index.d.ts index 5f97e8a..29804fc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -30,6 +30,12 @@ export declare function buildMany(services: String[], options: IDockerComposeBui export declare function buildOne(service: String, options: IDockerComposeOptions): Promise; +export declare function config(options: IDockerComposeOptions): Promise; + +export declare function configServices(options: IDockerComposeOptions): Promise; + +export declare function configVolumes(options: IDockerComposeOptions): Promise; + export declare function ps(options: IDockerComposeOptions): Promise; export declare function push(options: IDockerComposePushOptions): Promise; diff --git a/index.js b/index.js index 26116d9..2e0b54c 100644 --- a/index.js +++ b/index.js @@ -189,7 +189,6 @@ const rm = function (options) { * @return {object} std.out / std.err */ const exec = function (container, command, options) { - const args = command.split(/\s+/); return execCompose('exec', [ '-T', container ].concat(args), options); @@ -270,6 +269,51 @@ const buildOne = function (service, options) { return execCompose('build', [ service ], options); }; +/** + * Config command + * @param {object} options + * @param {string} options.cwd + * @param {boolean} [options.log] + * @param {?(string|string[])} [options.config] + * @param {?object} [options.env] + * @param {?(string[]|Array)} [options.composeOptions] + * + * @return {object} std.out / std.err + */ +const config = function (options) { + return execCompose('config', [], options); +}; + +/** + * Config command with --services option + * @param {object} options + * @param {string} options.cwd + * @param {boolean} [options.log] + * @param {?(string|string[])} [options.config] + * @param {?object} [options.env] + * @param {?(string[]|Array)} [options.composeOptions] + * + * @return {object} std.out / std.err + */ +const configServices = function (options) { + return execCompose('config', [ '--services' ], options); +}; + +/** + * Config command with --volumes option + * @param {object} options + * @param {string} options.cwd + * @param {boolean} [options.log] + * @param {?(string|string[])} [options.config] + * @param {?object} [options.env] + * @param {?(string[]|Array)} [options.composeOptions] + * + * @return {object} std.out / std.err + */ +const configVolumes = function (options) { + return execCompose('config', [ '--volumes' ], options); +}; + /** * Ps command * @param {object} options @@ -369,9 +413,10 @@ const logs = function (service, options) { * @param {?object} [options.env] * @param {?(string[]|Array)} [options.composeOptions] */ -const port = function(service, containerPort, options) { - const args = [service, containerPort] - return execCompose('port', args, options) +const port = function (service, containerPort, options) { + const args = [ service, containerPort ]; + + return execCompose('port', args, options); }; module.exports = { @@ -392,6 +437,9 @@ module.exports = { buildMany, buildOne, ps, + config, + configServices, + configVolumes, push, - port, + port }; diff --git a/readme.md b/readme.md index dec5906..83f60ef 100644 --- a/readme.md +++ b/readme.md @@ -35,6 +35,9 @@ npm install --save-dev docker-compose * `restartMany(services, options)` - Restart services * `restartOne(service, options)` - Restart service * `ps(options)` - Lists containers information +* `config(options)` - Validates configuration files and returns configuration yaml +* `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 ```javascript diff --git a/test/docker-compose-42.yml b/test/docker-compose-42.yml index ff084f9..61a5162 100644 --- a/test/docker-compose-42.yml +++ b/test/docker-compose-42.yml @@ -4,4 +4,8 @@ services: some-service: image: alpine volumes: - - ./volume:/mountedvolume \ No newline at end of file + - ./volume:/mountedvolume + - db-data:/mountedsecondvolume + +volumes: + db-data: diff --git a/test/index.js b/test/index.js index 4c3e814..56709d1 100644 --- a/test/index.js +++ b/test/index.js @@ -147,7 +147,7 @@ test('ensure custom ymls are working', async assert => { await compose.upAll({ cwd, log, config }); assert.true(await isContainerRunning('/compose_test_mongodb_2')); - // config & [config] are the same thing, ensures that multiple configs are handled properly + // config & [config] are the same thing, ensures that multiple configs are handled properly await compose.kill({ cwd, log, config: [ config ]}); assert.false(await isContainerRunning('/compose_test_mongodb_2')); assert.end(); @@ -265,6 +265,28 @@ test('teardown', async assert => { assert.end(); }); +test('config show data for docker-compose files', async assert => { + const std = await compose.config({ cwd: path.join(__dirname), log: true, config: 'docker-compose-42.yml' }); + + assert.false(std.err); + assert.true(std.out.includes('some-service')); + assert.true(std.out.includes('test/volume:/mountedvolume:rw')); +}); + +test('config show data for docker-compose files', async assert => { + const std = await compose.configServices({ cwd: path.join(__dirname), log: true, config: 'docker-compose-42.yml' }); + + assert.false(std.err); + assert.true(std.out.includes('some-service')); +}); + +test('config show data for docker-compose files', async assert => { + const std = await compose.configVolumes({ cwd: path.join(__dirname), log: true, config: 'docker-compose-42.yml' }); + + assert.false(std.err); + assert.true(std.out.includes('db-data')); +}); + test('ps shows status data for started containers', async assert => { await compose.upAll({ cwd: path.join(__dirname), log: true }); @@ -326,10 +348,11 @@ test('returns the port for a started service', async assert => { const config = { cwd: path.join(__dirname), config: './docker-compose-2.yml' - } + }; + await compose.upAll(config); const port = await compose.port('db', 5432, config); assert.true(port.out.match(/.*:[0-9]{1,5}/)); assert.end(); -}) +});