fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-15 15:08:48 +02:00
parent 44f2aab2f6
commit 225c1be14c
3 changed files with 34 additions and 33 deletions

View File

@ -107,9 +107,6 @@ tap.test('should create a service', async () => {
ports: [] ports: []
}); });
await testSecret.update(`{"updated": "socool"}`);
await testService.update();
await testService.remove(); await testService.remove();
await testNetwork.remove(); await testNetwork.remove();
await testSecret.remove(); await testSecret.remove();

View File

@ -50,7 +50,34 @@ export class DockerService {
version: serviceVersion 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) { for (const network of serviceCreationDescriptor.networks) {
networkArray.push({ networkArray.push({
Target: network.Name, Target: network.Name,
@ -64,9 +91,9 @@ export class DockerService {
const hostPort = portArray[0]; const hostPort = portArray[0];
const containerPort = portArray[1]; const containerPort = portArray[1];
ports.push({ ports.push({
"Protocol": "tcp", Protocol: 'tcp',
"PublishedPort": parseInt(containerPort, 10), PublishedPort: parseInt(containerPort, 10),
"TargetPort": parseInt(hostPort, 10) TargetPort: parseInt(hostPort, 10)
}); });
} }
@ -90,7 +117,8 @@ export class DockerService {
ContainerSpec: { ContainerSpec: {
Image: serviceCreationDescriptor.image.RepoTags[0], Image: serviceCreationDescriptor.image.RepoTags[0],
Labels: labels, Labels: labels,
Secrets: secretArray Secrets: secretArray,
Mounts: mounts
}, },
UpdateConfig: { UpdateConfig: {
Parallelism: 0, Parallelism: 0,
@ -151,25 +179,6 @@ export class DockerService {
this.dockerHostRef = dockerHostArg; 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() { public async remove() {
await this.dockerHostRef.request('DELETE', `/services/${this.ID}`); 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.`); console.log(`service ${this.Spec.Name} is up to date.`);
} }
} }
public async updateFromRegistry() {
if (await this.needsUpdate()) {
this.update();
}
}
} }

View File

@ -11,4 +11,5 @@ export interface IServiceCreationDescriptor {
networkAlias: string; networkAlias: string;
secrets: DockerSecret[]; secrets: DockerSecret[];
ports: string[]; ports: string[];
accessHostDockerSock?: boolean;
} }