Compare commits

...

8 Commits

Author SHA1 Message Date
bfda5177a6 1.0.8 2016-07-11 17:54:29 +02:00
ad2a1ac03d update timeout 2016-07-11 17:44:02 +02:00
99db0b902e remove confusing file 2016-07-11 17:41:47 +02:00
515d2d4970 1.0.7 2016-07-11 17:24:00 +02:00
abf2234480 add typings to package.json 2016-07-11 17:23:54 +02:00
b4c6bff74d 1.0.6 2016-06-17 02:38:03 +02:00
4da7f5194a implement .createContainer() 2016-06-17 02:38:00 +02:00
c356042075 implement .callOnChange() 2016-06-17 02:21:48 +02:00
6 changed files with 93 additions and 20 deletions

View File

@ -10,13 +10,13 @@ export declare class Dockersock {
listImages(): any;
listImagesDangling(): any;
pullImage(imageLabel: string): any;
createContainer(imageNameArg: any, pullFirst?: boolean): any;
createContainer(optionsArg: any, pullFirstArg?: boolean): any;
getContainerId(): void;
startContainer(containerNameArg: any): any;
stopContainer(containerNameArg: any): any;
removeContainer(containerNameArg: any): any;
clean(): any;
getChange(): void;
callOnChange(cb: Function): void;
request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): any;
requestStream(methodArg: any, routeArg: any, endArg?: boolean): any;
}

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,9 @@
{
"name": "dockersock",
"version": "1.0.5",
"version": "1.0.8",
"description": "easy communication with docker from node, TypeScript ready",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "npmts --notest && npm run build && npm run startdocker && npm run cleanup",
"build": "docker build -t npmts-test-image .",

View File

@ -1,5 +1,5 @@
import "typings-test";
import "should"
import "should";
import {Dockersock} from "../dist/index"
@ -26,7 +26,7 @@ describe("dockersock",function(){
});
});
it("should pull an image from imagetag",function(done){
this.timeout(30000);
this.timeout(60000);
testDockersock.pullImage("hosttoday%2Fht-docker-dbase")
.then((dataArg)=>{
done();

View File

@ -1,2 +0,0 @@
docker build -t dockersock-image .
docker-compose up

View File

@ -59,10 +59,20 @@ export class Dockersock {
pullImage(imageLabel:string){
return this.requestStream("POST","/images/create?fromImage=" + imageLabel);
};
createContainer(imageNameArg,pullFirst:boolean = true){
return this.request("POST","/containers/create","",{
"image":imageNameArg
});
createContainer(optionsArg,pullFirstArg:boolean = true){
let done = plugins.q.defer();
let create = () => {
return this.request("POST","/containers/create","",optionsArg);
}
if(pullFirstArg){
this.pullImage(optionsArg.Image)
.then(create)
.then(done.resolve);
} else {
create()
.then(done.resolve)
}
return done.promise;
};
getContainerId(){
@ -80,8 +90,33 @@ export class Dockersock {
let done = plugins.q.defer();
return done.promise;
};
getChange(){
callOnChange(cb:Function){
let cbPromise;
let changeBuffered:boolean = false; // when cb is running then buffer any consequent change
let requestStream = plugins.request.get(this.sockPath + "/events");
requestStream.on("response",(response) => {
if(response.statusCode == 200){
plugins.beautylog.ok("request returned status 200, so we are good!");
} else {
plugins.beautylog.error("request returned error: " + response.statusCode);
}
});
requestStream.on("data",(data:Buffer) => {
let status = JSON.parse(data.toString()).status;
plugins.beautylog.logReduced(status);
if(typeof cbPromise == "undefined" || cbPromise.state == "pending"){
cbPromise = cb();
} else if (changeBuffered) {
changeBuffered = true;
cbPromise.then(() => {
changeBuffered = false;
cbPromise = cb();
});
}
});
requestStream.on("end",()=> {
});
};
request(methodArg:string,routeArg:string,queryArg:string = "", dataArg = {}){
let done = plugins.q.defer();