From 225c1be14caf7d05d5558ee3f8be2301fe9ffc67 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 15 Sep 2019 15:08:48 +0200 Subject: [PATCH] fix(core): update --- test/test.ts | 3 -- ts/docker.classes.service.ts | 63 +++++++++++++++++++----------------- ts/interfaces/service.ts | 1 + 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/test/test.ts b/test/test.ts index 71d758a..a85d279 100644 --- a/test/test.ts +++ b/test/test.ts @@ -107,9 +107,6 @@ tap.test('should create a service', async () => { ports: [] }); - await testSecret.update(`{"updated": "socool"}`); - await testService.update(); - await testService.remove(); await testNetwork.remove(); await testSecret.remove(); diff --git a/ts/docker.classes.service.ts b/ts/docker.classes.service.ts index 87cb09b..ca0cc2f 100644 --- a/ts/docker.classes.service.ts +++ b/ts/docker.classes.service.ts @@ -50,7 +50,34 @@ export class DockerService { version: serviceVersion }; - const networkArray: any[] = []; + const mounts: Array<{ + /** + * the target inside the container + */ + Target: string; + /** + * The Source from which to mount the data (Volume or host path) + */ + Source: string; + Type: 'bind' | 'volume' | 'tmpfs' | 'npipe'; + ReadOnly: boolean; + Consistency: 'default' | 'consistent' | 'cached' | 'delegated'; + }> = []; + if (serviceCreationDescriptor.accessHostDockerSock) { + mounts.push({ + Target: '/var/run/docker.sock', + Source: '/var/run/docker.sock', + Consistency: 'default', + ReadOnly: false, + Type: 'bind' + }); + } + + const networkArray: Array<{ + Target: string; + Aliases: string[]; + }> = []; + for (const network of serviceCreationDescriptor.networks) { networkArray.push({ Target: network.Name, @@ -64,9 +91,9 @@ export class DockerService { const hostPort = portArray[0]; const containerPort = portArray[1]; ports.push({ - "Protocol": "tcp", - "PublishedPort": parseInt(containerPort, 10), - "TargetPort": parseInt(hostPort, 10) + Protocol: 'tcp', + PublishedPort: parseInt(containerPort, 10), + TargetPort: parseInt(hostPort, 10) }); } @@ -90,7 +117,8 @@ export class DockerService { ContainerSpec: { Image: serviceCreationDescriptor.image.RepoTags[0], Labels: labels, - Secrets: secretArray + Secrets: secretArray, + Mounts: mounts }, UpdateConfig: { Parallelism: 0, @@ -151,25 +179,6 @@ export class DockerService { this.dockerHostRef = dockerHostArg; } - public async update() { - const labels: interfaces.TLabels = { - ...this.Spec.Labels, - version: 'x.x.x' - }; - - const dockerData = await this.dockerHostRef.request( - 'POST', - `/services/${this.ID}/update?version=${this.Version.Index}`, - { - Name: this.Spec.Name, - TaskTemplate: this.Spec.TaskTemplate, - Labels: labels, - Networks: this.Spec.Networks - } - ); - Object.assign(this, dockerData); - } - public async remove() { await this.dockerHostRef.request('DELETE', `/services/${this.ID}`); } @@ -196,10 +205,4 @@ export class DockerService { console.log(`service ${this.Spec.Name} is up to date.`); } } - - public async updateFromRegistry() { - if (await this.needsUpdate()) { - this.update(); - } - } } diff --git a/ts/interfaces/service.ts b/ts/interfaces/service.ts index e8decb5..f7ecbfd 100644 --- a/ts/interfaces/service.ts +++ b/ts/interfaces/service.ts @@ -11,4 +11,5 @@ export interface IServiceCreationDescriptor { networkAlias: string; secrets: DockerSecret[]; ports: string[]; + accessHostDockerSock?: boolean; }