From c79f6a698fb36a87606d8b14842a0e7332540475 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 11 Sep 2019 20:25:45 +0200 Subject: [PATCH] fix(core): update --- package-lock.json | 21 +++++++++++++ package.json | 1 + ts/docker.classes.service.ts | 59 +++++++++++++++++++++++++++++++++--- ts/docker.plugins.ts | 3 +- 4 files changed, 78 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 53e66f6..773bf40 100644 --- a/package-lock.json +++ b/package-lock.json @@ -313,6 +313,22 @@ "luxon": "^1.16.0" } }, + "@pushrocks/smartversion": { + "version": "2.0.4", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartversion/-/smartversion-2.0.4.tgz", + "integrity": "sha512-LrtaWRn1DD2zIUr8nVAsKwZ+Y55TFIVZ0z3xjwAQ46SoiTrFWooeQ2Xw18DqsEo1cEqMZyGAskaJkOaRkXHtUA==", + "requires": { + "@types/semver": "^6.0.2", + "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://verdaccio.lossless.one/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + } + } + }, "@pushrocks/tapbundle": { "version": "3.0.13", "resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.0.13.tgz", @@ -409,6 +425,11 @@ "resolved": "https://verdaccio.lossless.one/@types%2fportscanner/-/portscanner-2.1.0.tgz", "integrity": "sha512-II0FA05TSt4r7PBUvYTqub+yrXTRu7L/PQnTtjcJYzAeBts6xHM/OA2MKyeQ80sFxX7p+0BTo68Nh1P3N6Oj/g==" }, + "@types/semver": { + "version": "6.0.2", + "resolved": "https://verdaccio.lossless.one/@types%2fsemver/-/semver-6.0.2.tgz", + "integrity": "sha512-G1Ggy7/9Nsa1Jt2yiBR2riEuyK2DFNnqow6R7cromXPMNynackRY1vqFTLz/gwnef1LHokbXThcPhqMRjUbkpQ==" + }, "@types/vinyl": { "version": "2.0.3", "resolved": "https://verdaccio.lossless.one/@types%2fvinyl/-/vinyl-2.0.3.tgz", diff --git a/package.json b/package.json index f58de78..e909fa4 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@pushrocks/smartnetwork": "^1.1.14", "@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartrequest": "^1.1.26", + "@pushrocks/smartversion": "^2.0.4", "rxjs": "^6.5.3" }, "devDependencies": { diff --git a/ts/docker.classes.service.ts b/ts/docker.classes.service.ts index 19aadd9..5402239 100644 --- a/ts/docker.classes.service.ts +++ b/ts/docker.classes.service.ts @@ -38,6 +38,9 @@ export class DockerService { imageUrl: serviceCreationDescriptor.Image }); + const serviceVersion = serviceImage.Labels.version; + serviceCreationDescriptor.Labels.version = serviceVersion; + const networkArray: any[] = []; for (const network of serviceCreationDescriptor.networks) { networkArray.push({ @@ -52,7 +55,8 @@ export class DockerService { ContainerSpec: { Image: serviceCreationDescriptor.Image, Labels: serviceCreationDescriptor.Labels - } + }, + ForceUpdate: 1 }, Labels: serviceCreationDescriptor.Labels, Networks: networkArray @@ -71,9 +75,15 @@ export class DockerService { public UpdatedAt: string; public Spec: { Name: string; - Labels: [any]; // ZBD - TaskTemplate: [any], - Mode: [any]; + Labels: interfaces.TLabels; // ZBD + TaskTemplate: { + ContainerSpec: { + Image: string; + Isolation: string; + } + ForceUpdate: 0; + }, + Mode: {}; Networks: [any[]] }; public Endpoint: { Spec: {}, VirtualIPs: [any[]] }; @@ -84,10 +94,49 @@ export class DockerService { } public async update() { - + const labels: interfaces.TLabels = { + ...this.Spec.Labels, + + }; + const dockerData = await this.dockerHostRef.request('POST', `/servces/${this.ID}/update?version=${this.Version.Index}`, { + Name: this.Spec.Name, + TaskTemplate: { + ContainerSpec: { + Image: this.Spec.TaskTemplate.ContainerSpec.Image, + Labels: labels + }, + ForceUpdate: 1 + }, + Labels: labels, + }); + Object.assign(this, dockerData); } public async remove() { await this.dockerHostRef.request('DELETE', `/services/${this.ID}`); } + + public async reReadFromDockerEngine () { + const dockerData = await this.dockerHostRef.request('GET', `/services/${this.ID}`); + Object.assign(this, dockerData); + } + + public async updateFromRegistry () { + // TODO: implement digest based update recognition + + await this.reReadFromDockerEngine(); + const dockerImage = await DockerImage.createFromRegistry(this.dockerHostRef, { + imageUrl: this.Spec.TaskTemplate.ContainerSpec.Image + }); + + const imageVersion = new plugins.smartversion.SmartVersion(dockerImage.Labels.version); + const serviceVersion = new plugins.smartversion.SmartVersion(this.Spec.Labels.version); + if (imageVersion.greaterThan(serviceVersion)) { + console.log('service needs to be updated'); + this.update(); + } + + + + } } diff --git a/ts/docker.plugins.ts b/ts/docker.plugins.ts index 0e5c3c0..637bd4b 100644 --- a/ts/docker.plugins.ts +++ b/ts/docker.plugins.ts @@ -4,10 +4,11 @@ import * as smartlog from '@pushrocks/smartlog'; import * as smartnetwork from '@pushrocks/smartnetwork'; import * as smartpromise from '@pushrocks/smartpromise'; import * as smartrequest from '@pushrocks/smartrequest'; +import * as smartversion from '@pushrocks/smartversion'; smartlog.defaultLogger.enableConsole(); -export { lik, smartlog, smartnetwork, smartpromise, smartrequest }; +export { lik, smartlog, smartnetwork, smartpromise, smartrequest, smartversion }; // third party import * as rxjs from 'rxjs';