Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c496405818 | |||
020737e21b | |||
fe3560caac | |||
b2a7e67868 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/docker",
|
"name": "@mojoio/docker",
|
||||||
"version": "1.0.41",
|
"version": "1.0.43",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/docker",
|
"name": "@mojoio/docker",
|
||||||
"version": "1.0.41",
|
"version": "1.0.43",
|
||||||
"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",
|
||||||
|
10
test/test.ts
10
test/test.ts
@ -52,4 +52,14 @@ tap.test('should return a change Observable', async tools => {
|
|||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// SERVICES
|
||||||
|
tap.test('should activate swarm mode', async () => {
|
||||||
|
await testDockerHost.activateSwarm();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should list all services', async tools => {
|
||||||
|
const services = await docker.DockerService.getServices(testDockerHost);
|
||||||
|
console.log(services);
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -49,7 +49,10 @@ export class DockerContainer {
|
|||||||
if (response.statusCode < 300) {
|
if (response.statusCode < 300) {
|
||||||
plugins.smartlog.defaultLogger.log('info', 'Container created successfully');
|
plugins.smartlog.defaultLogger.log('info', 'Container created successfully');
|
||||||
} else {
|
} else {
|
||||||
plugins.smartlog.defaultLogger.log('error', 'There has been a problem when creating the container');
|
plugins.smartlog.defaultLogger.log(
|
||||||
|
'error',
|
||||||
|
'There has been a problem when creating the container'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,10 +65,10 @@ export class DockerHost {
|
|||||||
/**
|
/**
|
||||||
* activates docker swarm
|
* activates docker swarm
|
||||||
*/
|
*/
|
||||||
public async activateSwarm(addvertisementIpArg: string) {
|
public async activateSwarm(addvertisementIpArg?: string) {
|
||||||
const response = await this.request('POST', '/swarm/init', {
|
const response = await this.request('POST', '/swarm/init', {
|
||||||
ListenAddr: '0.0.0.0:2377',
|
ListenAddr: '0.0.0.0:2377',
|
||||||
AdvertiseAddr: `${addvertisementIpArg}:2377`,
|
AdvertiseAddr: addvertisementIpArg ? `${addvertisementIpArg}:2377` : undefined,
|
||||||
DataPathPort: 4789,
|
DataPathPort: 4789,
|
||||||
DefaultAddrPool: ['10.10.0.0/8', '20.20.0.0/8'],
|
DefaultAddrPool: ['10.10.0.0/8', '20.20.0.0/8'],
|
||||||
SubnetSize: 24,
|
SubnetSize: 24,
|
||||||
|
@ -13,7 +13,7 @@ export class DockerImage {
|
|||||||
return images;
|
return images;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async findImageByName (dockerHost: DockerHost, imageNameArg: string) {
|
public static async findImageByName(dockerHost: DockerHost, imageNameArg: string) {
|
||||||
const images = await this.getImages(dockerHost);
|
const images = await this.getImages(dockerHost);
|
||||||
return images.find(image => {
|
return images.find(image => {
|
||||||
return image.RepoTags.includes(imageNameArg);
|
return image.RepoTags.includes(imageNameArg);
|
||||||
@ -36,7 +36,7 @@ export class DockerImage {
|
|||||||
`Successfully pulled image ${creationObject.imageUrl} from the registry`
|
`Successfully pulled image ${creationObject.imageUrl} from the registry`
|
||||||
);
|
);
|
||||||
const originTag = `${creationObject.imageUrl}:${creationObject.tag}`;
|
const originTag = `${creationObject.imageUrl}:${creationObject.tag}`;
|
||||||
console.log(originTag)
|
console.log(originTag);
|
||||||
const image = await DockerImage.findImageByName(dockerHostArg, originTag);
|
const image = await DockerImage.findImageByName(dockerHostArg, originTag);
|
||||||
return image;
|
return image;
|
||||||
} else {
|
} else {
|
||||||
@ -93,9 +93,7 @@ export class DockerImage {
|
|||||||
return this.RepoTags.length > 0;
|
return this.RepoTags.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public tagImage(newTag) {
|
public tagImage(newTag) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pulls the latest version from the registry
|
* pulls the latest version from the registry
|
||||||
@ -111,6 +109,4 @@ export class DockerImage {
|
|||||||
// TODO: Compare image digists before and after
|
// TODO: Compare image digists before and after
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,15 @@ export class DockerNetwork {
|
|||||||
Attachable: true,
|
Attachable: true,
|
||||||
Ingress: false
|
Ingress: false
|
||||||
});
|
});
|
||||||
if (response.statusCode < 300 ) {
|
if (response.statusCode < 300) {
|
||||||
plugins.smartlog.defaultLogger.log('info', 'Created network successfully');
|
plugins.smartlog.defaultLogger.log('info', 'Created network successfully');
|
||||||
return await DockerNetwork.getNetworkByName(dockerHost, networkCreationDescriptor.Name);
|
return await DockerNetwork.getNetworkByName(dockerHost, networkCreationDescriptor.Name);
|
||||||
} else {
|
} else {
|
||||||
plugins.smartlog.defaultLogger.log('error', 'There has been an error creating the wanted network');
|
plugins.smartlog.defaultLogger.log(
|
||||||
return null
|
'error',
|
||||||
|
'There has been an error creating the wanted network'
|
||||||
|
);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,4 +3,41 @@ import * as interfaces from './interfaces';
|
|||||||
|
|
||||||
import { DockerHost } from './docker.classes.host';
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
|
||||||
export class DockerService {}
|
export class DockerService {
|
||||||
|
// STATIC
|
||||||
|
public static async getServices(dockerHost: DockerHost) {
|
||||||
|
const services: DockerService[] = [];
|
||||||
|
const response = await dockerHost.request('GET', '/services');
|
||||||
|
for (const serviceObject of response.body) {
|
||||||
|
services.push(new DockerService(dockerHost, serviceObject));
|
||||||
|
}
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a service
|
||||||
|
*/
|
||||||
|
public static async createService(
|
||||||
|
dockerHost: DockerHost,
|
||||||
|
serviceCreationDescriptor: interfaces.IServiceCreationDescriptor
|
||||||
|
) {
|
||||||
|
dockerHost.request('POST', '/services/create', {
|
||||||
|
Name: serviceCreationDescriptor.Name,
|
||||||
|
TaskTemplate: {
|
||||||
|
ContainerSpec: {
|
||||||
|
Image: serviceCreationDescriptor.Image,
|
||||||
|
Labels: serviceCreationDescriptor.Labels
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Labels: serviceCreationDescriptor.Labels
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
|
public dockerHost: DockerHost;
|
||||||
|
|
||||||
|
constructor(dockerHostArg: DockerHost, serviceObject) {
|
||||||
|
this.dockerHost = dockerHostArg;
|
||||||
|
Object.assign(this, serviceObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export interface IImageCreationDescriptor {
|
export interface IImageCreationDescriptor {
|
||||||
imageUrl: string;
|
imageUrl: string;
|
||||||
tag: string;
|
tag: string;
|
||||||
}
|
}
|
||||||
|
@ -3,3 +3,4 @@ export * from './image';
|
|||||||
export * from './label';
|
export * from './label';
|
||||||
export * from './network';
|
export * from './network';
|
||||||
export * from './port';
|
export * from './port';
|
||||||
|
export * from './service';
|
||||||
|
7
ts/interfaces/service.ts
Normal file
7
ts/interfaces/service.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import * as interfaces from './';
|
||||||
|
|
||||||
|
export interface IServiceCreationDescriptor {
|
||||||
|
Name: string;
|
||||||
|
Image: string;
|
||||||
|
Labels: interfaces.TLabels;
|
||||||
|
}
|
Reference in New Issue
Block a user