Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
5cf80944fe | |||
cdb69c5f17 | |||
178c1d2df1 | |||
43d9da808b | |||
15f5c38eb0 | |||
225c1be14c | |||
44f2aab2f6 | |||
b69315f1d3 | |||
7d20804986 | |||
0aab639fbd | |||
794bb60dfc |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/docker",
|
"name": "@mojoio/docker",
|
||||||
"version": "1.0.67",
|
"version": "1.0.73",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/docker",
|
"name": "@mojoio/docker",
|
||||||
"version": "1.0.67",
|
"version": "1.0.73",
|
||||||
"description": "easy communication with docker remote api from node, TypeScript ready",
|
"description": "easy communication with docker remote api from node, TypeScript ready",
|
||||||
"private": false,
|
"private": false,
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -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();
|
||||||
|
@ -62,7 +62,7 @@ export class DockerHost {
|
|||||||
username: gitlabAuthArray[0],
|
username: gitlabAuthArray[0],
|
||||||
password: gitlabAuthArray[1],
|
password: gitlabAuthArray[1],
|
||||||
serveraddress: 'registry.gitlab.com'
|
serveraddress: 'registry.gitlab.com'
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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,
|
||||||
@ -59,12 +86,23 @@ export class DockerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ports = [];
|
const ports = [];
|
||||||
|
for (const port of serviceCreationDescriptor.ports) {
|
||||||
|
const portArray = port.split(':');
|
||||||
|
const hostPort = portArray[0];
|
||||||
|
const containerPort = portArray[1];
|
||||||
|
ports.push({
|
||||||
|
Protocol: 'tcp',
|
||||||
|
PublishedPort: parseInt(containerPort, 10),
|
||||||
|
TargetPort: parseInt(hostPort, 10)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// lets configure secrets
|
||||||
const secretArray: any[] = [];
|
const secretArray: any[] = [];
|
||||||
for (const secret of serviceCreationDescriptor.secrets) {
|
for (const secret of serviceCreationDescriptor.secrets) {
|
||||||
secretArray.push({
|
secretArray.push({
|
||||||
File: {
|
File: {
|
||||||
Name: 'secret.json',
|
Name: 'secret.json', // TODO: make sure that works with multiple secrets
|
||||||
UID: '33',
|
UID: '33',
|
||||||
GID: '33',
|
GID: '33',
|
||||||
Mode: 384
|
Mode: 384
|
||||||
@ -74,13 +112,23 @@ export class DockerService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lets configure limits
|
||||||
|
const limits = {
|
||||||
|
MemoryBytes: 1000 * 1000000
|
||||||
|
};
|
||||||
|
|
||||||
|
if (serviceCreationDescriptor.resources) {
|
||||||
|
limits.MemoryBytes = serviceCreationDescriptor.resources.memorySizeMB * 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await dockerHost.request('POST', '/services/create', {
|
const response = await dockerHost.request('POST', '/services/create', {
|
||||||
Name: serviceCreationDescriptor.name,
|
Name: serviceCreationDescriptor.name,
|
||||||
TaskTemplate: {
|
TaskTemplate: {
|
||||||
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,
|
||||||
@ -89,7 +137,10 @@ export class DockerService {
|
|||||||
Monitor: 15000000000,
|
Monitor: 15000000000,
|
||||||
MaxFailureRatio: 0.15
|
MaxFailureRatio: 0.15
|
||||||
},
|
},
|
||||||
ForceUpdate: 1
|
ForceUpdate: 1,
|
||||||
|
Resources: {
|
||||||
|
Limits: limits
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Networks: networkArray,
|
Networks: networkArray,
|
||||||
@ -141,25 +192,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}`);
|
||||||
}
|
}
|
||||||
@ -186,10 +218,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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,8 @@ export interface IServiceCreationDescriptor {
|
|||||||
networkAlias: string;
|
networkAlias: string;
|
||||||
secrets: DockerSecret[];
|
secrets: DockerSecret[];
|
||||||
ports: string[];
|
ports: string[];
|
||||||
|
accessHostDockerSock?: boolean;
|
||||||
|
resources?: {
|
||||||
|
memorySizeMB: number
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user