fix(core): update
This commit is contained in:
parent
a4dc4e7950
commit
d56350ff28
6
package-lock.json
generated
6
package-lock.json
generated
@ -249,9 +249,9 @@
|
|||||||
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
|
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
|
||||||
},
|
},
|
||||||
"@pushrocks/smartrequest": {
|
"@pushrocks/smartrequest": {
|
||||||
"version": "1.1.23",
|
"version": "1.1.26",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.23.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.26.tgz",
|
||||||
"integrity": "sha512-Hws3YfzIE0b/E3aTkSugLskKWBq7e8HDXEN+RlRyTFONxW/XONKJFTw4mp3jk+puWpYGDoOTcP+Ua4jd19z9pA==",
|
"integrity": "sha512-8tYY+N42qdSTN5x40m6Afqmjo8HwkuZW+iWdMwO8PFxhrymcx8kuf5rYcG0wVLGtBjDgKgVNidb8GgFEhG40Yw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"@types/form-data": "^2.2.1",
|
"@types/form-data": "^2.2.1",
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
"@pushrocks/smartlog": "^2.0.19",
|
"@pushrocks/smartlog": "^2.0.19",
|
||||||
"@pushrocks/smartnetwork": "^1.1.14",
|
"@pushrocks/smartnetwork": "^1.1.14",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"@pushrocks/smartrequest": "^1.1.23",
|
"@pushrocks/smartrequest": "^1.1.26",
|
||||||
"rxjs": "^6.5.3"
|
"rxjs": "^6.5.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
10
test/test.ts
10
test/test.ts
@ -5,12 +5,12 @@ import { DockerService } from '../ts/index';
|
|||||||
let testDockerHost: docker.DockerHost;
|
let testDockerHost: docker.DockerHost;
|
||||||
|
|
||||||
tap.test('should create a new Dockersock instance', async () => {
|
tap.test('should create a new Dockersock instance', async () => {
|
||||||
testDockerHost = new docker.DockerHost();
|
testDockerHost = new docker.DockerHost('http://unix:/var/run/docker.sock:');
|
||||||
return expect(testDockerHost).to.be.instanceof(docker.DockerHost);
|
return expect(testDockerHost).to.be.instanceof(docker.DockerHost);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a docker swarm', async () => {
|
tap.test('should create a docker swarm', async () => {
|
||||||
|
await testDockerHost.activateSwarm();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Containers
|
// Containers
|
||||||
@ -63,7 +63,7 @@ tap.test('should activate swarm mode', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should list all services', async tools => {
|
tap.test('should list all services', async tools => {
|
||||||
const services = await docker.DockerService.getServices(testDockerHost);
|
const services = await testDockerHost.getServices();
|
||||||
console.log(services);
|
console.log(services);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ tap.test('should create a service', async () => {
|
|||||||
const testNetwork = await docker.DockerNetwork.createNetwork(testDockerHost, {
|
const testNetwork = await docker.DockerNetwork.createNetwork(testDockerHost, {
|
||||||
Name: 'testNetwork'
|
Name: 'testNetwork'
|
||||||
});
|
});
|
||||||
await DockerService.createService(testDockerHost, {
|
const testService = await DockerService.createService(testDockerHost, {
|
||||||
Image: 'nginx:latest',
|
Image: 'nginx:latest',
|
||||||
Labels: {
|
Labels: {
|
||||||
'testlabel': 'hi'
|
'testlabel': 'hi'
|
||||||
@ -80,6 +80,8 @@ tap.test('should create a service', async () => {
|
|||||||
networks: [testNetwork],
|
networks: [testNetwork],
|
||||||
networkAlias: 'testService'
|
networkAlias: 'testService'
|
||||||
});
|
});
|
||||||
|
await testService.remove();
|
||||||
|
await testNetwork.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as plugins from './docker.plugins';
|
import * as plugins from './docker.plugins';
|
||||||
import { DockerContainer } from './docker.classes.container';
|
import { DockerContainer } from './docker.classes.container';
|
||||||
import { DockerNetwork } from './docker.classes.network';
|
import { DockerNetwork } from './docker.classes.network';
|
||||||
|
import { DockerService } from './docker.classes.service';
|
||||||
|
|
||||||
export class DockerHost {
|
export class DockerHost {
|
||||||
/**
|
/**
|
||||||
@ -52,6 +53,14 @@ export class DockerHost {
|
|||||||
return containerArray;
|
return containerArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets all services
|
||||||
|
*/
|
||||||
|
public async getServices() {
|
||||||
|
const serviceArray = await DockerService.getServices(this);
|
||||||
|
return serviceArray;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -115,7 +124,8 @@ export class DockerHost {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Host: 'docker.sock'
|
Host: 'docker.sock'
|
||||||
},
|
},
|
||||||
requestBody: dataArg
|
requestBody: dataArg,
|
||||||
|
keepAlive: false
|
||||||
});
|
});
|
||||||
if (response.statusCode !== 200) {
|
if (response.statusCode !== 200) {
|
||||||
console.log(response.body);
|
console.log(response.body);
|
||||||
@ -130,10 +140,11 @@ export class DockerHost {
|
|||||||
{
|
{
|
||||||
method: methodArg,
|
method: methodArg,
|
||||||
headers: {
|
headers: {
|
||||||
// 'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Host: 'docker.sock'
|
Host: 'docker.sock'
|
||||||
},
|
},
|
||||||
requestBody: null
|
requestBody: null,
|
||||||
|
keepAlive: false
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -8,7 +8,9 @@ export class DockerNetwork {
|
|||||||
const dockerNetworks: DockerNetwork[] = [];
|
const dockerNetworks: DockerNetwork[] = [];
|
||||||
const response = await dockerHost.request('GET', '/networks');
|
const response = await dockerHost.request('GET', '/networks');
|
||||||
for (const networkObject of response.body) {
|
for (const networkObject of response.body) {
|
||||||
dockerNetworks.push(new DockerNetwork(dockerHost, networkObject));
|
const dockerNetwork = new DockerNetwork(dockerHost);
|
||||||
|
Object.assign(dockerNetwork, networkObject);
|
||||||
|
dockerNetworks.push(dockerNetwork);
|
||||||
}
|
}
|
||||||
return dockerNetworks;
|
return dockerNetworks;
|
||||||
}
|
}
|
||||||
@ -78,11 +80,8 @@ export class DockerNetwork {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(dockerHostArg: DockerHost, dockerNetworkObjectArg: any) {
|
constructor(dockerHostArg: DockerHost) {
|
||||||
this.dockerHost = dockerHostArg;
|
this.dockerHost = dockerHostArg;
|
||||||
Object.keys(dockerNetworkObjectArg).forEach(keyArg => {
|
|
||||||
this[keyArg] = dockerNetworkObjectArg[keyArg];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,18 +10,28 @@ export class DockerService {
|
|||||||
const services: DockerService[] = [];
|
const services: DockerService[] = [];
|
||||||
const response = await dockerHost.request('GET', '/services');
|
const response = await dockerHost.request('GET', '/services');
|
||||||
for (const serviceObject of response.body) {
|
for (const serviceObject of response.body) {
|
||||||
services.push(new DockerService(dockerHost, serviceObject));
|
const dockerService = new DockerService(dockerHost);
|
||||||
|
Object.assign(dockerService, serviceObject);
|
||||||
|
services.push(dockerService);
|
||||||
}
|
}
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async getServiceByName(dockerHost: DockerHost, networkName: string): Promise<DockerService> {
|
||||||
|
const allServices = await DockerService.getServices(dockerHost);
|
||||||
|
const wantedService = allServices.find(service => {
|
||||||
|
return service.Spec.Name === networkName;
|
||||||
|
});
|
||||||
|
return wantedService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a service
|
* creates a service
|
||||||
*/
|
*/
|
||||||
public static async createService(
|
public static async createService(
|
||||||
dockerHost: DockerHost,
|
dockerHost: DockerHost,
|
||||||
serviceCreationDescriptor: interfaces.IServiceCreationDescriptor
|
serviceCreationDescriptor: interfaces.IServiceCreationDescriptor
|
||||||
) {
|
): Promise<DockerService> {
|
||||||
// lets get the image
|
// lets get the image
|
||||||
plugins.smartlog.defaultLogger.log('info', `downloading image for service ${serviceCreationDescriptor.Name}`);
|
plugins.smartlog.defaultLogger.log('info', `downloading image for service ${serviceCreationDescriptor.Name}`);
|
||||||
const serviceImage = await DockerImage.createFromRegistry(dockerHost, {
|
const serviceImage = await DockerImage.createFromRegistry(dockerHost, {
|
||||||
@ -36,7 +46,7 @@ export class DockerService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dockerHost.request('POST', '/services/create', {
|
const response = await dockerHost.request('POST', '/services/create', {
|
||||||
Name: serviceCreationDescriptor.Name,
|
Name: serviceCreationDescriptor.Name,
|
||||||
TaskTemplate: {
|
TaskTemplate: {
|
||||||
ContainerSpec: {
|
ContainerSpec: {
|
||||||
@ -47,17 +57,37 @@ export class DockerService {
|
|||||||
Labels: serviceCreationDescriptor.Labels,
|
Labels: serviceCreationDescriptor.Labels,
|
||||||
Networks: networkArray
|
Networks: networkArray
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createdService = await DockerService.getServiceByName(dockerHost, serviceCreationDescriptor.Name);
|
||||||
|
return createdService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public dockerHost: DockerHost;
|
public dockerHostRef: DockerHost;
|
||||||
|
|
||||||
|
public ID: string;
|
||||||
|
public Version: { Index: number };
|
||||||
|
public CreatedAt: string;
|
||||||
|
public UpdatedAt: string;
|
||||||
|
public Spec: {
|
||||||
|
Name: string;
|
||||||
|
Labels: [any]; // ZBD
|
||||||
|
TaskTemplate: [any],
|
||||||
|
Mode: [any];
|
||||||
|
Networks: [any[]]
|
||||||
|
};
|
||||||
|
public Endpoint: { Spec: {}, VirtualIPs: [any[]] };
|
||||||
|
|
||||||
constructor(dockerHostArg: DockerHost, serviceObject) {
|
|
||||||
this.dockerHost = dockerHostArg;
|
constructor(dockerHostArg: DockerHost) {
|
||||||
Object.assign(this, serviceObject);
|
this.dockerHostRef = dockerHostArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
public async update() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async remove() {
|
||||||
|
await this.dockerHostRef.request('DELETE', `/services/${this.ID}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user