Compare commits

..

6 Commits

Author SHA1 Message Date
49445d93c6 1.0.75 2019-09-21 21:57:57 +02:00
4f838837f8 fix(core): update 2019-09-21 21:57:57 +02:00
c76968bbe8 1.0.74 2019-09-20 16:29:44 +02:00
6c5e5644b1 fix(core): update 2019-09-20 16:29:43 +02:00
5cf80944fe 1.0.73 2019-09-19 20:05:57 +02:00
cdb69c5f17 fix(core): update 2019-09-19 20:05:56 +02:00
7 changed files with 44 additions and 13 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/docker", "name": "@mojoio/docker",
"version": "1.0.72", "version": "1.0.75",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/docker", "name": "@mojoio/docker",
"version": "1.0.72", "version": "1.0.75",
"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",

View File

@ -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();

View File

@ -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';
}
} }
} }

View File

@ -90,4 +90,17 @@ 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<{
[key: string]: {
Name: string;
EndpointID: string;
MacAddress: string;
IPv4Address: string;
IPv6Address: string;
};
}> {
const response = await this.dockerHost.request('GET', `/networks/${this.Id}`);
return response.body.Containers;
}
} }

View File

@ -92,16 +92,17 @@ 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)
}); });
} }
// lets configure secrets
const secretArray: any[] = []; const secretArray: any[] = [];
for (const secret of serviceCreationDescriptor.secrets) { for (const secret of serviceCreationDescriptor.secrets) {
secretArray.push({ secretArray.push({
File: { File: {
Name: 'secret.json', Name: 'secret.json', // TODO: make sure that works with multiple secrets
UID: '33', UID: '33',
GID: '33', GID: '33',
Mode: 384 Mode: 384
@ -111,6 +112,15 @@ export class DockerService {
}); });
} }
// lets configure limits
const limits = {
MemoryBytes: 1000 * 1000000
};
if (serviceCreationDescriptor.resources) {
limits.MemoryBytes = serviceCreationDescriptor.resources.memorySizeMB * 1000000;
}
const response = await dockerHost.request('POST', '/services/create', { const response = await dockerHost.request('POST', '/services/create', {
Name: serviceCreationDescriptor.name, Name: serviceCreationDescriptor.name,
TaskTemplate: { TaskTemplate: {
@ -127,7 +137,10 @@ export class DockerService {
Monitor: 15000000000, Monitor: 15000000000,
MaxFailureRatio: 0.15 MaxFailureRatio: 0.15
}, },
ForceUpdate: 1 ForceUpdate: 1,
Resources: {
Limits: limits
}
}, },
Labels: labels, Labels: labels,
Networks: networkArray, Networks: networkArray,

View File

@ -12,4 +12,7 @@ export interface IServiceCreationDescriptor {
secrets: DockerSecret[]; secrets: DockerSecret[];
ports: string[]; ports: string[];
accessHostDockerSock?: boolean; accessHostDockerSock?: boolean;
resources?: {
memorySizeMB: number
};
} }