Compare commits

..

4 Commits

Author SHA1 Message Date
178c1d2df1 1.0.72 2019-09-18 17:29:43 +02:00
43d9da808b fix(core): update 2019-09-18 17:29:43 +02:00
15f5c38eb0 1.0.71 2019-09-15 15:08:48 +02:00
225c1be14c fix(core): update 2019-09-15 15:08:48 +02:00
6 changed files with 37 additions and 36 deletions

2
package-lock.json generated
View File

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

View File

@ -1,6 +1,6 @@
{
"name": "@mojoio/docker",
"version": "1.0.70",
"version": "1.0.72",
"description": "easy communication with docker remote api from node, TypeScript ready",
"private": false,
"main": "dist/index.js",

View File

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

View File

@ -62,7 +62,7 @@ export class DockerHost {
username: gitlabAuthArray[0],
password: gitlabAuthArray[1],
serveraddress: 'registry.gitlab.com'
})
});
}
/**

View File

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

View File

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