Compare commits

...

3 Commits

Author SHA1 Message Date
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
4 changed files with 90 additions and 16 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,6 +1,6 @@
{
"name": "dockersock",
"version": "1.0.5",
"version": "1.0.6",
"description": "easy communication with docker from node, TypeScript ready",
"main": "dist/index.js",
"scripts": {

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();