Compare commits

..

33 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
20 changed files with 2451 additions and 308 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,9 +1,12 @@
/// <reference types="request" />
/// <reference types="q" /> /// <reference types="q" />
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";
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): plugins.q.Promise<{}>; auth(userArg: string, passArg: string): plugins.q.Promise<{}>;
listContainers(): plugins.q.Promise<{}>; listContainers(): plugins.q.Promise<{}>;
@ -12,7 +15,7 @@ export declare class Dockersock {
listContainersStopped(): plugins.q.Promise<{}>; listContainersStopped(): plugins.q.Promise<{}>;
listImages(): plugins.q.Promise<{}>; listImages(): plugins.q.Promise<{}>;
listImagesDangling(): plugins.q.Promise<{}>; listImagesDangling(): plugins.q.Promise<{}>;
pullImage(imageLabel: string): plugins.q.Promise<{}>; pullImage(imageLabelArg: string): plugins.q.Promise<{}>;
createContainer(optionsArg: any, pullFirstArg?: boolean): plugins.q.Promise<{}>; createContainer(optionsArg: any, pullFirstArg?: boolean): plugins.q.Promise<{}>;
getContainerId(): void; getContainerId(): void;
startContainer(containerNameArg: any): plugins.q.Promise<{}>; startContainer(containerNameArg: any): plugins.q.Promise<{}>;
@ -20,7 +23,11 @@ export declare class Dockersock {
removeContainer(containerNameArg: any): plugins.q.Promise<{}>; removeContainer(containerNameArg: any): plugins.q.Promise<{}>;
clean(): plugins.q.Promise<{}>; clean(): plugins.q.Promise<{}>;
callOnChange(cb: Function): void; callOnChange(cb: Function): void;
/**
* gets you an observable that reports changes in the docker infrastructure
*/
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: any, routeArg: any, endArg?: boolean): 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,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 declare let request: any; export import request = require("request");
export import rxjs = require("rxjs"); 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"); exports.rxjs = require("rxjs");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvZG9ja2Vyc29jay5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNwQixlQUFPLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBQzFCLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQyJ9 //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvZG9ja2Vyc29jay5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsMEJBQXdCO0FBQ3hCLHlDQUErQztBQUMvQyw2QkFBbUM7QUFDbkMseUJBQStCO0FBQy9CLHFDQUEyQztBQUMzQywrQkFBcUMifQ==

3
dist/index.js vendored
View File

@ -1,5 +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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ3hCLDhDQUF5QixpQ0FBaUMsQ0FBQztBQUFuRCxnRUFBa0QifQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF3QjtBQUN4QixpRkFBNkQ7QUFBcEQscURBQUEsVUFBVSxDQUFBIn0=

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,14 +1,11 @@
{ {
"name": "dockersock", "name": "dockersock",
"version": "1.0.10", "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", "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",
@ -28,18 +25,17 @@
}, },
"homepage": "https://gitlab.com/pushrocks/dockersock#README", "homepage": "https://gitlab.com/pushrocks/dockersock#README",
"dependencies": { "dependencies": {
"@types/es6-promise": "0.0.27-alpha", "@types/q": "1.x.x",
"@types/q": "0.0.26-alpha", "@types/request": "0.x.x",
"beautylog": "^5.0.12", "beautylog": "^6.1.5",
"es6-promise": "^3.2.1", "lik": "^1.0.27",
"q": "^1.4.1", "q": "^1.5.0",
"request": "^2.72.0", "request": "^2.81.0",
"rxjs": "^5.0.0-beta.10", "rxjs": "^5.2.0",
"typings-global": "^1.0.3" "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,36 +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(60000);
testDockersock.pullImage("hosttoday%2Fht-docker-dbase")
.then(function (dataArg) {
done();
}, done);
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUVoQixzQkFBeUIsZUFFekIsQ0FBQyxDQUZ1QztBQUV4QyxRQUFRLENBQUMsWUFBWSxFQUFDO0lBQ2xCLFFBQVEsQ0FBQyxlQUFlLEVBQUM7UUFDckIsSUFBSSxjQUF5QixDQUFDO1FBQzlCLEVBQUUsQ0FBQyx5Q0FBeUMsRUFBQztZQUN6QyxjQUFjLEdBQUcsSUFBSSxrQkFBVSxFQUFFLENBQUM7WUFDbEMsY0FBYyxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLGtCQUFVLENBQUMsQ0FBQztRQUNwRCxDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQyx3QkFBd0IsRUFBQyxVQUFTLElBQUk7WUFDckMsY0FBYyxDQUFDLGNBQWMsRUFBRTtpQkFDMUIsSUFBSSxDQUFDLFVBQUMsT0FBTztnQkFDVixPQUFPLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxDQUFDO2dCQUNyQixJQUFJLEVBQUUsQ0FBQztZQUNYLENBQUMsQ0FBQyxDQUFDO1FBQ1gsQ0FBQyxDQUFDLENBQUM7UUFDSCxFQUFFLENBQUMsaUNBQWlDLEVBQUMsVUFBUyxJQUFJO1lBQzlDLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7WUFDbkIsY0FBYyxDQUFDLHNCQUFzQixFQUFFO2lCQUNsQyxJQUFJLENBQUMsVUFBQyxPQUFPO2dCQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLENBQUM7Z0JBQ3JCLElBQUksRUFBRSxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUM7UUFDWCxDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQyxvQ0FBb0MsRUFBQyxVQUFTLElBQUk7WUFDakQsSUFBSSxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUMsQ0FBQztZQUNwQixjQUFjLENBQUMsU0FBUyxDQUFDLDZCQUE2QixDQUFDO2lCQUNsRCxJQUFJLENBQUMsVUFBQyxPQUFPO2dCQUNWLElBQUksRUFBRSxDQUFDO1lBQ1gsQ0FBQyxFQUFDLElBQUksQ0FBQyxDQUFDO1FBQ2hCLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyJ9

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(60000); 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,22 +1,26 @@
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";
// 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;
}; };
@ -27,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++;
@ -52,20 +56,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(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(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);
@ -75,37 +80,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;
@ -115,39 +120,62 @@ export class Dockersock {
}); });
} }
}); });
requestStream.on("end",()=> { requestStream.on("end", () => {
}); });
}; };
getChangeObservable(){
let requestStream = plugins.request.get(this.sockPath + "/events"); /**
requestStream.on("response",(response) => { * gets you an observable that reports changes in the docker infrastructure
if(response.statusCode == 200){ */
plugins.beautylog.ok("request returned status 200, so we are good!"); getChangeObservable() {
} else { let options = {
plugins.beautylog.error("request returned error: " + response.statusCode); method: "GET",
} url: this.sockPath + "/events",
}); headers: {
let changeObservable = Observable.fromEvent(requestStream,"data"); "Content-Type": "application/json",
requestStream.on("end",()=> { "Host": "docker.sock"
}
};
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; 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"
}, },
body:jsonArg body: jsonArg
}; };
plugins.request(options,(err, res, body) => { //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);
@ -159,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(response); "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,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 let request = require("request"); export import request = require("request");
export import rxjs = require("rxjs"); 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