now has possibility to end streaming requests
This commit is contained in:
parent
56612f9ac9
commit
6a8751afd2
@ -43,6 +43,7 @@ release:
|
|||||||
- priv
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
|
image: hosttoday/ht-docker-node:npmts
|
||||||
stage: trigger
|
stage: trigger
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
|
2
dist/dockersock.classes.dockersock.d.ts
vendored
2
dist/dockersock.classes.dockersock.d.ts
vendored
@ -4,6 +4,7 @@ import * as plugins from "./dockersock.plugins";
|
|||||||
import { Observable } from "rxjs";
|
import { Observable } from "rxjs";
|
||||||
export declare class Dockersock {
|
export declare class Dockersock {
|
||||||
sockPath: string;
|
sockPath: string;
|
||||||
|
requestObjectmap: plugins.lik.Objectmap;
|
||||||
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<{}>;
|
||||||
@ -23,4 +24,5 @@ export declare class Dockersock {
|
|||||||
getChangeObservable(): Observable<{}>;
|
getChangeObservable(): Observable<{}>;
|
||||||
request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>;
|
request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>;
|
||||||
requestStream(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>;
|
requestStream(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>;
|
||||||
|
endRequests(): void;
|
||||||
}
|
}
|
||||||
|
16
dist/dockersock.classes.dockersock.js
vendored
16
dist/dockersock.classes.dockersock.js
vendored
File diff suppressed because one or more lines are too long
1
dist/dockersock.plugins.d.ts
vendored
1
dist/dockersock.plugins.d.ts
vendored
@ -1,5 +1,6 @@
|
|||||||
import "typings-global";
|
import "typings-global";
|
||||||
export import beautylog = require("beautylog");
|
export import beautylog = require("beautylog");
|
||||||
|
export import lik = require("lik");
|
||||||
export import q = require("q");
|
export import q = require("q");
|
||||||
export import request = require("request");
|
export import request = require("request");
|
||||||
export import rxjs = require("rxjs");
|
export import rxjs = require("rxjs");
|
||||||
|
3
dist/dockersock.plugins.js
vendored
3
dist/dockersock.plugins.js
vendored
@ -1,7 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
exports.beautylog = require("beautylog");
|
exports.beautylog = require("beautylog");
|
||||||
|
exports.lik = require("lik");
|
||||||
exports.q = require("q");
|
exports.q = require("q");
|
||||||
exports.request = require("request");
|
exports.request = require("request");
|
||||||
exports.rxjs = require("rxjs");
|
exports.rxjs = require("rxjs");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvZG9ja2Vyc29jay5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNqQixlQUFPLFdBQVcsU0FBUyxDQUFDLENBQUM7QUFDN0IsWUFBSSxXQUFXLE1BQU0sQ0FBQyxDQUFDIn0=
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvZG9ja2Vyc29jay5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFdBQUcsV0FBVyxLQUFLLENBQUMsQ0FBQztBQUNyQixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDakIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQyJ9
|
@ -27,15 +27,16 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "^0.0.27",
|
"@types/q": "^0.0.27",
|
||||||
"@types/request": "^0.0.27",
|
"@types/request": "^0.0.27",
|
||||||
"beautylog": "^5.0.14",
|
"beautylog": "^5.0.18",
|
||||||
|
"lik": "^1.0.7",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"request": "^2.73.0",
|
"request": "^2.74.0",
|
||||||
"rxjs": "^5.0.0-beta.10",
|
"rxjs": "^5.0.0-beta.10",
|
||||||
"typings-global": "^1.0.6"
|
"typings-global": "^1.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts-g": "^5.2.6",
|
"npmts-g": "^5.2.8",
|
||||||
"should": "^9.0.2",
|
"should": "^10.0.0",
|
||||||
"typings-test": "^1.0.1"
|
"typings-test": "^1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
test/test.js
12
test/test.js
@ -29,8 +29,16 @@ describe("dockersock", function () {
|
|||||||
testDockersock.pullImage("hosttoday/ht-docker-dbase")
|
testDockersock.pullImage("hosttoday/ht-docker-dbase")
|
||||||
.then((dataArg) => {
|
.then((dataArg) => {
|
||||||
done();
|
done();
|
||||||
}, done);
|
});
|
||||||
|
});
|
||||||
|
it("should return a change Objservable", function (done) {
|
||||||
|
this.timeout(10000);
|
||||||
|
testDockersock.getChangeObservable();
|
||||||
|
setTimeout(() => {
|
||||||
|
testDockersock.endRequests();
|
||||||
|
done();
|
||||||
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QUFJLEVBQUUsQ0FBQztZQUNYLENBQUMsRUFBQyxJQUFJLENBQUMsQ0FBQztRQUNaLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyJ9
|
10
test/test.ts
10
test/test.ts
@ -30,7 +30,15 @@ describe("dockersock",function(){
|
|||||||
testDockersock.pullImage("hosttoday/ht-docker-dbase")
|
testDockersock.pullImage("hosttoday/ht-docker-dbase")
|
||||||
.then((dataArg)=>{
|
.then((dataArg)=>{
|
||||||
done();
|
done();
|
||||||
},done);
|
});
|
||||||
|
});
|
||||||
|
it("should return a change Objservable",function(done){
|
||||||
|
this.timeout(10000);
|
||||||
|
testDockersock.getChangeObservable();
|
||||||
|
setTimeout(() => {
|
||||||
|
testDockersock.endRequests();
|
||||||
|
done();
|
||||||
|
},5000);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -1,22 +1,23 @@
|
|||||||
import "typings-global"
|
import "typings-global"
|
||||||
import * as plugins from "./dockersock.plugins";
|
import * as plugins from "./dockersock.plugins";
|
||||||
import {Observable} from "rxjs";
|
import { Observable } from "rxjs";
|
||||||
|
|
||||||
export class Dockersock {
|
export class Dockersock {
|
||||||
sockPath:string;
|
sockPath: string;
|
||||||
constructor(pathArg:string = "http://unix:/var/run/docker.sock:"){
|
requestObjectmap: plugins.lik.Objectmap = new plugins.lik.Objectmap();
|
||||||
|
constructor(pathArg: string = "http://unix:/var/run/docker.sock:") {
|
||||||
this.sockPath = pathArg;
|
this.sockPath = pathArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
};
|
};
|
||||||
@ -27,8 +28,8 @@ export class Dockersock {
|
|||||||
.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++;
|
||||||
@ -52,21 +53,21 @@ export class Dockersock {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
if(pullFirstArg){
|
if (pullFirstArg) {
|
||||||
this.pullImage(optionsArg.Image)
|
this.pullImage(optionsArg.Image)
|
||||||
.then(create)
|
.then(create)
|
||||||
.then(done.resolve);
|
.then(done.resolve);
|
||||||
@ -76,37 +77,37 @@ 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");
|
||||||
requestStream.on("response",(response) => {
|
requestStream.on("response", (response) => {
|
||||||
if(response.statusCode == 200){
|
if (response.statusCode == 200) {
|
||||||
plugins.beautylog.ok("request returned status 200, so we are good!");
|
plugins.beautylog.ok("request returned status 200, so we are good!");
|
||||||
} else {
|
} else {
|
||||||
plugins.beautylog.error("request returned error: " + response.statusCode);
|
plugins.beautylog.error("request returned error: " + response.statusCode);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
requestStream.on("data",(data:Buffer) => {
|
requestStream.on("data", (data: Buffer) => {
|
||||||
let status = JSON.parse(data.toString()).status;
|
let status = JSON.parse(data.toString()).status;
|
||||||
plugins.beautylog.logReduced(status);
|
plugins.beautylog.logReduced(status);
|
||||||
if(typeof cbPromise == "undefined" || cbPromise.state == "pending"){
|
if (typeof cbPromise == "undefined" || cbPromise.state == "pending") {
|
||||||
cbPromise = cb();
|
cbPromise = cb();
|
||||||
} else if (changeBuffered) {
|
} else if (changeBuffered) {
|
||||||
changeBuffered = true;
|
changeBuffered = true;
|
||||||
@ -116,54 +117,56 @@ export class Dockersock {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
requestStream.on("end",()=> {
|
requestStream.on("end", () => {
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
getChangeObservable(){
|
getChangeObservable() {
|
||||||
let options = {
|
let options = {
|
||||||
method:"GET",
|
method: "GET",
|
||||||
url:this.sockPath + "/events",
|
url: this.sockPath + "/events",
|
||||||
headers:{
|
headers: {
|
||||||
"Content-Type":"application/json",
|
"Content-Type": "application/json",
|
||||||
"Host":"docker.sock"
|
"Host": "docker.sock"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let requestStream = plugins.request(options,(err, res, body) => {
|
let requestStream = plugins.request(options, (err, res, body) => {
|
||||||
if (!err && res.statusCode == 200) {
|
if (!err && res.statusCode == 200) {
|
||||||
} else {
|
} else {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
console.log(res);
|
console.log(res);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
requestStream.on("response",(response) => {
|
requestStream.on("response", (response) => {
|
||||||
if(response.statusCode == 200){
|
this.requestObjectmap.add(response);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
plugins.beautylog.ok("request returned status 200, so we are good!");
|
plugins.beautylog.ok("request returned status 200, so we are good!");
|
||||||
} else {
|
} else {
|
||||||
plugins.beautylog.error("request returned error: " + response.statusCode);
|
plugins.beautylog.error("request returned error: " + response.statusCode);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let changeObservable = Observable.fromEvent(requestStream,"data");
|
let changeObservable = Observable.fromEvent(requestStream, "data");
|
||||||
requestStream.on("end",()=> {
|
requestStream.on("end", () => {
|
||||||
|
this.requestObjectmap.remove(requestStream);
|
||||||
});
|
});
|
||||||
return changeObservable;
|
return changeObservable;
|
||||||
}
|
}
|
||||||
request(methodArg:string,routeArg:string,queryArg:string = "", 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 = "";
|
||||||
if(methodArg == "GET") suffix = "/json";
|
if (methodArg == "GET") suffix = "/json";
|
||||||
let options = {
|
let options = {
|
||||||
method:methodArg,
|
method: methodArg,
|
||||||
url:this.sockPath + routeArg + suffix + queryArg,
|
url: this.sockPath + routeArg + suffix + queryArg,
|
||||||
headers:{
|
headers: {
|
||||||
"Content-Type":"application/json",
|
"Content-Type": "application/json",
|
||||||
"Host":"docker.sock"
|
"Host": "docker.sock"
|
||||||
},
|
},
|
||||||
body:jsonArg
|
body: jsonArg
|
||||||
};
|
};
|
||||||
//console.log(options);
|
//console.log(options);
|
||||||
plugins.request(options,(err, res, body) => {
|
plugins.request(options, (err, res, body) => {
|
||||||
if (!err && res.statusCode == 200) {
|
if (!err && res.statusCode == 200) {
|
||||||
var responseObj = JSON.parse(body);
|
var responseObj = JSON.parse(body);
|
||||||
done.resolve(responseObj);
|
done.resolve(responseObj);
|
||||||
@ -175,20 +178,20 @@ export class Dockersock {
|
|||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
requestStream(methodArg:string,routeArg:string,queryArg:string = "", 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 = "";
|
||||||
let options = {
|
let options = {
|
||||||
method:methodArg,
|
method: methodArg,
|
||||||
url:this.sockPath + routeArg + suffix + queryArg,
|
url: this.sockPath + routeArg + suffix + queryArg,
|
||||||
headers:{
|
headers: {
|
||||||
"Content-Type":"application/json",
|
"Content-Type": "application/json",
|
||||||
"Host":"docker.sock"
|
"Host": "docker.sock"
|
||||||
},
|
},
|
||||||
body:jsonArg
|
body: jsonArg
|
||||||
};
|
};
|
||||||
let requestStream = plugins.request(options,(err, res, body) => {
|
let requestStream = plugins.request(options, (err, res, body) => {
|
||||||
if (!err && res.statusCode == 200) {
|
if (!err && res.statusCode == 200) {
|
||||||
done.resolve();
|
done.resolve();
|
||||||
} else {
|
} else {
|
||||||
@ -197,19 +200,29 @@ export class Dockersock {
|
|||||||
done.reject(err);
|
done.reject(err);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
requestStream.on("response",(response) => {
|
requestStream.on("response", (response) => {
|
||||||
if(response.statusCode == 200){
|
this.requestObjectmap.add(response);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
plugins.beautylog.ok("request returned status 200, so we are good!");
|
plugins.beautylog.ok("request returned status 200, so we are good!");
|
||||||
} else {
|
} else {
|
||||||
plugins.beautylog.error("request returned error: " + response.statusCode);
|
plugins.beautylog.error("request returned error: " + response.statusCode);
|
||||||
done.reject(response);
|
done.reject(response);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
requestStream.on("data",(data:Buffer) => {
|
requestStream.on("data", (data: Buffer) => {
|
||||||
let status;
|
let status;
|
||||||
status = JSON.parse(data.toString()).status;
|
status = JSON.parse(data.toString()).status;
|
||||||
plugins.beautylog.logReduced(status);
|
plugins.beautylog.logReduced(status);
|
||||||
});
|
});
|
||||||
|
requestStream.on("end", () => {
|
||||||
|
this.requestObjectmap.remove(requestStream);
|
||||||
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
};
|
||||||
|
endRequests() {
|
||||||
|
this.requestObjectmap.forEach((itemArg: plugins.request.Request) => {
|
||||||
|
itemArg.emit("end");
|
||||||
|
});
|
||||||
|
this.requestObjectmap.wipe();
|
||||||
|
};
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import "typings-global";
|
import "typings-global";
|
||||||
export import beautylog = require("beautylog");
|
export import beautylog = require("beautylog");
|
||||||
|
export import lik = require("lik");
|
||||||
export import q = require("q");
|
export import q = require("q");
|
||||||
export import request = require("request");
|
export import request = require("request");
|
||||||
export import rxjs = require("rxjs");
|
export import rxjs = require("rxjs");
|
Loading…
Reference in New Issue
Block a user