Skip to content

Commit 9a77324

Browse files
authored
Merge pull request #19 from dani8art/#8
added documentation
2 parents e89a142 + 0d6e8e3 commit 9a77324

10 files changed

+191
-32
lines changed

docs/README.md

Lines changed: 179 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,186 @@
1-
## Installation
1+
## How to install
22

3-
On your application package run next command:
3+
### Docker compose manager module for node.js
44

55
```
6-
$ node npm install docker-compose-manager --save
6+
npm i docker-compose-manager --save
77
```
88

9-
### You can use
9+
## Docker compose manager API
1010

11-
1. ```dockerComposeUp = function(dir, options, success, error)```
12-
2. ```dockerComposeDown = function(dir, success, error)```
13-
3. ```dockerComposeStop = function(dir, success, error)```
14-
4. ```dockerComposeStart = function(dir, success, error)```
15-
5. ```dockerExec = function (container, exec_command, options, success, error)```
16-
6. ```dockerInspectIPAddressOfContainer = function (container, options)```
17-
7. ```dockerInspectPortOfContainer = function (container, options)```
11+
1. [dockerComposeUp](#dockercomposeup)
12+
2. [dockerComposeDown](#dockercomposedown)
13+
3. [dockerComposeStop](#dockercomposestop)
14+
4. [dockerComposeStart](#dockercomposestart)
15+
5. [dockerExec](#dockerexec)
16+
6. [dockerInspectIPAddressOfContainer](#dockerinspectipaddressofcontainer)
17+
7. [dockerInspectPortOfContainer](#dockerinspectportofcontainer)
1818

19-
>Soon more documentation.
19+
### DockerComposeUp
20+
21+
This method receives a URI of a file and builds, (re)creates, starts, and attaches to containers for a service.
22+
23+
#### Parameters
24+
25+
Name | Type | Description
26+
-----|------|-------------
27+
**file** | `string` | **Required.** The file where the service is described.
28+
**options** | `[string]` | **Optional.** Docker compose up commad [options](https://docs.docker.com/compose/reference/up/).
29+
30+
#### Example
31+
32+
```javascript
33+
var dcManager = require('docker-compose-manager');
34+
var file = __dirname + '/docker-compose.yaml';
35+
36+
dcManager.dockerComposeUp(file).then(out => {
37+
console.log(out);
38+
}, err=>{
39+
console.error(err);
40+
});
41+
```
42+
43+
### DockerComposeDown
44+
45+
This method receives a URI of a file and stops containers, removes containers, networks, volumes, and images created by [dockerComposeUp](#dockercomposeup).
46+
47+
#### Parameters
48+
49+
Name | Type | Description
50+
-----|------|-------------
51+
**file** | `string` | **Required.** The file where the service is described.
52+
**options** | `[string]` | **Optional.** Docker compose down commad [options](https://docs.docker.com/compose/reference/down/).
53+
54+
#### Example
55+
56+
```javascript
57+
var dcManager = require('docker-compose-manager');
58+
var file = __dirname + '/docker-compose.yaml';
59+
60+
dcManager.dockerComposeDown(file).then(out => {
61+
console.log(out);
62+
}, err=>{
63+
console.error(err);
64+
});
65+
```
66+
67+
### DockerComposeStop
68+
69+
This method receives a URI of a file and stops running containers without removing them.
70+
71+
#### Parameters
72+
73+
Name | Type | Description
74+
-----|------|-------------
75+
**file** | `string` | **Required.** The file where the service is described.
76+
**options** | `[string]` | **Optional.** Docker compose stop commad [options](https://docs.docker.com/compose/reference/stop/).
77+
78+
#### Example
79+
80+
```javascript
81+
var dcManager = require('docker-compose-manager');
82+
var file = __dirname + '/docker-compose.yaml';
83+
84+
dcManager.dockerComposeStop(file).then(out => {
85+
console.log(out);
86+
}, err=>{
87+
console.error(err);
88+
});
89+
```
90+
91+
### DockerComposeStart
92+
93+
This method receives a URI of a file and sStarts existing containers for a service.
94+
95+
#### Parameters
96+
97+
Name | Type | Description
98+
-----|------|-------------
99+
**file** | `string` | **Required.** The file where the service is described.
100+
**options** | `[string]` | **Optional.** Docker compose start commad [options](https://docs.docker.com/compose/reference/start/).
101+
102+
#### Example
103+
104+
```javascript
105+
var dcManager = require('docker-compose-manager');
106+
var file = __dirname + '/docker-compose.yaml';
107+
108+
dcManager.dockerComposeStart(file).then(out => {
109+
console.log(out);
110+
}, err=>{
111+
console.error(err);
112+
});
113+
```
114+
115+
### DockerExec
116+
117+
This method receives a container name and the command will be executed inside of it, and execute `docker exec` command with insede_command given.
118+
119+
#### Parameters
120+
121+
Name | Type | Description
122+
-----|------|-------------
123+
**container** | `string` | **Required.** The container where the command will be executed.
124+
**exec_command** | `[string]` | **Required.** The command which will be executed.
125+
**options** | `[string]` | **Optional.** Docker exec commad [options](https://docs.docker.com/engine/reference/commandline/exec/).
126+
127+
#### Example
128+
129+
```javascript
130+
var dcManager = require('docker-compose-manager'),
131+
container = 'node_container_01',
132+
command = ['node', '--version'];
133+
134+
dcManager.dockerExec(container, command).then(out => {
135+
console.log(out);
136+
}, err=>{
137+
console.error(err);
138+
});
139+
```
140+
141+
### DockerInspectIPAddressOfContainer
142+
143+
This method receives a container and retrun a promise that resolves the ip of it.
144+
145+
#### Parameters
146+
147+
Name | Type | Description
148+
-----|------|-------------
149+
**container** | `string` | **Required.** The container for quering.
150+
**options** | `object` | **Optional.** This object has only one field: `options.network`. This is the network where the container is attached.
151+
152+
#### Example
153+
154+
```javascript
155+
var dcManager = require('docker-compose-manager'),
156+
container = 'node_container_01';
157+
158+
dcManager.dockerInspectIPAddressOfContainer(container,{network: "bridge"}).then(ip => {
159+
console.log(ip);
160+
}, err=>{
161+
console.error(err);
162+
});
163+
```
164+
165+
### DockerInspectPortOfContainer
166+
167+
This method receives a container and retrun a promise that resolves the port on it will expose.
168+
169+
#### Parameters
170+
171+
Name | Type | Description
172+
-----|------|-------------
173+
**container** | `string` | **Required.** The container for quering.
174+
175+
#### Example
176+
177+
```javascript
178+
var dcManager = require('docker-compose-manager'),
179+
container = 'node_container_01';
180+
181+
dcManager.dockerInspectPortOfContainer(container).then(port => {
182+
console.log(port);
183+
}, err=>{
184+
console.error(err);
185+
});
186+
```

tests/00-module/001-dc-manager.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('Docker compose manager Module tests', function () {
6565
}).then(() => {
6666
return module.dockerComposeStart(file);
6767
}).then(() => {
68-
return module.dockerExec('mongo', ['mongo', '--version']);
68+
return module.dockerExec('tests_mongo_1', ['mongo', '--version']);
6969
}).then(() => {
7070
return module.dockerInspectIPAddressOfContainer('tests_mongo_1', { network: "tests_default" }).then(ip => {
7171
expect(ip).to.be.equal('172.18.0.2');

tests/00-module/002-dc-up.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ describe('docker-compose up tests', function () {
1212
var file = __dirname + '/../docker-compose.yaml';
1313
it('Execute command up', done => {
1414

15-
var expected = fs.readFileSync('./tests/00-module/expected/dc-up.expected.txt', 'utf-8');
1615
module.dockerComposeUp(file).then(out => {
17-
expect(out).to.equal(expected);
16+
expect(out.indexOf('Creating network "tests_default" with the default driver')).to.not.equal(-1);
17+
expect(out.indexOf('Creating tests_mongo_1')).to.not.equal(-1);
18+
expect(out.indexOf('done')).to.not.equal(-1);
1819
done();
1920
}, done);
2021

tests/00-module/003-dc-stop.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ describe('docker-compose stop tests', function () {
1212
var file = __dirname + '/../docker-compose.yaml';
1313
it('Execute command stop', done => {
1414

15-
var expected = fs.readFileSync('./tests/00-module/expected/dc-stop.expected.txt', 'utf-8');
1615
module.dockerComposeStop(file).then(out => {
17-
expect(out).to.equal(expected);
16+
expect(out.indexOf('Stopping tests_mongo_1')).to.not.equal(-1);
17+
expect(out.indexOf('done')).to.not.equal(-1);
1818
done();
1919
}, done);
2020

tests/00-module/004-dc-start.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ describe('docker-compose start tests', function () {
1212
var file = __dirname + '/../docker-compose.yaml';
1313
it('Execute command start', done => {
1414

15-
var expected = fs.readFileSync('./tests/00-module/expected/dc-start.expected.txt', 'utf-8');
1615
module.dockerComposeStart(file).then(out => {
17-
expect(out).to.equal(expected);
16+
expect(out.indexOf('Starting mongo')).to.not.equal(-1);
17+
expect(out.indexOf('done')).to.not.equal(-1);
1818
done();
1919
}, done);
2020

tests/00-module/005-dc-down.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ describe('docker-compose down tests', function () {
1212
var file = __dirname + '/../docker-compose.yaml';
1313
it('Execute command down', done => {
1414

15-
var expected = fs.readFileSync('./tests/00-module/expected/dc-down.expected.txt', 'utf-8');
1615
module.dockerComposeDown(file).then(out => {
17-
expect(out).to.equal(expected);
16+
expect(out.indexOf('Stopping tests_mongo_1')).to.not.equal(-1);
17+
expect(out.indexOf('Removing tests_mongo_1')).to.not.equal(-1);
18+
expect(out.indexOf('done')).to.not.equal(-1);
19+
expect(out.indexOf('Removing network tests_default')).to.not.equal(-1);
1820
done();
1921
}, done);
2022

tests/00-module/expected/dc-down.expected.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/00-module/expected/dc-start.expected.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/00-module/expected/dc-stop.expected.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/00-module/expected/dc-up.expected.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)