Compare commits

..

46 Commits

Author SHA1 Message Date
91d7f583e2 1.0.20 2017-04-02 15:30:58 +02:00
a77ed42e9f now working with npmdocker and the npmts 7.x.x 2017-04-02 15:30:43 +02:00
499c6cc3b7 update ci 2017-04-02 12:12:18 +02:00
19283fb695 update ci 2017-04-02 12:11:21 +02:00
b2d84b1399 update npmextra to have npmts and npmdocker available in ci 2017-04-02 12:08:36 +02:00
7cc2374130 improve README 2017-04-02 12:05:29 +02:00
526bb5bbd0 update 2017-03-26 13:02:20 +02:00
14b2105a49 1.0.19 2016-08-03 12:21:26 +02:00
37efeffe69 update dependencies 2016-08-03 12:21:07 +02:00
943f46d620 update type versions 2016-08-03 12:19:54 +02:00
cfb7c1ce06 1.0.18 2016-07-31 23:07:14 +02:00
489a47b9bf now waiting for response to be stored before ending streaming request 2016-07-31 23:07:09 +02:00
28fa5349d7 cosmetic fix 2016-07-31 22:47:22 +02:00
cc82b3af04 1.0.17 2016-07-31 21:05:57 +02:00
6a8751afd2 now has possibility to end streaming requests 2016-07-31 21:05:41 +02:00
56612f9ac9 1.0.16 2016-07-29 20:41:30 +02:00
2a1fcd8cdb fixed request for change observable 2016-07-29 20:41:27 +02:00
09911328b2 1.0.15 2016-07-28 19:41:27 +02:00
548e32419e improve README 2016-07-28 19:41:14 +02:00
2b2b06b48b Merge branch 'master' of gitlab.com:pushrocks/dockersock 2016-07-28 19:38:40 +02:00
37028a9b1f add npmdocker 2016-07-28 19:38:26 +02:00
3cba5844d8 fix dep versions 2016-07-18 04:07:52 +02:00
a3ceb68eab add request typings 2016-07-18 04:06:56 +02:00
be659a2dbd 1.0.14 2016-07-18 02:50:34 +02:00
144f963d8a fixed request for newer docker 2016-07-18 02:50:28 +02:00
0c7cd35448 prepare for npmdocker 2016-07-18 01:35:04 +02:00
4e3446cb2f now encoding URI 2016-07-18 00:54:41 +02:00
cec9555908 update 2016-07-17 23:09:54 +02:00
14803c1569 1.0.13 2016-07-15 13:54:12 +02:00
2d2449890f 1.0.12 2016-07-15 12:52:40 +02:00
5fd3a63822 update to ES6 2016-07-15 12:52:33 +02:00
5ae04ce5c2 1.0.11 2016-07-12 14:32:17 +02:00
2b3b991372 fixed q types dependency 2016-07-12 14:32:12 +02:00
487ba592a7 1.0.10 2016-07-12 14:04:31 +02:00
60e3239d99 fix response syntax 2016-07-12 14:04:23 +02:00
f23cc2eb82 1.0.9 2016-07-12 13:36:56 +02:00
de05d432b1 added rxjs, added getChangeObservable 2016-07-12 13:36:34 +02:00
4a90510ff4 add eventEmitter to dockersock class 2016-07-11 21:55:10 +02:00
bfda5177a6 1.0.8 2016-07-11 17:54:29 +02:00
ad2a1ac03d update timeout 2016-07-11 17:44:02 +02:00
99db0b902e remove confusing file 2016-07-11 17:41:47 +02:00
515d2d4970 1.0.7 2016-07-11 17:24:00 +02:00
abf2234480 add typings to package.json 2016-07-11 17:23:54 +02:00
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
21 changed files with 2550 additions and 295 deletions

5
.gitignore vendored
View File

@ -1,3 +1,4 @@
docs/ .yarn/
coverage/
node_modules/ node_modules/
coverage/
public/

View File

@ -1,38 +1,31 @@
image: hosttoday/ht-docker-dbase image: hosttoday/ht-docker-dbase:npmci
services: services:
- docker:dind - docker:dind
cache:
paths:
- .yarn/
key: "$CI_BUILD_STAGE"
stages: stages:
- build
- test - test
- release - release
- trigger - trigger
- pages
before_script: before_script:
- npmci prepare docker-gitlab - npmci prepare docker-gitlab
build:
stage: build
script:
- npm install
- npm test
- npmci build docker
tags:
- lossless
- priv
test: test:
stage: test stage: test
script: script:
- npmci test docker - npmci test stable
tags: tags:
- lossless - lossless
- priv - priv
release: release:
image: hosttoday/ht-docker-node:npmts image: hosttoday/ht-docker-node:npmci
stage: release stage: release
script: script:
- npmci publish npm - npmci publish npm
@ -43,6 +36,7 @@ release:
- priv - priv
trigger: trigger:
image: hosttoday/ht-docker-node:npmci
stage: trigger stage: trigger
script: script:
- npmci trigger - npmci trigger
@ -50,4 +44,19 @@ trigger:
- tags - tags
tags: tags:
- lossless - lossless
- priv - priv
pages:
image: hosttoday/ht-docker-node:npmci
stage: pages
script:
- npmci command yarn global add npmpage
- npmci command npmpage --publish gitlab
tags:
- docker
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public

View File

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

View File

@ -1,11 +1,25 @@
# dockersock # dockersock
easy communication with docker from node, TypeScript ready easy communication with docker remote api from node, TypeScript ready
## Status ## Availabililty
[![build status](https://gitlab.com/pushrocks/dockersock/badges/master/build.svg)](https://gitlab.com/pushrocks/dockersock/commits/master) [![npm](https://mojoio.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/dockersock)
[![git](https://mojoio.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/mojoio/dockersock)
[![git](https://mojoio.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/mojoio/dockersock)
[![docs](https://mojoio.gitlab.io/assets/repo-button-docs.svg)](https://mojoio.gitlab.io/dockersock/)
## Status for master
[![build status](https://GitLab.com/mojoio/dockersock/badges/master/build.svg)](https://GitLab.com/mojoio/dockersock/commits/master)
[![coverage report](https://GitLab.com/mojoio/dockersock/badges/master/coverage.svg)](https://GitLab.com/mojoio/dockersock/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/dockersock.svg)](https://www.npmjs.com/package/dockersock)
[![Dependency Status](https://david-dm.org/mojoio/dockersock.svg)](https://david-dm.org/mojoio/dockersock)
[![bitHound Dependencies](https://www.bithound.io/github/mojoio/dockersock/badges/dependencies.svg)](https://www.bithound.io/github/mojoio/dockersock/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/mojoio/dockersock/badges/code.svg)](https://www.bithound.io/github/mojoio/dockersock)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage ## Usage
We recommend the use of TypeScript for best Intellisense. Use TypeScript for best in class instellisense.
```TypeScript ```TypeScript
import {Dockersock} from "dockersock"; // require Dockersock class import {Dockersock} from "dockersock"; // require Dockersock class
@ -25,4 +39,11 @@ myDockersock.newContainer({ // start new Container, equals "docker run" shell co
image: "someimagetag" image: "someimagetag"
}) })
``` ```
For further information read the linked docs at the top of this README.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://mojo.io)

View File

@ -1,22 +1,33 @@
/// <reference types="request" />
/// <reference types="q" />
import "typings-global"; import "typings-global";
import * as plugins from "./dockersock.plugins";
import { Observable } from "rxjs";
import { Objectmap } from 'lik';
export declare class Dockersock { export declare class Dockersock {
sockPath: string; sockPath: string;
requestObjectmap: Objectmap<plugins.request.Request>;
constructor(pathArg?: string); constructor(pathArg?: string);
auth(userArg: string, passArg: string): any; auth(userArg: string, passArg: string): plugins.q.Promise<{}>;
listContainers(): any; listContainers(): plugins.q.Promise<{}>;
listContainersDetailed(): any; listContainersDetailed(): plugins.q.Promise<{}>;
listContainersRunning(): any; listContainersRunning(): plugins.q.Promise<{}>;
listContainersStopped(): any; listContainersStopped(): plugins.q.Promise<{}>;
listImages(): any; listImages(): plugins.q.Promise<{}>;
listImagesDangling(): any; listImagesDangling(): plugins.q.Promise<{}>;
pullImage(imageLabel: string): any; pullImage(imageLabelArg: string): plugins.q.Promise<{}>;
createContainer(imageNameArg: any, pullFirst?: boolean): any; createContainer(optionsArg: any, pullFirstArg?: boolean): plugins.q.Promise<{}>;
getContainerId(): void; getContainerId(): void;
startContainer(containerNameArg: any): any; startContainer(containerNameArg: any): plugins.q.Promise<{}>;
stopContainer(containerNameArg: any): any; stopContainer(containerNameArg: any): plugins.q.Promise<{}>;
removeContainer(containerNameArg: any): any; removeContainer(containerNameArg: any): plugins.q.Promise<{}>;
clean(): any; clean(): plugins.q.Promise<{}>;
getChange(): void; callOnChange(cb: Function): void;
request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): any; /**
requestStream(methodArg: any, routeArg: any, endArg?: boolean): any; * gets you an observable that reports changes in the docker infrastructure
*/
getChangeObservable(): Observable<{}>;
request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>;
requestStream(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>;
endRequests(): void;
} }

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,6 @@
import "typings-global"; import "typings-global";
export import beautylog = require("beautylog"); export import beautylog = require("beautylog");
export declare let q: any; export import lik = require("lik");
export declare let request: any; export import q = require("q");
export import request = require("request");
export import rxjs = require("rxjs");

View File

@ -1,7 +1,9 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRvY2tlcnNvY2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNwQyxTQUFDLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGVBQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUMiLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIjtcbmV4cG9ydCBpbXBvcnQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgcSA9IHJlcXVpcmUoXCJxXCIpO1xuZXhwb3J0IGxldCByZXF1ZXN0ID0gcmVxdWlyZShcInJlcXVlc3RcIik7Il19 //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvZG9ja2Vyc29jay5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsMEJBQXdCO0FBQ3hCLHlDQUErQztBQUMvQyw2QkFBbUM7QUFDbkMseUJBQStCO0FBQy9CLHFDQUEyQztBQUMzQywrQkFBcUMifQ==

4
dist/index.js vendored
View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global"); require("typings-global");
var dockersock_classes_dockersock_1 = require("./dockersock.classes.dockersock"); var dockersock_classes_dockersock_1 = require("./dockersock.classes.dockersock");
exports.Dockersock = dockersock_classes_dockersock_1.Dockersock; exports.Dockersock = dockersock_classes_dockersock_1.Dockersock;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF3QjtBQUN4QixpRkFBNkQ7QUFBcEQscURBQUEsVUFBVSxDQUFBIn0=
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsOENBQXlCLGlDQUFpQyxDQUFDO0FBQW5ELGdFQUFrRCIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5leHBvcnQge0RvY2tlcnNvY2t9IGZyb20gXCIuL2RvY2tlcnNvY2suY2xhc3Nlcy5kb2NrZXJzb2NrXCIiXX0=

49
docs/README.md Normal file
View File

@ -0,0 +1,49 @@
# dockersock
easy communication with docker remote api from node, TypeScript ready
## Availabililty
[![npm](https://mojoio.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/dockersock)
[![git](https://mojoio.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/mojoio/dockersock)
[![git](https://mojoio.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/mojoio/dockersock)
[![docs](https://mojoio.gitlab.io/assets/repo-button-docs.svg)](https://mojoio.gitlab.io/dockersock/)
## Status for master
[![build status](https://GitLab.com/mojoio/dockersock/badges/master/build.svg)](https://GitLab.com/mojoio/dockersock/commits/master)
[![coverage report](https://GitLab.com/mojoio/dockersock/badges/master/coverage.svg)](https://GitLab.com/mojoio/dockersock/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/dockersock.svg)](https://www.npmjs.com/package/dockersock)
[![Dependency Status](https://david-dm.org/mojoio/dockersock.svg)](https://david-dm.org/mojoio/dockersock)
[![bitHound Dependencies](https://www.bithound.io/github/mojoio/dockersock/badges/dependencies.svg)](https://www.bithound.io/github/mojoio/dockersock/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/mojoio/dockersock/badges/code.svg)](https://www.bithound.io/github/mojoio/dockersock)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
Use TypeScript for best in class instellisense.
```TypeScript
import {Dockersock} from "dockersock"; // require Dockersock class
let myDockersock = new Dockersock(); // optional: you can pass a domain to the contructor, defaults to /var/run/docker.sock
myDockersock.listContainers() // promise, resolve gets container data
myDockersock.listContainersDetailed() // promise, resolve gets more detailed container data (by combining several requests internally)
myDockersock.listContainersRunning() // promise, resolve gets container data for currently running containers
myDockersock.listContainersStopped() // promise, resolve gets container data for stopped containers
myDockersock.startContainer({ // starts a already present container
name: "somecontainername"
})
myDockersock.newContainer({ // start new Container, equals "docker run" shell command
image: "someimagetag"
})
```
For further information read the linked docs at the top of this README.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://mojo.io)

17
npmextra.json Normal file
View File

@ -0,0 +1,17 @@
{
"npmts":{
"mode":"default",
"coverageTreshold":10
},
"npmdocker":{
"baseImage":"hosttoday/ht-docker-node:npmci",
"command":"(npmci command yarn global add npmts) && npmts",
"dockerSock":"true"
},
"npmci": {
"globalNpmTools": [
"npmts",
"npmdocker"
]
}
}

View File

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

View File

@ -1,13 +1,11 @@
{ {
"name": "dockersock", "name": "dockersock",
"version": "1.0.5", "version": "1.0.20",
"description": "easy communication with docker from node, TypeScript ready", "description": "easy communication with docker remote api from node, TypeScript ready",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "npmts --notest && npm run build && npm run startdocker && npm run cleanup", "test": "npmdocker"
"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",
@ -27,14 +25,17 @@
}, },
"homepage": "https://gitlab.com/pushrocks/dockersock#README", "homepage": "https://gitlab.com/pushrocks/dockersock#README",
"dependencies": { "dependencies": {
"beautylog": "^5.0.12", "@types/q": "1.x.x",
"q": "^1.4.1", "@types/request": "0.x.x",
"request": "^2.72.0", "beautylog": "^6.1.5",
"typings-global": "^1.0.3" "lik": "^1.0.27",
"q": "^1.5.0",
"request": "^2.81.0",
"rxjs": "^5.2.0",
"typings-global": "^1.0.14"
}, },
"devDependencies": { "devDependencies": {
"npmts-g": "^5.2.6", "observable-to-promise": "^0.5.0",
"should": "^9.0.2", "tapbundle": "^1.0.5"
"typings-test": "^1.0.1"
} }
} }

2
test/test.d.ts vendored
View File

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

View File

@ -1,37 +0,0 @@
"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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUVQLENBQUMsQ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ICAgIH0pO1xuICAgICAgICB9KTtcbiAgICAgICAgaXQoXCJzaG91bGQgbGlzdCBkZXRhaWxlZCBjb250YWluZXJzXCIsZnVuY3Rpb24oZG9uZSl7XG4gICAgICAgICAgICB0aGlzLnRpbWVvdXQoNTAwMCk7XG4gICAgICAgICAgICB0ZXN0RG9ja2Vyc29jay5saXN0Q29udGFpbmVyc0RldGFpbGVkKClcbiAgICAgICAgICAgICAgICAudGhlbigoZGF0YUFyZyk9PntcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZGF0YUFyZyk7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgICAgIGl0KFwic2hvdWxkIHB1bGwgYW4gaW1hZ2UgZnJvbSBpbWFnZXRhZ1wiLGZ1bmN0aW9uKGRvbmUpe1xuICAgICAgICAgICAgdGhpcy50aW1lb3V0KDMwMDAwKTtcbiAgICAgICAgICAgIHRlc3REb2NrZXJzb2NrLnB1bGxJbWFnZShcImhvc3R0b2RheSUyRmh0LWRvY2tlci1kYmFzZVwiKVxuICAgICAgICAgICAgICAgIC50aGVuKChkYXRhQXJnKT0+e1xuICAgICAgICAgICAgICAgICAgICBkb25lKCk7XG4gICAgICAgICAgICAgICAgfSxkb25lKTtcbiAgICAgICAgfSlcbiAgICB9KTtcbn0pOyJdfQ==

View File

@ -1,36 +1,36 @@
import "typings-test"; import "typings-global";
import "should" import { expect, tap } from 'tapbundle'
import * as observableToPromise from 'observable-to-promise'
import { Dockersock } from "../dist/index";
import {Dockersock} from "../dist/index" let testDockersock: Dockersock;
describe("dockersock",function(){ tap.test("should create a new Dockersock instance", async () => {
describe(".Dockersock()",function(){ testDockersock = new Dockersock();
let testDockersock:Dockersock; return expect(testDockersock).to.be.instanceof(Dockersock);
it("should create a new Dockersock instance",function(){ }).catch(tap.threw);
testDockersock = new Dockersock();
testDockersock.should.be.instanceof(Dockersock); tap.test("should list containers", async () => {
await testDockersock.listContainers()
.then(async (dataArg) => {
console.log(dataArg);
}); });
it("should list containers",function(done){ }).catch(tap.threw);
testDockersock.listContainers()
.then((dataArg)=>{ tap.test("should list detailed containers", async () => {
console.log(dataArg); await testDockersock.listContainersDetailed()
done(); .then(async (dataArg) => {
}); console.log(dataArg);
}); });
it("should list detailed containers",function(done){ }).catch(tap.threw);
this.timeout(5000);
testDockersock.listContainersDetailed() tap.test("should pull an image from imagetag", async () => {
.then((dataArg)=>{ await testDockersock.pullImage("hosttoday/ht-docker-node:npmci")
console.log(dataArg); }).catch(tap.threw);
done();
}); /*tap.test("should return a change Objservable", async () => {
}); let myObservable = testDockersock.getChangeObservable();
it("should pull an image from imagetag",function(done){ testDockersock.endRequests();
this.timeout(30000); let testPromise = observableToPromise(myObservable)
testDockersock.pullImage("hosttoday%2Fht-docker-dbase") return await expect(testPromise).to.eventually.be.fulfilled
.then((dataArg)=>{ }).catch(tap.threw);*/
done();
},done);
})
});
});

View File

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

View File

@ -1,21 +1,26 @@
import "typings-global" import "typings-global"
import * as plugins from "./dockersock.plugins"; import * as plugins from "./dockersock.plugins";
import { Observable } from "rxjs";
// interfaces
import { Objectmap } from 'lik'
export class Dockersock { export class Dockersock {
sockPath:string; sockPath: string;
constructor(pathArg:string = "http://unix:/var/run/docker.sock:"){ requestObjectmap = new plugins.lik.Objectmap<plugins.request.Request>();
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;
}; };
@ -26,8 +31,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++;
@ -51,52 +56,126 @@ 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(imageLabel:string){ pullImage(imageLabelArg: string) {
return this.requestStream("POST","/images/create?fromImage=" + imageLabel); let imageLabel = encodeURI(imageLabelArg);
return this.requestStream("POST", "/images/create?fromImage=" + imageLabel);
}; };
createContainer(imageNameArg,pullFirst:boolean = true){ createContainer(optionsArg, pullFirstArg: boolean = true) {
return this.request("POST","/containers/create","",{ let done = plugins.q.defer();
"image":imageNameArg 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(){ 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;
}; };
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(); /**
let jsonArg:string = JSON.stringify(dataArg); * gets you an observable that reports changes in the docker infrastructure
let suffix:string = ""; */
if(methodArg == "GET") suffix = "/json"; getChangeObservable() {
let options = { let options = {
method:methodArg, method: "GET",
url:this.sockPath + routeArg + suffix + queryArg, url: this.sockPath + "/events",
headers:{ headers: {
"Content-Type":"application/json" "Content-Type": "application/json",
}, "Host": "docker.sock"
body:jsonArg }
}; };
plugins.request(options,(err, res, body) => { let requestStream = plugins.request(options, (err, res, body) => {
if (!err && res.statusCode == 200) {
} else {
console.log(err);
console.log(res);
};
});
let incomingMessage
requestStream.on("response", (response) => {
incomingMessage = response
this.requestObjectmap.add(incomingMessage);
if (response.statusCode == 200) {
plugins.beautylog.ok("request returned status 200, so we are good!");
} else {
plugins.beautylog.error("request returned error: " + response.statusCode);
}
});
let changeObservable = Observable.fromEvent(requestStream, "data");
requestStream.on("end", () => {
this.requestObjectmap.remove(incomingMessage);
});
return changeObservable;
}
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",
"Host": "docker.sock"
},
body: jsonArg
};
//console.log(options);
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);
@ -108,26 +187,57 @@ export class Dockersock {
}); });
return done.promise; return done.promise;
} }
requestStream(methodArg,routeArg,endArg:boolean = true){ requestStream(methodArg: string, routeArg: string, queryArg: string = "", dataArg = {}) {
let done = plugins.q.defer(); let done = plugins.q.defer();
if(methodArg == "POST"){ let jsonArg: string = JSON.stringify(dataArg);
let requestStream = plugins.request.post(this.sockPath + routeArg); let suffix: string = "";
requestStream.on("response",(response) => { let options = {
if(response.statusCode == 200){ method: methodArg,
plugins.beautylog.ok("request returned status 200, so we are good!"); url: this.sockPath + routeArg + suffix + queryArg,
} else { headers: {
plugins.beautylog.error("request returned error: " + response.statusCode); "Content-Type": "application/json",
done.reject(); "Host": "docker.sock"
} },
}); body: jsonArg
requestStream.on("data",(data:Buffer) => { };
let status = JSON.parse(data.toString()).status; let requestStream = plugins.request(options, (err, res, body) => {
plugins.beautylog.logReduced(status); if (!err && res.statusCode == 200) {
});
requestStream.on("end",()=> {
done.resolve(); done.resolve();
}); } else {
} console.log(err);
console.log(res);
done.reject(err);
};
});
let incomingMessage
requestStream.on("response", (response) => {
incomingMessage = response
this.requestObjectmap.add(incomingMessage);
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(response);
}
});
requestStream.on("data", (data: Buffer) => {
let status;
status = JSON.parse(data.toString()).status;
plugins.beautylog.logReduced(status);
});
requestStream.on("end", () => {
this.requestObjectmap.remove(incomingMessage);
});
return done.promise; return done.promise;
} };
endRequests() {
setTimeout(() => {
this.requestObjectmap.forEach((itemArg: plugins.request.Request) => {
itemArg.emit("end");
});
this.requestObjectmap.wipe();
}, 5000);
};
} }

View File

@ -1,4 +1,6 @@
import "typings-global"; import "typings-global";
export import beautylog = require("beautylog"); export import beautylog = require("beautylog");
export let q = require("q"); export import lik = require("lik");
export let request = require("request"); export import q = require("q");
export import request = require("request");
export import rxjs = require("rxjs");

View File

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

1974
yarn.lock Normal file

File diff suppressed because it is too large Load Diff