Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
3f18cb68bf | |||
dae3b59e3b | |||
53062e70d4 | |||
3e70dc465b | |||
49445d93c6 | |||
4f838837f8 | |||
c76968bbe8 | |||
6c5e5644b1 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mojoio/docker",
|
||||
"version": "1.0.73",
|
||||
"version": "1.0.77",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mojoio/docker",
|
||||
"version": "1.0.73",
|
||||
"version": "1.0.77",
|
||||
"description": "easy communication with docker remote api from node, TypeScript ready",
|
||||
"private": false,
|
||||
"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'
|
||||
});
|
||||
const testSecret = await docker.DockerSecret.createSecret(testDockerHost, {
|
||||
name: 'serviceSecret',
|
||||
name: 'testSecret',
|
||||
version: '0.0.1',
|
||||
labels: {},
|
||||
contentArg: '{"hi": "wow"}'
|
||||
});
|
||||
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, {
|
||||
image: testImage,
|
||||
labels: {
|
||||
testlabel: 'hi'
|
||||
},
|
||||
labels: {},
|
||||
name: 'testService',
|
||||
networks: [testNetwork],
|
||||
networkAlias: 'testService',
|
||||
secrets: [testSecret],
|
||||
ports: []
|
||||
ports: ['3000:80']
|
||||
});
|
||||
|
||||
await testService.remove();
|
||||
|
@ -137,6 +137,10 @@ export class DockerImage {
|
||||
|
||||
// get stuff
|
||||
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 { DockerHost } from './docker.classes.host';
|
||||
import { DockerService } from './docker.classes.service';
|
||||
|
||||
export class DockerNetwork {
|
||||
public static async getNetworks(dockerHost: DockerHost): Promise<DockerNetwork[]> {
|
||||
@ -90,4 +91,29 @@ export class DockerNetwork {
|
||||
public async remove() {
|
||||
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 getContainersOnNetworkForService(serviceArg: DockerService) {
|
||||
const containersOnNetwork = await this.getContainersOnNetwork();
|
||||
const containersOfService = containersOnNetwork.filter(container => {
|
||||
return container.Name.startsWith(serviceArg.Spec.Name);
|
||||
});
|
||||
return containersOnNetwork;
|
||||
}
|
||||
}
|
||||
|
@ -92,8 +92,8 @@ export class DockerService {
|
||||
const containerPort = portArray[1];
|
||||
ports.push({
|
||||
Protocol: 'tcp',
|
||||
PublishedPort: parseInt(containerPort, 10),
|
||||
TargetPort: parseInt(hostPort, 10)
|
||||
PublishedPort: parseInt(hostPort, 10),
|
||||
TargetPort: parseInt(containerPort, 10)
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user