fix(core): update

This commit is contained in:
Philipp Kunz 2019-01-10 00:24:35 +01:00
parent 7f38868510
commit 8430a4d6e0
10 changed files with 1032 additions and 268 deletions

1118
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -26,15 +26,18 @@
},
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
"dependencies": {
"@pushrocks/lik": "^3.0.1",
"@pushrocks/smartlog": "^2.0.1",
"@pushrocks/lik": "^3.0.4",
"@pushrocks/smartlog": "^2.0.9",
"@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartrequest": "^1.1.1",
"rxjs": "^6.2.2"
"@pushrocks/smartrequest": "^1.1.14",
"rxjs": "^6.3.3"
},
"devDependencies": {
"@gitzone/tsrun": "^1.1.9",
"@pushrocks/tapbundle": "^3.0.1"
"@gitzone/tsrun": "^1.1.17",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.18",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0"
},
"private": false
}

View File

@ -13,16 +13,18 @@ tap.test('should list containers', async () => {
console.log(containers);
});
/*
tap.test('should pull an image from imagetag', async () => {
await testDockerHost.pullImage('hosttoday/ht-docker-node:npmci');
tap.skip.test('should pull an image from imagetag', async () => {
// await testDockerHost.pullImage('hosttoday/ht-docker-node:npmci');
});
tap.skip.test('should return a change Objservable', async () => {
let myObservable = testDockerHost.getChangeObservable();
testDockerHost.endRequests();
let testPromise = observableToPromise(myObservable);
return await expect(testPromise).to.eventually.be.fulfilled;
}); */
tap.test('should return a change Objservable', async (tools) => {
const testObservable = await testDockerHost.getEventObservable();
const subscription = testObservable.subscribe(changeObject => {
console.log(changeObject);
});
await tools.delayFor(2000);
subscription.unsubscribe();
});
tap.start();

View File

@ -1,13 +1,73 @@
import * as plugins from './dockersock.plugins';
import * as interfaces from './interfaces';
import { DockerHost } from './docker.classes.host';
export class DockerContainer {
// ======
// STATIC
// ======
/**
* get all containers
*/
static async getContainers(dockerHostArg: DockerHost): Promise<DockerContainer[]> {
const result: DockerContainer[] = [];
const response = await dockerHostArg.request('GET', '/containers/json');
for(const containerResult in response.body) {
result.push(new DockerContainer());
for (const containerResult of response.body) {
result.push(new DockerContainer(containerResult));
}
return result;
}
/**
*
* @param containerId
*/
static async getContainerById(containerId: string) {
}
static async create() {}
// ========
// INSTANCE
// ========
constructor(dockerContainerObjectArg: any) {
Object.keys(dockerContainerObjectArg).forEach(keyArg => {
this[keyArg] = dockerContainerObjectArg[keyArg];
})
}
Id: string;
Names: string[];
Image: string;
ImageID: string;
Command: string;
Created: number;
Ports: interfaces.TPorts;
Labels: interfaces.TLabels;
State: string;
Status: string;
HostConfig: any;
NetworkSettings: {
Networks: {
[key: string]: {
IPAMConfig: any;
Links: any;
Aliases: any;
NetworkID: string;
EndpointID: string;
Gateway: string;
IPAddress: string;
IPPrefixLen: number;
IPv6Gateway: string;
GlobalIPv6Address: string;
GlobalIPv6PrefixLen: number;
MacAddress: string;
DriverOpts: any;
};
};
};
Mounts: any;
}

View File

@ -37,6 +37,18 @@ export class DockerHost {
async getContainers() {
const containerArray = await DockerContainer.getContainers(this);
return containerArray;
};
async getEventObservable(): Promise<plugins.rxjs.Observable<any>> {
const response = await this.requestStreaming('GET', '/events');
return plugins.rxjs.Observable.create(observer => {
response.on('data', data => {
observer.next(data.toString());
});
return () => {
response.emit('end');
};
});
}
/**
@ -44,7 +56,6 @@ export class DockerHost {
*/
async request(methodArg: string, routeArg: string, dataArg = {}) {
const requestUrl = `${this.sockPath}${routeArg}`;
console.log(requestUrl);
const response = await plugins.smartrequest.request(requestUrl, {
method: methodArg,
headers: {
@ -55,4 +66,22 @@ export class DockerHost {
});
return response;
}
async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) {
const requestUrl = `${this.sockPath}${routeArg}`;
const response = await plugins.smartrequest.request(
requestUrl, {
method: methodArg,
headers: {
// 'Content-Type': 'application/json',
Host: 'docker.sock'
},
requestBody: null
},
true
);
console.log(response.statusCode);
console.log(response.body);
return response;
}
}

View File

@ -1,6 +1,19 @@
import 'typings-global';
export import smartlog = require('@pushrocks/smartlog');
export import lik = require('@pushrocks/lik');
export import smartpromise = require('@pushrocks/smartpromise');
export import smartrequest = require('@pushrocks/smartrequest');
export import rxjs = require('rxjs');
// @pushrocks scope
import * as lik from '@pushrocks/lik';
import * as smartlog from '@pushrocks/smartlog';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
export {
lik,
smartlog,
smartpromise,
smartrequest
};
// third party
import * as rxjs from 'rxjs';
export {
rxjs
};

2
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1,2 @@
export * from './label';
export * from './port';

2
ts/interfaces/label.ts Normal file
View File

@ -0,0 +1,2 @@
// tslint:disable-next-line: interface-over-type-literal
export type TLabels = {[key: string]: string };

6
ts/interfaces/port.ts Normal file
View File

@ -0,0 +1,6 @@
export interface IPort {
PrivatePort: 80;
Type: 'tcp';
}
export type TPorts = IPort[];

17
tslint.json Normal file
View File

@ -0,0 +1,17 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}