mirror of
https://github.com/danbulant/docker-compose
synced 2026-05-21 13:28:42 +00:00
Merge pull request #54 from Steveb-p/master
Add config command & related
This commit is contained in:
commit
c620655332
5 changed files with 93 additions and 9 deletions
6
index.d.ts
vendored
6
index.d.ts
vendored
|
|
@ -30,6 +30,12 @@ export declare function buildMany(services: String[], options: IDockerComposeBui
|
|||
|
||||
export declare function buildOne(service: String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
|
||||
export declare function config(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
|
||||
export declare function configServices(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
|
||||
export declare function configVolumes(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
|
||||
export declare function ps(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
|
||||
export declare function push(options: IDockerComposePushOptions): Promise<IDockerComposeResult>;
|
||||
|
|
|
|||
58
index.js
58
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<string|string[]>)} [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<string|string[]>)} [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<string|string[]>)} [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<string|string[]>)} [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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -4,4 +4,8 @@ services:
|
|||
some-service:
|
||||
image: alpine
|
||||
volumes:
|
||||
- ./volume:/mountedvolume
|
||||
- ./volume:/mountedvolume
|
||||
- db-data:/mountedsecondvolume
|
||||
|
||||
volumes:
|
||||
db-data:
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
})
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue