fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-11 20:25:45 +02:00
parent 0ef098e9c8
commit c79f6a698f
4 changed files with 78 additions and 6 deletions

21
package-lock.json generated
View File

@ -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",

View File

@ -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": {

View File

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

View File

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