Compare commits

..

52 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
1d75c1334f 1.0.5 2016-06-17 00:28:45 +02:00
0824d5b910 now using new beautylog reduced log method 2016-06-17 00:28:41 +02:00
0575e618f2 now prperly pulling an image 2016-06-16 20:25:18 +02:00
6b22f12051 1.0.4 2016-06-16 08:47:34 +02:00
51bf5cfd72 implement pullImage() 2016-06-16 08:47:21 +02:00
5cbcba2f1e prepare container creation 2016-06-16 06:43:34 +02:00
21 changed files with 2562 additions and 209 deletions

5
.gitignore vendored
View File

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

View File

@ -1,38 +1,31 @@
image: hosttoday/ht-docker-dbase
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:dind
cache:
paths:
- .yarn/
key: "$CI_BUILD_STAGE"
stages:
- build
- test
- release
- trigger
- pages
before_script:
- npmci prepare docker-gitlab
build:
stage: build
script:
- npm install
- npm test
- npmci build docker
tags:
- lossless
- priv
test:
stage: test
script:
- npmci test docker
- npmci test stable
tags:
- lossless
- priv
release:
image: hosttoday/ht-docker-node:npmts
image: hosttoday/ht-docker-node:npmci
stage: release
script:
- npmci publish npm
@ -43,6 +36,7 @@ release:
- priv
trigger:
image: hosttoday/ht-docker-node:npmci
stage: trigger
script:
- npmci trigger
@ -51,3 +45,18 @@ trigger:
tags:
- lossless
- 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
easy communication with docker from node, TypeScript ready
easy communication with docker remote api from node, TypeScript ready
## Status
[![build status](https://gitlab.com/pushrocks/dockersock/badges/master/build.svg)](https://gitlab.com/pushrocks/dockersock/commits/master)
## 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
We recommend the use of TypeScript for best Intellisense.
Use TypeScript for best in class instellisense.
```TypeScript
import {Dockersock} from "dockersock"; // require Dockersock class
@ -26,3 +40,10 @@ myDockersock.newContainer({ // start new Container, equals "docker run" shell co
})
```
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,17 +1,33 @@
/// <reference types="request" />
/// <reference types="q" />
import "typings-global";
import * as plugins from "./dockersock.plugins";
import { Observable } from "rxjs";
import { Objectmap } from 'lik';
export declare class Dockersock {
sockPath: string;
requestObjectmap: Objectmap<plugins.request.Request>;
constructor(pathArg?: string);
auth(userArg: string, passArg: string): any;
listContainers(): any;
listContainersDetailed(): any;
listContainersRunning(): any;
listContainersStopped(): any;
listImages(): any;
auth(userArg: string, passArg: string): plugins.q.Promise<{}>;
listContainers(): plugins.q.Promise<{}>;
listContainersDetailed(): plugins.q.Promise<{}>;
listContainersRunning(): plugins.q.Promise<{}>;
listContainersStopped(): plugins.q.Promise<{}>;
listImages(): plugins.q.Promise<{}>;
listImagesDangling(): plugins.q.Promise<{}>;
pullImage(imageLabelArg: string): plugins.q.Promise<{}>;
createContainer(optionsArg: any, pullFirstArg?: boolean): plugins.q.Promise<{}>;
getContainerId(): void;
startContainer(containerNameArg: any): any;
stopContainer(): any;
clean(): any;
getChange(): void;
request(methodArg: string, routeArg: string, dataArg?: {}): any;
startContainer(containerNameArg: any): plugins.q.Promise<{}>;
stopContainer(containerNameArg: any): plugins.q.Promise<{}>;
removeContainer(containerNameArg: any): plugins.q.Promise<{}>;
clean(): plugins.q.Promise<{}>;
callOnChange(cb: Function): void;
/**
* 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";
export import beautylog = require("beautylog");
export declare let q: any;
export declare let request: any;
export import lik = require("lik");
export import q = require("q");
export import request = require("request");
export import rxjs = require("rxjs");

View File

@ -1,7 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
exports.beautylog = require("beautylog");
exports.lik = require("lik");
exports.q = require("q");
exports.request = require("request");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRvY2tlcnNvY2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNwQyxTQUFDLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGVBQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUMiLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIjtcbmV4cG9ydCBpbXBvcnQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgcSA9IHJlcXVpcmUoXCJxXCIpO1xuZXhwb3J0IGxldCByZXF1ZXN0ID0gcmVxdWlyZShcInJlcXVlc3RcIik7Il19
exports.rxjs = require("rxjs");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvZG9ja2Vyc29jay5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsMEJBQXdCO0FBQ3hCLHlDQUErQztBQUMvQyw2QkFBbUM7QUFDbkMseUJBQStCO0FBQy9CLHFDQUEyQztBQUMzQywrQkFBcUMifQ==

4
dist/index.js vendored
View File

@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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=
//# 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,13 +1,11 @@
{
"name": "dockersock",
"version": "1.0.3",
"description": "easy communication with docker from node, TypeScript ready",
"version": "1.0.20",
"description": "easy communication with docker remote api from node, TypeScript ready",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"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"
"test": "npmdocker"
},
"repository": {
"type": "git",
@ -27,14 +25,17 @@
},
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
"dependencies": {
"beautylog": "^5.0.10",
"q": "^1.4.1",
"request": "^2.72.0",
"typings-global": "^1.0.3"
"@types/q": "1.x.x",
"@types/request": "0.x.x",
"beautylog": "^6.1.5",
"lik": "^1.0.27",
"q": "^1.5.0",
"request": "^2.81.0",
"rxjs": "^5.2.0",
"typings-global": "^1.0.14"
},
"devDependencies": {
"npmts-g": "^5.2.6",
"should": "^9.0.2",
"typings-test": "^1.0.1"
"observable-to-promise": "^0.5.0",
"tapbundle": "^1.0.5"
}
}

2
test/test.d.ts vendored
View File

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

View File

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

View File

@ -1,29 +1,36 @@
import "typings-test";
import "should"
import "typings-global";
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(){
describe(".Dockersock()",function(){
let testDockersock:Dockersock;
it("should create a new Dockersock instance",function(){
tap.test("should create a new Dockersock instance", async () => {
testDockersock = new Dockersock();
testDockersock.should.be.instanceof(Dockersock);
});
it("should list containers",function(done){
testDockersock.listContainers()
.then((dataArg)=>{
return expect(testDockersock).to.be.instanceof(Dockersock);
}).catch(tap.threw);
tap.test("should list containers", async () => {
await testDockersock.listContainers()
.then(async (dataArg) => {
console.log(dataArg);
done();
});
});
it("should list detailed containers",function(done){
this.timeout(5000);
testDockersock.listContainersDetailed()
.then((dataArg)=>{
}).catch(tap.threw);
tap.test("should list detailed containers", async () => {
await testDockersock.listContainersDetailed()
.then(async (dataArg) => {
console.log(dataArg);
done();
});
});
});
});
}).catch(tap.threw);
tap.test("should pull an image from imagetag", async () => {
await testDockersock.pullImage("hosttoday/ht-docker-node:npmci")
}).catch(tap.threw);
/*tap.test("should return a change Objservable", async () => {
let myObservable = testDockersock.getChangeObservable();
testDockersock.endRequests();
let testPromise = observableToPromise(myObservable)
return await expect(testPromise).to.eventually.be.fulfilled
}).catch(tap.threw);*/

View File

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

View File

@ -1,21 +1,26 @@
import "typings-global"
import * as plugins from "./dockersock.plugins";
import { Observable } from "rxjs";
// interfaces
import { Objectmap } from 'lik'
export class Dockersock {
sockPath:string;
constructor(pathArg:string = "http://unix:/var/run/docker.sock:"){
sockPath: string;
requestObjectmap = new plugins.lik.Objectmap<plugins.request.Request>();
constructor(pathArg: string = "http://unix:/var/run/docker.sock:") {
this.sockPath = pathArg;
}
// methods
auth(userArg:string,passArg:string){
auth(userArg: string, passArg: string) {
let done = plugins.q.defer();
this.request("POST","");
this.request("POST", "");
return done.promise;
}
listContainers() {
let done = plugins.q.defer();
this.request("GET","/containers")
this.request("GET", "/containers")
.then(done.resolve);
return done.promise;
};
@ -26,8 +31,8 @@ export class Dockersock {
.then((dataArg) => {
let recursiveCounter = 0;
let makeDetailed = () => {
if(typeof dataArg[recursiveCounter] != "undefined"){
this.request("GET","/containers/" + dataArg[recursiveCounter].Id)
if (typeof dataArg[recursiveCounter] != "undefined") {
this.request("GET", "/containers/" + dataArg[recursiveCounter].Id)
.then((dataArg2) => {
detailedDataObject.push(dataArg2);
recursiveCounter++;
@ -51,39 +56,126 @@ export class Dockersock {
return done.promise;
}
listImages() {
let done = plugins.q.defer();
return done.promise;
return this.request("GET", "/images", "?all=true");
}
getContainerId(){
listImagesDangling() {
return this.request("GET", "/images", "?dangling=true");
}
startContainer(containerNameArg){
return this.request("POST","/containers/"+ containerNameArg +"/start");
pullImage(imageLabelArg: string) {
let imageLabel = encodeURI(imageLabelArg);
return this.requestStream("POST", "/images/create?fromImage=" + imageLabel);
};
stopContainer(){
return this.request("POST","/containers/"+ containerNameArg +"/stop");
createContainer(optionsArg, pullFirstArg: boolean = true) {
let done = plugins.q.defer();
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() {
};
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(){
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,dataArg = {}){
let done = plugins.q.defer();
let jsonArg:string = JSON.stringify(dataArg);
let suffix:string = ""
if(methodArg == "GET") suffix = "/json";
/**
* gets you an observable that reports changes in the docker infrastructure
*/
getChangeObservable() {
let options = {
method:methodArg,
url:this.sockPath + routeArg + suffix,
headers:{
"Content-Type":"application/json"
},
body:jsonArg
method: "GET",
url: this.sockPath + "/events",
headers: {
"Content-Type": "application/json",
"Host": "docker.sock"
}
};
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) {
var responseObj = JSON.parse(body);
done.resolve(responseObj);
@ -95,4 +187,57 @@ export class Dockersock {
});
return done.promise;
}
requestStream(methodArg: string, routeArg: string, queryArg: string = "", dataArg = {}) {
let done = plugins.q.defer();
let jsonArg: string = JSON.stringify(dataArg);
let suffix: string = "";
let options = {
method: methodArg,
url: this.sockPath + routeArg + suffix + queryArg,
headers: {
"Content-Type": "application/json",
"Host": "docker.sock"
},
body: jsonArg
};
let requestStream = plugins.request(options, (err, res, body) => {
if (!err && res.statusCode == 200) {
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;
};
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";
export import beautylog = require("beautylog");
export let q = require("q");
export let request = require("request");
export import lik = require("lik");
export import q = require("q");
export import request = require("request");
export import rxjs = require("rxjs");

View File

@ -1,2 +1,2 @@
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