Compare commits

...

4 Commits

Author SHA1 Message Date
57594728df 1.0.26 2019-01-10 00:24:35 +01:00
8430a4d6e0 fix(core): update 2019-01-10 00:24:35 +01:00
7f38868510 1.0.25 2018-07-17 08:39:38 +02:00
7a80718d27 fix(core): update 2018-07-17 08:39:37 +02:00
12 changed files with 1425 additions and 205 deletions

1425
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@mojoio/docker",
"version": "1.0.24",
"version": "1.0.26",
"description": "easy communication with docker remote api from node, TypeScript ready",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@ -26,14 +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.0.17",
"rxjs": "^6.2.2"
"@pushrocks/smartrequest": "^1.1.14",
"rxjs": "^6.3.3"
},
"devDependencies": {
"@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,2 +1 @@
import * as plugins from './dockersock.plugins';

View File

@ -1,10 +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 = [];
await dockerHostArg.request('GET', '/containers/json')
const result: DockerContainer[] = [];
const response = await dockerHostArg.request('GET', '/containers/json');
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

@ -1,5 +1,5 @@
import * as plugins from "./dockersock.plugins";
import { DockerContainer } from "./docker.classes.container";
import * as plugins from './dockersock.plugins';
import { DockerContainer } from './docker.classes.container';
export class DockerHost {
/**
@ -16,7 +16,7 @@ export class DockerHost {
* the constructor to instantiate a new docker sock instance
* @param pathArg
*/
constructor(pathArg: string = "http://unix:/var/run/docker.sock:") {
constructor(pathArg: string = 'http://unix:/var/run/docker.sock:') {
this.sockPath = pathArg;
}
@ -27,7 +27,7 @@ export class DockerHost {
*/
auth(registryArg: string, userArg: string, passArg: string) {
let done = plugins.smartpromise.defer();
this.request("POST", "");
this.request('POST', '');
return done.promise;
}
@ -37,22 +37,51 @@ 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');
};
});
}
/**
* fire a request
*/
async request(methodArg: string, routeArg: string, dataArg = {}) {
const requestUrl = `${this.sockPath}${routeArg}`
console.log(requestUrl);
const requestUrl = `${this.sockPath}${routeArg}`;
const response = await plugins.smartrequest.request(requestUrl, {
method: methodArg,
headers: {
"Content-Type": "application/json",
"Host": "docker.sock"
'Content-Type': 'application/json',
Host: 'docker.sock'
},
requestBody: dataArg
});
return response
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"
}