This commit is contained in:
Philipp Kunz 2017-07-16 12:04:35 +02:00
parent 91d7f583e2
commit dd35e5d7d2
8 changed files with 521 additions and 1620 deletions

View File

@ -1,4 +1,3 @@
/// <reference types="request" />
/// <reference types="q" /> /// <reference types="q" />
import "typings-global"; import "typings-global";
import * as plugins from "./dockersock.plugins"; import * as plugins from "./dockersock.plugins";
@ -6,7 +5,7 @@ import { Observable } from "rxjs";
import { Objectmap } from 'lik'; import { Objectmap } from 'lik';
export declare class Dockersock { export declare class Dockersock {
sockPath: string; sockPath: string;
requestObjectmap: Objectmap<plugins.request.Request>; requestObjectmap: Objectmap<any>;
constructor(pathArg?: string); constructor(pathArg?: string);
auth(userArg: string, passArg: string): plugins.q.Promise<{}>; auth(userArg: string, passArg: string): plugins.q.Promise<{}>;
listContainers(): plugins.q.Promise<{}>; listContainers(): plugins.q.Promise<{}>;
@ -27,7 +26,24 @@ export declare class Dockersock {
* gets you an observable that reports changes in the docker infrastructure * gets you an observable that reports changes in the docker infrastructure
*/ */
getChangeObservable(): Observable<{}>; getChangeObservable(): Observable<{}>;
/**
* fire a request
* @param methodArg
* @param routeArg
* @param queryArg
* @param dataArg
*/
request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>; request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>;
/**
* fire a streaming request
* @param methodArg
* @param routeArg
* @param queryArg
* @param dataArg
*/
requestStream(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>; requestStream(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>;
/**
* end all currently streaming requests
*/
endRequests(): void; endRequests(): void;
} }

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@
"npmdocker":{ "npmdocker":{
"baseImage":"hosttoday/ht-docker-node:npmci", "baseImage":"hosttoday/ht-docker-node:npmci",
"command":"(npmci command yarn global add npmts) && npmts", "command":"(npmci command yarn global add npmts) && npmts",
"dockerSock":"true" "dockerSock": true
}, },
"npmci": { "npmci": {
"globalNpmTools": [ "globalNpmTools": [

View File

@ -5,7 +5,7 @@
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "npmdocker" "test": "(npmts --notest && npmdocker)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -26,16 +26,15 @@
"homepage": "https://gitlab.com/pushrocks/dockersock#README", "homepage": "https://gitlab.com/pushrocks/dockersock#README",
"dependencies": { "dependencies": {
"@types/q": "1.x.x", "@types/q": "1.x.x",
"@types/request": "0.x.x", "beautylog": "^6.1.10",
"beautylog": "^6.1.5", "lik": "^1.0.38",
"lik": "^1.0.27",
"q": "^1.5.0", "q": "^1.5.0",
"request": "^2.81.0", "request": "^2.81.0",
"rxjs": "^5.2.0", "rxjs": "^5.4.2",
"typings-global": "^1.0.14" "typings-global": "^1.0.19"
}, },
"devDependencies": { "devDependencies": {
"observable-to-promise": "^0.5.0", "observable-to-promise": "^0.5.0",
"tapbundle": "^1.0.5" "tapbundle": "^1.1.1"
} }
} }

View File

@ -8,29 +8,27 @@ let testDockersock: Dockersock;
tap.test("should create a new Dockersock instance", async () => { tap.test("should create a new Dockersock instance", async () => {
testDockersock = new Dockersock(); testDockersock = new Dockersock();
return expect(testDockersock).to.be.instanceof(Dockersock); return expect(testDockersock).to.be.instanceof(Dockersock);
}).catch(tap.threw); })
tap.test("should list containers", async () => { tap.test("should list containers", async () => {
await testDockersock.listContainers() let data = await testDockersock.listContainers()
.then(async (dataArg) => { console.log(data)
console.log(dataArg); })
});
}).catch(tap.threw);
tap.test("should list detailed containers", async () => { tap.test("should list detailed containers", async () => {
await testDockersock.listContainersDetailed() let data = await testDockersock.listContainersDetailed()
.then(async (dataArg) => { console.log(data)
console.log(dataArg); })
});
}).catch(tap.threw);
tap.test("should pull an image from imagetag", async () => { tap.test("should pull an image from imagetag", async () => {
await testDockersock.pullImage("hosttoday/ht-docker-node:npmci") await testDockersock.pullImage("hosttoday/ht-docker-node:npmci")
}).catch(tap.threw); })
/*tap.test("should return a change Objservable", async () => { tap.test("should return a change Objservable", async () => {
let myObservable = testDockersock.getChangeObservable(); let myObservable = testDockersock.getChangeObservable();
testDockersock.endRequests(); testDockersock.endRequests();
let testPromise = observableToPromise(myObservable) let testPromise = observableToPromise(myObservable)
return await expect(testPromise).to.eventually.be.fulfilled return await expect(testPromise).to.eventually.be.fulfilled
}).catch(tap.threw);*/ })
tap.start()

View File

@ -13,26 +13,26 @@ export class Dockersock {
} }
// methods // methods
auth(userArg: string, passArg: string) { auth (userArg: string, passArg: string) {
let done = plugins.q.defer(); let done = plugins.q.defer();
this.request("POST", ""); this.request("POST", "");
return done.promise; return done.promise;
} }
listContainers() { listContainers () {
let done = plugins.q.defer(); let done = plugins.q.defer();
this.request("GET", "/containers") this.request("GET", "/containers")
.then(done.resolve); .then(done.resolve);
return done.promise; return done.promise;
}; };
listContainersDetailed() { listContainersDetailed () {
let done = plugins.q.defer(); let done = plugins.q.defer();
let detailedDataObject = []; let detailedDataObject = [];
this.listContainers() this.listContainers()
.then((dataArg) => { .then((dataArg) => {
let recursiveCounter = 0; let recursiveCounter = 0;
let makeDetailed = () => { let makeDetailed = () => {
if (typeof dataArg[recursiveCounter] != "undefined") { if (typeof dataArg[ recursiveCounter ] != "undefined") {
this.request("GET", "/containers/" + dataArg[recursiveCounter].Id) this.request("GET", "/containers/" + dataArg[ recursiveCounter ].Id)
.then((dataArg2) => { .then((dataArg2) => {
detailedDataObject.push(dataArg2); detailedDataObject.push(dataArg2);
recursiveCounter++; recursiveCounter++;
@ -47,25 +47,25 @@ export class Dockersock {
}); });
return done.promise; return done.promise;
}; };
listContainersRunning() { listContainersRunning () {
let done = plugins.q.defer(); let done = plugins.q.defer();
return done.promise; return done.promise;
} }
listContainersStopped() { listContainersStopped () {
let done = plugins.q.defer(); let done = plugins.q.defer();
return done.promise; return done.promise;
} }
listImages() { listImages () {
return this.request("GET", "/images", "?all=true"); return this.request("GET", "/images", "?all=true");
} }
listImagesDangling() { listImagesDangling () {
return this.request("GET", "/images", "?dangling=true"); return this.request("GET", "/images", "?dangling=true");
} }
pullImage(imageLabelArg: string) { pullImage (imageLabelArg: string) {
let imageLabel = encodeURI(imageLabelArg); let imageLabel = encodeURI(imageLabelArg);
return this.requestStream("POST", "/images/create?fromImage=" + imageLabel); return this.requestStream("POST", "/images/create?fromImage=" + imageLabel);
}; };
createContainer(optionsArg, pullFirstArg: boolean = true) { createContainer (optionsArg, pullFirstArg: boolean = true) {
let done = plugins.q.defer(); let done = plugins.q.defer();
let create = () => { let create = () => {
return this.request("POST", "/containers/create", "", optionsArg); return this.request("POST", "/containers/create", "", optionsArg);
@ -80,23 +80,23 @@ export class Dockersock {
} }
return done.promise; return done.promise;
}; };
getContainerId() { getContainerId () {
}; };
startContainer(containerNameArg) { startContainer (containerNameArg) {
return this.request("POST", "/containers/" + containerNameArg + "/start"); return this.request("POST", "/containers/" + containerNameArg + "/start");
}; };
stopContainer(containerNameArg) { stopContainer (containerNameArg) {
return this.request("POST", "/containers/" + containerNameArg + "/stop"); return this.request("POST", "/containers/" + containerNameArg + "/stop");
}; };
removeContainer(containerNameArg) { removeContainer (containerNameArg) {
return this.request("DELETE", "/containers/" + containerNameArg + "?v=1"); return this.request("DELETE", "/containers/" + containerNameArg + "?v=1");
}; };
clean() { clean () {
let done = plugins.q.defer(); let done = plugins.q.defer();
return done.promise; return done.promise;
}; };
callOnChange(cb: Function) { callOnChange (cb: Function) {
let cbPromise; let cbPromise;
let changeBuffered: boolean = false; // when cb is running then buffer any consequent change let changeBuffered: boolean = false; // when cb is running then buffer any consequent change
let requestStream = plugins.request.get(this.sockPath + "/events"); let requestStream = plugins.request.get(this.sockPath + "/events");
@ -128,7 +128,7 @@ export class Dockersock {
/** /**
* gets you an observable that reports changes in the docker infrastructure * gets you an observable that reports changes in the docker infrastructure
*/ */
getChangeObservable() { getChangeObservable () {
let options = { let options = {
method: "GET", method: "GET",
url: this.sockPath + "/events", url: this.sockPath + "/events",
@ -160,7 +160,16 @@ export class Dockersock {
}); });
return changeObservable; return changeObservable;
} }
request(methodArg: string, routeArg: string, queryArg: string = "", dataArg = {}) {
/**
* fire a request
* @param methodArg
* @param routeArg
* @param queryArg
* @param dataArg
*/
request (methodArg: string, routeArg: string, queryArg: string = "", dataArg = {}) {
let done = plugins.q.defer(); let done = plugins.q.defer();
let jsonArg: string = JSON.stringify(dataArg); let jsonArg: string = JSON.stringify(dataArg);
let suffix: string = ""; let suffix: string = "";
@ -187,7 +196,15 @@ export class Dockersock {
}); });
return done.promise; return done.promise;
} }
requestStream(methodArg: string, routeArg: string, queryArg: string = "", dataArg = {}) {
/**
* fire a streaming request
* @param methodArg
* @param routeArg
* @param queryArg
* @param dataArg
*/
requestStream (methodArg: string, routeArg: string, queryArg: string = "", dataArg = {}) {
let done = plugins.q.defer(); let done = plugins.q.defer();
let jsonArg: string = JSON.stringify(dataArg); let jsonArg: string = JSON.stringify(dataArg);
let suffix: string = ""; let suffix: string = "";
@ -231,8 +248,10 @@ export class Dockersock {
return done.promise; return done.promise;
}; };
/**
endRequests() { * end all currently streaming requests
*/
endRequests () {
setTimeout(() => { setTimeout(() => {
this.requestObjectmap.forEach((itemArg: plugins.request.Request) => { this.requestObjectmap.forEach((itemArg: plugins.request.Request) => {
itemArg.emit("end"); itemArg.emit("end");

1590
yarn.lock

File diff suppressed because it is too large Load Diff