Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
53062e70d4 | |||
3e70dc465b | |||
49445d93c6 | |||
4f838837f8 | |||
c76968bbe8 | |||
6c5e5644b1 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/docker",
|
"name": "@mojoio/docker",
|
||||||
"version": "1.0.73",
|
"version": "1.0.76",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/docker",
|
"name": "@mojoio/docker",
|
||||||
"version": "1.0.73",
|
"version": "1.0.76",
|
||||||
"description": "easy communication with docker remote api from node, TypeScript ready",
|
"description": "easy communication with docker remote api from node, TypeScript ready",
|
||||||
"private": false,
|
"private": false,
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
10
test/test.ts
10
test/test.ts
@ -87,24 +87,22 @@ tap.test('should create a service', async () => {
|
|||||||
Name: 'testNetwork'
|
Name: 'testNetwork'
|
||||||
});
|
});
|
||||||
const testSecret = await docker.DockerSecret.createSecret(testDockerHost, {
|
const testSecret = await docker.DockerSecret.createSecret(testDockerHost, {
|
||||||
name: 'serviceSecret',
|
name: 'testSecret',
|
||||||
version: '0.0.1',
|
version: '0.0.1',
|
||||||
labels: {},
|
labels: {},
|
||||||
contentArg: '{"hi": "wow"}'
|
contentArg: '{"hi": "wow"}'
|
||||||
});
|
});
|
||||||
const testImage = await docker.DockerImage.createFromRegistry(testDockerHost, {
|
const testImage = await docker.DockerImage.createFromRegistry(testDockerHost, {
|
||||||
imageUrl: 'nginx:latest'
|
imageUrl: 'registry.gitlab.com/hosttoday/ht-docker-static'
|
||||||
});
|
});
|
||||||
const testService = await docker.DockerService.createService(testDockerHost, {
|
const testService = await docker.DockerService.createService(testDockerHost, {
|
||||||
image: testImage,
|
image: testImage,
|
||||||
labels: {
|
labels: {},
|
||||||
testlabel: 'hi'
|
|
||||||
},
|
|
||||||
name: 'testService',
|
name: 'testService',
|
||||||
networks: [testNetwork],
|
networks: [testNetwork],
|
||||||
networkAlias: 'testService',
|
networkAlias: 'testService',
|
||||||
secrets: [testSecret],
|
secrets: [testSecret],
|
||||||
ports: []
|
ports: ['3000:80']
|
||||||
});
|
});
|
||||||
|
|
||||||
await testService.remove();
|
await testService.remove();
|
||||||
|
@ -137,6 +137,10 @@ export class DockerImage {
|
|||||||
|
|
||||||
// get stuff
|
// get stuff
|
||||||
public async getVersion() {
|
public async getVersion() {
|
||||||
return this.Labels.version;
|
if (this.Labels && this.Labels.version) {
|
||||||
|
return this.Labels.version;
|
||||||
|
} else {
|
||||||
|
return 'x.x.x';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import * as plugins from './docker.plugins';
|
|||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
import { DockerHost } from './docker.classes.host';
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
import { DockerService } from './docker.classes.service';
|
||||||
|
|
||||||
export class DockerNetwork {
|
export class DockerNetwork {
|
||||||
public static async getNetworks(dockerHost: DockerHost): Promise<DockerNetwork[]> {
|
public static async getNetworks(dockerHost: DockerHost): Promise<DockerNetwork[]> {
|
||||||
@ -90,4 +91,28 @@ export class DockerNetwork {
|
|||||||
public async remove() {
|
public async remove() {
|
||||||
const response = await this.dockerHost.request('DELETE', `/networks/${this.Id}`);
|
const response = await this.dockerHost.request('DELETE', `/networks/${this.Id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getContainersOnNetwork(): Promise<Array<{
|
||||||
|
Name: string;
|
||||||
|
EndpointID: string;
|
||||||
|
MacAddress: string;
|
||||||
|
IPv4Address: string;
|
||||||
|
IPv6Address: string;
|
||||||
|
}>> {
|
||||||
|
const returnArray = [];
|
||||||
|
const response = await this.dockerHost.request('GET', `/networks/${this.Id}`);
|
||||||
|
for (const key of Object.keys(response.body.Containers)) {
|
||||||
|
returnArray.push(response.body.Containers[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnArray;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getIpForService(serviceArg: DockerService) {
|
||||||
|
const containersOnNetwork = await this.getContainersOnNetwork();
|
||||||
|
const containersOfService = containersOnNetwork.filter(container => {
|
||||||
|
return container.Name.startsWith(serviceArg.Spec.Name);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,8 +92,8 @@ export class DockerService {
|
|||||||
const containerPort = portArray[1];
|
const containerPort = portArray[1];
|
||||||
ports.push({
|
ports.push({
|
||||||
Protocol: 'tcp',
|
Protocol: 'tcp',
|
||||||
PublishedPort: parseInt(containerPort, 10),
|
PublishedPort: parseInt(hostPort, 10),
|
||||||
TargetPort: parseInt(hostPort, 10)
|
TargetPort: parseInt(containerPort, 10)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user