Compare commits

...

6 Commits

Author SHA1 Message Date
16ffe53f30 1.0.3 2016-06-16 04:45:28 +02:00
4eae29cec9 implement start and stop for containers 2016-06-16 04:45:22 +02:00
188c7af749 fix CI 2016-06-16 04:21:28 +02:00
49e7cc010b add tests with in docker 2016-06-16 04:18:10 +02:00
c58dad05cd prepare for in docker test trough npmts 2016-06-16 02:41:17 +02:00
38dca0c9a0 update test Environment 2016-06-16 01:56:53 +02:00
16 changed files with 260 additions and 114 deletions

View File

@ -47,7 +47,7 @@ trigger:
script:
- npmci trigger
only:
- master
- tags
tags:
- lossless
- priv

View File

@ -1,3 +1,6 @@
FROM hosttoday/ht-docker-node:lts
COPY ./node_modules /app-node/node_modules
COPY ./dist /app-node/dist
FROM hosttoday/ht-docker-node:npmts
RUN mkdir app-node
COPY ./ /app-node/
WORKDIR /app-node
ENV CI true
CMD ["npmts"]

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,17 @@
import "typings-global";
export declare class dockersock {
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;
getContainerId(): void;
startContainer(containerNameArg: any): any;
stopContainer(): any;
clean(): any;
getChange(): void;
request(methodArg: string, routeArg: string, dataArg?: {}): any;
}

110
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
View File

@ -0,0 +1,2 @@
import "typings-global";
export { Dockersock } from "./dockersock.classes.dockersock";

6
dist/index.js vendored Normal file
View 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
View 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

View File

@ -1,3 +1,4 @@
{
"mode":"default"
"mode":"default",
"coverageTreshold":10
}

View File

@ -1,11 +1,13 @@
{
"name": "dockersock",
"version": "1.0.2",
"version": "1.0.3",
"description": "easy communication with docker from node, TypeScript ready",
"main": "dist/index.js",
"scripts": {
"test": "npmts",
"testindocker": "npmts && docker-machine start default; eval \"$(docker-machine env default)\" && docker build -t test-image . && docker run test-image"
"test": "npmts --notest && npm run build && npm run startdocker && npm run cleanup",
"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": {
"type": "git",
@ -31,6 +33,8 @@
"typings-global": "^1.0.3"
},
"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
View File

@ -0,0 +1,2 @@
import "typings-test";
import "should";

30
test/test.js Normal file
View File

@ -0,0 +1,30 @@
"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();
});
});
});
});
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUVQLENBQUMsQ0FGYztBQUVmLHNCQUF5QixlQUV6QixDQUFDLENBRnVDO0FBRXhDLFFBQVEsQ0FBQyxZQUFZLEVBQUM7SUFDbEIsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixJQUFJLGNBQXlCLENBQUM7UUFDOUIsRUFBRSxDQUFDLHlDQUF5QyxFQUFDO1lBQ3pDLGNBQWMsR0FBRyxJQUFJLGtCQUFVLEVBQUUsQ0FBQztZQUNsQyxjQUFjLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsa0JBQVUsQ0FBQyxDQUFDO1FBQ3BELENBQUMsQ0FBQyxDQUFDO1FBQ0gsRUFBRSxDQUFDLHdCQUF3QixFQUFDLFVBQVMsSUFBSTtZQUNyQyxjQUFjLENBQUMsY0FBYyxFQUFFO2lCQUMxQixJQUFJLENBQUMsVUFBQyxPQUFPO2dCQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLENBQUM7Z0JBQ3JCLElBQUksRUFBRSxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUM7UUFDWCxDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQyxpQ0FBaUMsRUFBQyx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yZyk9PntcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZGF0YUFyZyk7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgICAgIGl0KFwic2hvdWxkIGxpc3QgZGV0YWlsZWQgY29udGFpbmVyc1wiLGZ1bmN0aW9uKGRvbmUpe1xuICAgICAgICAgICAgdGhpcy50aW1lb3V0KDUwMDApO1xuICAgICAgICAgICAgdGVzdERvY2tlcnNvY2subGlzdENvbnRhaW5lcnNEZXRhaWxlZCgpXG4gICAgICAgICAgICAgICAgLnRoZW4oKGRhdGFBcmcpPT57XG4gICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGRhdGFBcmcpO1xuICAgICAgICAgICAgICAgICAgICBkb25lKCk7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuICAgIH0pO1xufSk7Il19

29
test/test.ts Normal file
View File

@ -0,0 +1,29 @@
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();
});
});
});
});

2
test/testEnv.sh Normal file
View File

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

View File

@ -1,13 +1,18 @@
import "typings-global"
import * as plugins from "./dockersock.plugins";
export class dockersock {
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")
@ -20,12 +25,13 @@ export class dockersock {
this.listContainers()
.then((dataArg) => {
let recursiveCounter = 0;
let makeDetailed = function(){
let makeDetailed = () => {
if(typeof dataArg[recursiveCounter] != "undefined"){
this.request.get("GET","/containers/" + dataArg[recursiveCounter].Id)
.then((data) => {
this.request("GET","/containers/" + dataArg[recursiveCounter].Id)
.then((dataArg2) => {
detailedDataObject.push(dataArg2);
recursiveCounter++;
detailedDataObject.push(data);
// recursive call
makeDetailed();
});
} else {
@ -48,23 +54,36 @@ export class dockersock {
let done = plugins.q.defer();
return done.promise;
}
getContainerId(){
}
startContainer(containerNameArg){
return this.request("POST","/containers/"+ containerNameArg +"/start");
};
stopContainer(){
return this.request("POST","/containers/"+ containerNameArg +"/stop");
}
clean() {
let done = plugins.q.defer();
return done.promise;
}
};
getChange(){
};
request(methodArg:string,routeArg: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 + "/json",
url:this.sockPath + routeArg + suffix,
headers:{
"Content-Type":"application/json"
},
body:jsonArg
};
plugins.request(options,function(err, res, body){
plugins.request(options,(err, res, body) => {
if (!err && res.statusCode == 200) {
var responseObj = JSON.parse(body);
done.resolve(responseObj);

2
ts/index.ts Normal file
View File

@ -0,0 +1,2 @@
import "typings-global";
export {Dockersock} from "./dockersock.classes.dockersock"