Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
1d75c1334f | |||
0824d5b910 | |||
0575e618f2 | |||
6b22f12051 | |||
51bf5cfd72 | |||
5cbcba2f1e | |||
16ffe53f30 | |||
4eae29cec9 | |||
188c7af749 | |||
49e7cc010b | |||
c58dad05cd | |||
38dca0c9a0 |
@ -47,7 +47,7 @@ trigger:
|
|||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- master
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- priv
|
- priv
|
@ -1,3 +1,6 @@
|
|||||||
FROM hosttoday/ht-docker-node:lts
|
FROM hosttoday/ht-docker-node:npmts
|
||||||
COPY ./node_modules /app-node/node_modules
|
RUN mkdir app-node
|
||||||
COPY ./dist /app-node/dist
|
COPY ./ /app-node/
|
||||||
|
WORKDIR /app-node
|
||||||
|
ENV CI true
|
||||||
|
CMD ["npmts"]
|
12
dist/dockersock.class.dockersock.d.ts
vendored
12
dist/dockersock.class.dockersock.d.ts
vendored
@ -1,12 +0,0 @@
|
|||||||
import "typings-global";
|
|
||||||
export declare class dockersock {
|
|
||||||
sockPath: string;
|
|
||||||
constructor(pathArg?: string);
|
|
||||||
listContainers(): any;
|
|
||||||
listContainersDetailed(): any;
|
|
||||||
listContainersRunning(): any;
|
|
||||||
listContainersStopped(): any;
|
|
||||||
listImages(): any;
|
|
||||||
clean(): any;
|
|
||||||
request(methodArg: string, routeArg: string, dataArg?: {}): any;
|
|
||||||
}
|
|
87
dist/dockersock.class.dockersock.js
vendored
87
dist/dockersock.class.dockersock.js
vendored
File diff suppressed because one or more lines are too long
22
dist/dockersock.classes.dockersock.d.ts
vendored
Normal file
22
dist/dockersock.classes.dockersock.d.ts
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export declare class Dockersock {
|
||||||
|
sockPath: string;
|
||||||
|
constructor(pathArg?: string);
|
||||||
|
auth(userArg: string, passArg: string): any;
|
||||||
|
listContainers(): any;
|
||||||
|
listContainersDetailed(): any;
|
||||||
|
listContainersRunning(): any;
|
||||||
|
listContainersStopped(): any;
|
||||||
|
listImages(): any;
|
||||||
|
listImagesDangling(): any;
|
||||||
|
pullImage(imageLabel: string): any;
|
||||||
|
createContainer(imageNameArg: any, pullFirst?: boolean): any;
|
||||||
|
getContainerId(): void;
|
||||||
|
startContainer(containerNameArg: any): any;
|
||||||
|
stopContainer(containerNameArg: any): any;
|
||||||
|
removeContainer(containerNameArg: any): any;
|
||||||
|
clean(): any;
|
||||||
|
getChange(): void;
|
||||||
|
request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): any;
|
||||||
|
requestStream(methodArg: any, routeArg: any, endArg?: boolean): any;
|
||||||
|
}
|
154
dist/dockersock.classes.dockersock.js
vendored
Normal file
154
dist/dockersock.classes.dockersock.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
dist/index.d.ts
vendored
Normal file
2
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export { Dockersock } from "./dockersock.classes.dockersock";
|
6
dist/index.js
vendored
Normal file
6
dist/index.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
var dockersock_classes_dockersock_1 = require("./dockersock.classes.dockersock");
|
||||||
|
exports.Dockersock = dockersock_classes_dockersock_1.Dockersock;
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsOENBQXlCLGlDQUFpQyxDQUFDO0FBQW5ELGdFQUFrRCIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5leHBvcnQge0RvY2tlcnNvY2t9IGZyb20gXCIuL2RvY2tlcnNvY2suY2xhc3Nlcy5kb2NrZXJzb2NrXCIiXX0=
|
18
docker-compose.yml
Normal file
18
docker-compose.yml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
nginx1 :
|
||||||
|
image: "nginx"
|
||||||
|
environment:
|
||||||
|
VIRTUAL_HOST: "test100.labkomp.de"
|
||||||
|
restart: always
|
||||||
|
container_name: nginx1
|
||||||
|
nginx2:
|
||||||
|
image: nginx
|
||||||
|
environment:
|
||||||
|
VIRTUAL_HOST: "test101.labkomp.de"
|
||||||
|
restart: always
|
||||||
|
container_name: nginx2
|
||||||
|
npmts-test-container:
|
||||||
|
image: "npmts-test-image"
|
||||||
|
volumes:
|
||||||
|
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||||
|
restart: always
|
||||||
|
container_name: npmts-test-container
|
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"mode":"default"
|
"mode":"default",
|
||||||
|
"coverageTreshold":10
|
||||||
}
|
}
|
14
package.json
14
package.json
@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "dockersock",
|
"name": "dockersock",
|
||||||
"version": "1.0.2",
|
"version": "1.0.5",
|
||||||
"description": "easy communication with docker from node, TypeScript ready",
|
"description": "easy communication with docker from node, TypeScript ready",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npmts",
|
"test": "npmts --notest && npm run build && npm run startdocker && npm run cleanup",
|
||||||
"testindocker": "npmts && docker-machine start default; eval \"$(docker-machine env default)\" && docker build -t test-image . && docker run test-image"
|
"build": "docker build -t npmts-test-image .",
|
||||||
|
"startdocker": "docker run -v /var/run/docker.sock:/var/run/docker.sock --name npmts-test-container npmts-test-image",
|
||||||
|
"cleanup": "docker rm npmts-test-container && docker rmi npmts-test-image"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,12 +27,14 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
|
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^5.0.10",
|
"beautylog": "^5.0.12",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"request": "^2.72.0",
|
"request": "^2.72.0",
|
||||||
"typings-global": "^1.0.3"
|
"typings-global": "^1.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts-g": "^5.2.6"
|
"npmts-g": "^5.2.6",
|
||||||
|
"should": "^9.0.2",
|
||||||
|
"typings-test": "^1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
test/test.d.ts
vendored
Normal file
2
test/test.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import "typings-test";
|
||||||
|
import "should";
|
37
test/test.js
Normal file
37
test/test.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-test");
|
||||||
|
require("should");
|
||||||
|
var index_1 = require("../dist/index");
|
||||||
|
describe("dockersock", function () {
|
||||||
|
describe(".Dockersock()", function () {
|
||||||
|
var testDockersock;
|
||||||
|
it("should create a new Dockersock instance", function () {
|
||||||
|
testDockersock = new index_1.Dockersock();
|
||||||
|
testDockersock.should.be.instanceof(index_1.Dockersock);
|
||||||
|
});
|
||||||
|
it("should list containers", function (done) {
|
||||||
|
testDockersock.listContainers()
|
||||||
|
.then(function (dataArg) {
|
||||||
|
console.log(dataArg);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("should list detailed containers", function (done) {
|
||||||
|
this.timeout(5000);
|
||||||
|
testDockersock.listContainersDetailed()
|
||||||
|
.then(function (dataArg) {
|
||||||
|
console.log(dataArg);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("should pull an image from imagetag", function (done) {
|
||||||
|
this.timeout(30000);
|
||||||
|
testDockersock.pullImage("hosttoday%2Fht-docker-dbase")
|
||||||
|
.then(function (dataArg) {
|
||||||
|
done();
|
||||||
|
}, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUVQLENBQUMsQ0FGYztBQUVmLHNCQUF5QixlQUV6QixDQUFDLENBRnVDO0FBRXhDLFFBQVEsQ0FBQyxZQUFZLEVBQUM7SUFDbEIsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixJQUFJLGNBQXlCLENBQUM7UUFDOUIsRUFBRSxDQUFDLHlDQUF5QyxFQUFDO1lBQ3pDLGNBQWMsR0FBRyxJQUFJLGtCQUFVLEVBQUUsQ0FBQztZQUNsQyxjQUFjLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsa0JBQVUsQ0FBQyxDQUFDO1FBQ3BELENBQUMsQ0FBQyxDQUFDO1FBQ0gsRUFBRSxDQUFDLHdCQUF3QixFQUFDLFVBQVMsSUFBSTtZQUNyQyxjQUFjLENBQUMsY0FBYyxFQUFFO2lCQUMxQixJQUFJLENBQUMsVUFBQyxPQUFPO2dCQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLENBQUM7Z0JBQ3JCLElBQUksRUFBRSxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUM7UUFDWCxDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQyxpQ0FBaUMsRUFBQyxVQUFTLElBQUk7WUFDOUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztZQUNuQixjQUFjLENBQUMsc0JBQXNCLEVBQUU7aUJBQ2xDLElBQUksQ0FBQyxVQUFDLE9BQU87Z0JBQ1YsT0FBTyxDQUFDLEdBQUcsQ0FBQyxPQUFPLENBQUMsQ0FBQztnQkFDckIsSUFBSSxFQUFFLENBQUM7WUFDWCxDQUFDLENBQUMsQ0FBQztRQUNYLENBQUMsQ0FBQyxDQUFDO1FBQ0gsRUFBRSxDQUFDLG9DQUFvQyxFQUFDLFVBQVMsSUFBSTtZQUNqRCxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFDO1lBQ3BCLGNBQWMsQ0FBQyxTQUFTLENBQUMsNkJBQTZCLENBQUM7aUJBQ2xELElBQUksQ0FBQyxVQUFDLE9BQU87Z0JBQ1YsSUFBSSxFQUFFLENBQUM7WUFDWCxDQUFDLEVBQUMsSUFBSSxDQUFDLENBQUM7UUFDaEIsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQztBQUNQLENBQUMsQ0FBQyxDQUFDIiwiZmlsZSI6InRlc3QuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLXRlc3RcIjtcbmltcG9ydCBcInNob3VsZFwiXG5cbmltcG9ydCB7RG9ja2Vyc29ja30gZnJvbSBcIi4uL2Rpc3QvaW5kZXhcIlxuXG5kZXNjcmliZShcImRvY2tlcnNvY2tcIixmdW5jdGlvbigpe1xuICAgIGRlc2NyaWJlKFwiLkRvY2tlcnNvY2soKVwiLGZ1bmN0aW9uKCl7XG4gICAgICAgIGxldCB0ZXN0RG9ja2Vyc29jazpEb2NrZXJzb2NrO1xuICAgICAgICBpdChcInNob3VsZCBjcmVhdGUgYSBuZXcgRG9ja2Vyc29jayBpbnN0YW5jZVwiLGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICB0ZXN0RG9ja2Vyc29jayA9IG5ldyBEb2NrZXJzb2NrKCk7XG4gICAgICAgICAgICB0ZXN0RG9ja2Vyc29jay5zaG91bGQuYmUuaW5zdGFuY2VvZihEb2NrZXJzb2NrKTtcbiAgICAgICAgfSk7XG4gICAgICAgIGl0KFwic2hvdWxkIGxpc3QgY29udGFpbmVyc1wiLGZ1bmN0aW9uKGRvbmUpe1xuICAgICAgICAgICAgdGVzdERvY2tlcnNvY2subGlzdENvbnRhaW5lcnMoKVxuICAgICAgICAgICAgICAgIC50aGVuKChkYXRhQXJnKT0+e1xuICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhkYXRhQXJnKTtcbiAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICB9KTtcbiAgICAgICAgaXQoXCJzaG91bGQgbGlzdCBkZXRhaWxlZCBjb250YWluZXJzXCIsZnVuY3Rpb24oZG9uZSl7XG4gICAgICAgICAgICB0aGlzLnRpbWVvdXQoNTAwMCk7XG4gICAgICAgICAgICB0ZXN0RG9ja2Vyc29jay5saXN0Q29udGFpbmVyc0RldGFpbGVkKClcbiAgICAgICAgICAgICAgICAudGhlbigoZGF0YUFyZyk9PntcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZGF0YUFyZyk7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgICAgIGl0KFwic2hvdWxkIHB1bGwgYW4gaW1hZ2UgZnJvbSBpbWFnZXRhZ1wiLGZ1bmN0aW9uKGRvbmUpe1xuICAgICAgICAgICAgdGhpcy50aW1lb3V0KDMwMDAwKTtcbiAgICAgICAgICAgIHRlc3REb2NrZXJzb2NrLnB1bGxJbWFnZShcImhvc3R0b2RheSUyRmh0LWRvY2tlci1kYmFzZVwiKVxuICAgICAgICAgICAgICAgIC50aGVuKChkYXRhQXJnKT0+e1xuICAgICAgICAgICAgICAgICAgICBkb25lKCk7XG4gICAgICAgICAgICAgICAgfSxkb25lKTtcbiAgICAgICAgfSlcbiAgICB9KTtcbn0pOyJdfQ==
|
36
test/test.ts
Normal file
36
test/test.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import "typings-test";
|
||||||
|
import "should"
|
||||||
|
|
||||||
|
import {Dockersock} from "../dist/index"
|
||||||
|
|
||||||
|
describe("dockersock",function(){
|
||||||
|
describe(".Dockersock()",function(){
|
||||||
|
let testDockersock:Dockersock;
|
||||||
|
it("should create a new Dockersock instance",function(){
|
||||||
|
testDockersock = new Dockersock();
|
||||||
|
testDockersock.should.be.instanceof(Dockersock);
|
||||||
|
});
|
||||||
|
it("should list containers",function(done){
|
||||||
|
testDockersock.listContainers()
|
||||||
|
.then((dataArg)=>{
|
||||||
|
console.log(dataArg);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("should list detailed containers",function(done){
|
||||||
|
this.timeout(5000);
|
||||||
|
testDockersock.listContainersDetailed()
|
||||||
|
.then((dataArg)=>{
|
||||||
|
console.log(dataArg);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("should pull an image from imagetag",function(done){
|
||||||
|
this.timeout(30000);
|
||||||
|
testDockersock.pullImage("hosttoday%2Fht-docker-dbase")
|
||||||
|
.then((dataArg)=>{
|
||||||
|
done();
|
||||||
|
},done);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
2
test/testEnv.sh
Normal file
2
test/testEnv.sh
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
docker build -t dockersock-image .
|
||||||
|
docker-compose up
|
@ -1,79 +0,0 @@
|
|||||||
import "typings-global"
|
|
||||||
import * as plugins from "./dockersock.plugins";
|
|
||||||
|
|
||||||
export class dockersock {
|
|
||||||
sockPath:string;
|
|
||||||
constructor(pathArg:string = "http://unix:/var/run/docker.sock:"){
|
|
||||||
this.sockPath = pathArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
// methods
|
|
||||||
listContainers() {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
this.request("GET","/containers")
|
|
||||||
.then(done.resolve);
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
listContainersDetailed() {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
let detailedDataObject = [];
|
|
||||||
this.listContainers()
|
|
||||||
.then((dataArg) => {
|
|
||||||
let recursiveCounter = 0;
|
|
||||||
let makeDetailed = function(){
|
|
||||||
if(typeof dataArg[recursiveCounter] != "undefined"){
|
|
||||||
this.request.get("GET","/containers/" + dataArg[recursiveCounter].Id)
|
|
||||||
.then((data) => {
|
|
||||||
recursiveCounter++;
|
|
||||||
detailedDataObject.push(data);
|
|
||||||
makeDetailed();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
done.resolve(detailedDataObject);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
makeDetailed();
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
listContainersRunning() {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
listContainersStopped() {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
listImages() {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
clean() {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
request(methodArg:string,routeArg:string,dataArg = {}){
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
let jsonArg:string = JSON.stringify(dataArg);
|
|
||||||
let options = {
|
|
||||||
method:methodArg,
|
|
||||||
url:this.sockPath + routeArg + "/json",
|
|
||||||
headers:{
|
|
||||||
"Content-Type":"application/json"
|
|
||||||
},
|
|
||||||
body:jsonArg
|
|
||||||
};
|
|
||||||
plugins.request(options,function(err, res, body){
|
|
||||||
if (!err && res.statusCode == 200) {
|
|
||||||
var responseObj = JSON.parse(body);
|
|
||||||
done.resolve(responseObj);
|
|
||||||
} else {
|
|
||||||
console.log(err);
|
|
||||||
console.log(res);
|
|
||||||
done.reject(err);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
133
ts/dockersock.classes.dockersock.ts
Normal file
133
ts/dockersock.classes.dockersock.ts
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
import "typings-global"
|
||||||
|
import * as plugins from "./dockersock.plugins";
|
||||||
|
|
||||||
|
export class Dockersock {
|
||||||
|
sockPath:string;
|
||||||
|
constructor(pathArg:string = "http://unix:/var/run/docker.sock:"){
|
||||||
|
this.sockPath = pathArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
// methods
|
||||||
|
auth(userArg:string,passArg:string){
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
this.request("POST","");
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
listContainers() {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
this.request("GET","/containers")
|
||||||
|
.then(done.resolve);
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
listContainersDetailed() {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
let detailedDataObject = [];
|
||||||
|
this.listContainers()
|
||||||
|
.then((dataArg) => {
|
||||||
|
let recursiveCounter = 0;
|
||||||
|
let makeDetailed = () => {
|
||||||
|
if(typeof dataArg[recursiveCounter] != "undefined"){
|
||||||
|
this.request("GET","/containers/" + dataArg[recursiveCounter].Id)
|
||||||
|
.then((dataArg2) => {
|
||||||
|
detailedDataObject.push(dataArg2);
|
||||||
|
recursiveCounter++;
|
||||||
|
// recursive call
|
||||||
|
makeDetailed();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
done.resolve(detailedDataObject);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
makeDetailed();
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
listContainersRunning() {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
listContainersStopped() {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
listImages() {
|
||||||
|
return this.request("GET","/images","?all=true");
|
||||||
|
}
|
||||||
|
listImagesDangling(){
|
||||||
|
return this.request("GET","/images","?dangling=true");
|
||||||
|
}
|
||||||
|
pullImage(imageLabel:string){
|
||||||
|
return this.requestStream("POST","/images/create?fromImage=" + imageLabel);
|
||||||
|
};
|
||||||
|
createContainer(imageNameArg,pullFirst:boolean = true){
|
||||||
|
return this.request("POST","/containers/create","",{
|
||||||
|
"image":imageNameArg
|
||||||
|
});
|
||||||
|
};
|
||||||
|
getContainerId(){
|
||||||
|
|
||||||
|
};
|
||||||
|
startContainer(containerNameArg){
|
||||||
|
return this.request("POST","/containers/"+ containerNameArg +"/start");
|
||||||
|
};
|
||||||
|
stopContainer(containerNameArg){
|
||||||
|
return this.request("POST","/containers/"+ containerNameArg +"/stop");
|
||||||
|
};
|
||||||
|
removeContainer(containerNameArg){
|
||||||
|
return this.request("DELETE","/containers/" + containerNameArg + "?v=1");
|
||||||
|
};
|
||||||
|
clean() {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
getChange(){
|
||||||
|
|
||||||
|
};
|
||||||
|
request(methodArg:string,routeArg:string,queryArg:string = "", dataArg = {}){
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
let jsonArg:string = JSON.stringify(dataArg);
|
||||||
|
let suffix:string = "";
|
||||||
|
if(methodArg == "GET") suffix = "/json";
|
||||||
|
let options = {
|
||||||
|
method:methodArg,
|
||||||
|
url:this.sockPath + routeArg + suffix + queryArg,
|
||||||
|
headers:{
|
||||||
|
"Content-Type":"application/json"
|
||||||
|
},
|
||||||
|
body:jsonArg
|
||||||
|
};
|
||||||
|
plugins.request(options,(err, res, body) => {
|
||||||
|
if (!err && res.statusCode == 200) {
|
||||||
|
var responseObj = JSON.parse(body);
|
||||||
|
done.resolve(responseObj);
|
||||||
|
} else {
|
||||||
|
console.log(err);
|
||||||
|
console.log(res);
|
||||||
|
done.reject(err);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
requestStream(methodArg,routeArg,endArg:boolean = true){
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
if(methodArg == "POST"){
|
||||||
|
let requestStream = plugins.request.post(this.sockPath + routeArg);
|
||||||
|
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);
|
||||||
|
done.reject();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
requestStream.on("data",(data:Buffer) => {
|
||||||
|
let status = JSON.parse(data.toString()).status;
|
||||||
|
plugins.beautylog.logReduced(status);
|
||||||
|
});
|
||||||
|
requestStream.on("end",()=> {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
}
|
2
ts/index.ts
Normal file
2
ts/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export {Dockersock} from "./dockersock.classes.dockersock"
|
Reference in New Issue
Block a user