mirror of
https://github.com/danbulant/docker-compose
synced 2026-05-26 13:31:54 +00:00
Add config command & related
This commit is contained in:
parent
214d01f904
commit
fdcffa6057
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 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 ps(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||||
|
|
||||||
export declare function push(options: IDockerComposePushOptions): 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
|
* @return {object} std.out / std.err
|
||||||
*/
|
*/
|
||||||
const exec = function (container, command, options) {
|
const exec = function (container, command, options) {
|
||||||
|
|
||||||
const args = command.split(/\s+/);
|
const args = command.split(/\s+/);
|
||||||
|
|
||||||
return execCompose('exec', [ '-T', container ].concat(args), options);
|
return execCompose('exec', [ '-T', container ].concat(args), options);
|
||||||
|
|
@ -270,6 +269,51 @@ const buildOne = function (service, options) {
|
||||||
return execCompose('build', [ 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
|
* Ps command
|
||||||
* @param {object} options
|
* @param {object} options
|
||||||
|
|
@ -369,9 +413,10 @@ const logs = function (service, options) {
|
||||||
* @param {?object} [options.env]
|
* @param {?object} [options.env]
|
||||||
* @param {?(string[]|Array<string|string[]>)} [options.composeOptions]
|
* @param {?(string[]|Array<string|string[]>)} [options.composeOptions]
|
||||||
*/
|
*/
|
||||||
const port = function(service, containerPort, options) {
|
const port = function (service, containerPort, options) {
|
||||||
const args = [service, containerPort]
|
const args = [ service, containerPort ];
|
||||||
return execCompose('port', args, options)
|
|
||||||
|
return execCompose('port', args, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
@ -392,6 +437,9 @@ module.exports = {
|
||||||
buildMany,
|
buildMany,
|
||||||
buildOne,
|
buildOne,
|
||||||
ps,
|
ps,
|
||||||
|
config,
|
||||||
|
configServices,
|
||||||
|
configVolumes,
|
||||||
push,
|
push,
|
||||||
port,
|
port
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ npm install --save-dev docker-compose
|
||||||
* `restartMany(services, options)` - Restart services
|
* `restartMany(services, options)` - Restart services
|
||||||
* `restartOne(service, options)` - Restart service
|
* `restartOne(service, options)` - Restart service
|
||||||
* `ps(options)` - Lists containers information
|
* `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
|
All commands return a `Promise({object})` with an stdout and stderr strings
|
||||||
```javascript
|
```javascript
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,7 @@ services:
|
||||||
image: alpine
|
image: alpine
|
||||||
volumes:
|
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 });
|
await compose.upAll({ cwd, log, config });
|
||||||
assert.true(await isContainerRunning('/compose_test_mongodb_2'));
|
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 ]});
|
await compose.kill({ cwd, log, config: [ config ]});
|
||||||
assert.false(await isContainerRunning('/compose_test_mongodb_2'));
|
assert.false(await isContainerRunning('/compose_test_mongodb_2'));
|
||||||
assert.end();
|
assert.end();
|
||||||
|
|
@ -265,6 +265,28 @@ test('teardown', async assert => {
|
||||||
assert.end();
|
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 => {
|
test('ps shows status data for started containers', async assert => {
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: true });
|
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 = {
|
const config = {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
config: './docker-compose-2.yml'
|
config: './docker-compose-2.yml'
|
||||||
}
|
};
|
||||||
|
|
||||||
await compose.upAll(config);
|
await compose.upAll(config);
|
||||||
const port = await compose.port('db', 5432, config);
|
const port = await compose.port('db', 5432, config);
|
||||||
|
|
||||||
assert.true(port.out.match(/.*:[0-9]{1,5}/));
|
assert.true(port.out.match(/.*:[0-9]{1,5}/));
|
||||||
assert.end();
|
assert.end();
|
||||||
})
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue