Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
515d2d4970 | |||
abf2234480 | |||
b4c6bff74d | |||
4da7f5194a | |||
c356042075 |
4
dist/dockersock.classes.dockersock.d.ts
vendored
4
dist/dockersock.classes.dockersock.d.ts
vendored
@ -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;
|
||||
}
|
||||
|
53
dist/dockersock.classes.dockersock.js
vendored
53
dist/dockersock.classes.dockersock.js
vendored
File diff suppressed because one or more lines are too long
@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "dockersock",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.7",
|
||||
"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 .",
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user