Compare commits

...

57 Commits

Author SHA1 Message Date
57594728df 1.0.26 2019-01-10 00:24:35 +01:00
8430a4d6e0 fix(core): update 2019-01-10 00:24:35 +01:00
7f38868510 1.0.25 2018-07-17 08:39:38 +02:00
7a80718d27 fix(core): update 2018-07-17 08:39:37 +02:00
1d0c4c3cf9 1.0.24 2018-07-16 23:52:50 +02:00
a037cba454 fix(core): shift to new style 2018-07-16 23:52:50 +02:00
7009e07ecc 1.0.23 2017-07-16 13:45:08 +02:00
7b8ef33e21 update creation of node_modules within npmdocker 2017-07-16 13:44:59 +02:00
3011e599e8 1.0.22 2017-07-16 12:04:53 +02:00
8adb636db3 1.0.21 2017-07-16 12:04:38 +02:00
dd35e5d7d2 update 2017-07-16 12:04:35 +02:00
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
32 changed files with 1876 additions and 466 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
@ -50,4 +44,19 @@ trigger:
- tags
tags:
- 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,29 @@
# dockersock
easy communication with docker from node, TypeScript ready
# @mojoio/dockersock
## Status
[![build status](https://gitlab.com/pushrocks/dockersock/badges/master/build.svg)](https://gitlab.com/pushrocks/dockersock/commits/master)
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
We recommend the use of TypeScript for best Intellisense.
Use TypeScript for best in class instellisense.
```TypeScript
import {Dockersock} from "dockersock"; // require Dockersock class
@ -24,5 +42,11 @@ myDockersock.startContainer({ // starts a already present container
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 | **©** [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 +0,0 @@
import "typings-global";
export declare class Dockersock {
sockPath: string;
constructor(pathArg?: string);
auth(userArg: string, passArg: string): any;
listContainers(): any;
listContainersDetailed(): any;
listContainersRunning(): any;
listContainersStopped(): any;
listImages(): any;
listImagesDangling(): any;
pullImage(imageLabel: string): any;
createContainer(imageNameArg: any, pullFirst?: boolean): any;
getContainerId(): void;
startContainer(containerNameArg: any): any;
stopContainer(containerNameArg: any): any;
removeContainer(containerNameArg: any): any;
clean(): any;
getChange(): void;
request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): any;
requestStream(methodArg: any, routeArg: any, endArg?: boolean): any;
}

File diff suppressed because one or more lines are too long

View File

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

View File

@ -1,7 +0,0 @@
"use strict";
require("typings-global");
exports.beautylog = require("beautylog");
exports.q = require("q");
exports.request = require("request");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRvY2tlcnNvY2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNwQyxTQUFDLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGVBQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUMiLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIjtcbmV4cG9ydCBpbXBvcnQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgcSA9IHJlcXVpcmUoXCJxXCIpO1xuZXhwb3J0IGxldCByZXF1ZXN0ID0gcmVxdWlyZShcInJlcXVlc3RcIik7Il19

2
dist/index.d.ts vendored
View File

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

6
dist/index.js vendored
View File

@ -1,6 +0,0 @@
"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=

View File

@ -1,18 +1,18 @@
nginx1 :
image: "nginx"
environment:
VIRTUAL_HOST: "test100.labkomp.de"
VIRTUAL_HOST: "test100.bleu.de"
restart: always
container_name: nginx1
nginx2:
image: nginx
environment:
VIRTUAL_HOST: "test101.labkomp.de"
VIRTUAL_HOST: "test101.bleu.de"
restart: always
container_name: nginx2
npmts-test-container:
image: "npmts-test-image"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
nginx3:
image: nginx
environment:
VIRTUAL_HOST: "test101.bleu.de"
restart: always
container_name: npmts-test-container
container_name: nginx3

15
npmextra.json Normal file
View File

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

View File

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

1527
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,12 @@
{
"name": "dockersock",
"version": "1.0.5",
"description": "easy communication with docker from node, TypeScript ready",
"name": "@mojoio/docker",
"version": "1.0.26",
"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": "tsrun test/test.ts",
"build": "(npmts --notest && npmdocker)"
},
"repository": {
"type": "git",
@ -27,14 +26,18 @@
},
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
"dependencies": {
"beautylog": "^5.0.12",
"q": "^1.4.1",
"request": "^2.72.0",
"typings-global": "^1.0.3"
"@pushrocks/lik": "^3.0.4",
"@pushrocks/smartlog": "^2.0.9",
"@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartrequest": "^1.1.14",
"rxjs": "^6.3.3"
},
"devDependencies": {
"npmts-g": "^5.2.6",
"should": "^9.0.2",
"typings-test": "^1.0.1"
}
"@gitzone/tsrun": "^1.1.17",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.18",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0"
},
"private": false
}

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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDL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gICAgICAgICAgZG9uZSgpO1xuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICB9KTtcbiAgICAgICAgaXQoXCJzaG91bGQgbGlzdCBkZXRhaWxlZCBjb250YWluZXJzXCIsZnVuY3Rpb24oZG9uZSl7XG4gICAgICAgICAgICB0aGlzLnRpbWVvdXQoNTAwMCk7XG4gICAgICAgICAgICB0ZXN0RG9ja2Vyc29jay5saXN0Q29udGFpbmVyc0RldGFpbGVkKClcbiAgICAgICAgICAgICAgICAudGhlbigoZGF0YUFyZyk9PntcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZGF0YUFyZyk7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgICAgIGl0KFwic2hvdWxkIHB1bGwgYW4gaW1hZ2UgZnJvbSBpbWFnZXRhZ1wiLGZ1bmN0aW9uKGRvbmUpe1xuICAgICAgICAgICAgdGhpcy50aW1lb3V0KDMwMDAwKTtcbiAgICAgICAgICAgIHRlc3REb2NrZXJzb2NrLnB1bGxJbWFnZShcImhvc3R0b2RheSUyRmh0LWRvY2tlci1kYmFzZVwiKVxuICAgICAgICAgICAgICAgIC50aGVuKChkYXRhQXJnKT0+e1xuICAgICAgICAgICAgICAgICAgICBkb25lKCk7XG4gICAgICAgICAgICAgICAgfSxkb25lKTtcbiAgICAgICAgfSlcbiAgICB9KTtcbn0pOyJdfQ==

View File

@ -1,36 +1,30 @@
import "typings-test";
import "should"
import { expect, tap } from '@pushrocks/tapbundle';
import { DockerHost } from '../ts/index';
import {Dockersock} from "../dist/index"
let testDockerHost: DockerHost;
describe("dockersock",function(){
describe(".Dockersock()",function(){
let testDockersock:Dockersock;
it("should create a new Dockersock instance",function(){
testDockersock = new Dockersock();
testDockersock.should.be.instanceof(Dockersock);
});
it("should list containers",function(done){
testDockersock.listContainers()
.then((dataArg)=>{
console.log(dataArg);
done();
});
});
it("should list detailed containers",function(done){
this.timeout(5000);
testDockersock.listContainersDetailed()
.then((dataArg)=>{
console.log(dataArg);
done();
});
});
it("should pull an image from imagetag",function(done){
this.timeout(30000);
testDockersock.pullImage("hosttoday%2Fht-docker-dbase")
.then((dataArg)=>{
done();
},done);
})
});
});
tap.test('should create a new Dockersock instance', async () => {
testDockerHost = new DockerHost();
return expect(testDockerHost).to.be.instanceof(DockerHost);
});
tap.test('should list containers', async () => {
const containers = await testDockerHost.getContainers();
console.log(containers);
});
tap.skip.test('should pull an image from imagetag', async () => {
// await testDockerHost.pullImage('hosttoday/ht-docker-node:npmci');
});
tap.test('should return a change Objservable', async (tools) => {
const testObservable = await testDockerHost.getEventObservable();
const subscription = testObservable.subscribe(changeObject => {
console.log(changeObject);
});
await tools.delayFor(2000);
subscription.unsubscribe();
});
tap.start();

View File

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

1
ts/docker.changes.ts Normal file
View File

@ -0,0 +1 @@
import * as plugins from './dockersock.plugins';

View File

@ -0,0 +1,73 @@
import * as plugins from './dockersock.plugins';
import * as interfaces from './interfaces';
import { DockerHost } from './docker.classes.host';
export class DockerContainer {
// ======
// STATIC
// ======
/**
* get all containers
*/
static async getContainers(dockerHostArg: DockerHost): Promise<DockerContainer[]> {
const result: DockerContainer[] = [];
const response = await dockerHostArg.request('GET', '/containers/json');
for (const containerResult of response.body) {
result.push(new DockerContainer(containerResult));
}
return result;
}
/**
*
* @param containerId
*/
static async getContainerById(containerId: string) {
}
static async create() {}
// ========
// INSTANCE
// ========
constructor(dockerContainerObjectArg: any) {
Object.keys(dockerContainerObjectArg).forEach(keyArg => {
this[keyArg] = dockerContainerObjectArg[keyArg];
})
}
Id: string;
Names: string[];
Image: string;
ImageID: string;
Command: string;
Created: number;
Ports: interfaces.TPorts;
Labels: interfaces.TLabels;
State: string;
Status: string;
HostConfig: any;
NetworkSettings: {
Networks: {
[key: string]: {
IPAMConfig: any;
Links: any;
Aliases: any;
NetworkID: string;
EndpointID: string;
Gateway: string;
IPAddress: string;
IPPrefixLen: number;
IPv6Gateway: string;
GlobalIPv6Address: string;
GlobalIPv6PrefixLen: number;
MacAddress: string;
DriverOpts: any;
};
};
};
Mounts: any;
}

87
ts/docker.classes.host.ts Normal file
View File

@ -0,0 +1,87 @@
import * as plugins from './dockersock.plugins';
import { DockerContainer } from './docker.classes.container';
export class DockerHost {
/**
* the path where the docker sock can be found
*/
sockPath: string;
/**
* keeping track of currently active requests to safely end this module at any time
*/
requestObjectmap = new plugins.lik.Objectmap<any>();
/**
* the constructor to instantiate a new docker sock instance
* @param pathArg
*/
constructor(pathArg: string = 'http://unix:/var/run/docker.sock:') {
this.sockPath = pathArg;
}
/**
* authenticate against a registry
* @param userArg
* @param passArg
*/
auth(registryArg: string, userArg: string, passArg: string) {
let done = plugins.smartpromise.defer();
this.request('POST', '');
return done.promise;
}
/**
*
*/
async getContainers() {
const containerArray = await DockerContainer.getContainers(this);
return containerArray;
};
async getEventObservable(): Promise<plugins.rxjs.Observable<any>> {
const response = await this.requestStreaming('GET', '/events');
return plugins.rxjs.Observable.create(observer => {
response.on('data', data => {
observer.next(data.toString());
});
return () => {
response.emit('end');
};
});
}
/**
* fire a request
*/
async request(methodArg: string, routeArg: string, dataArg = {}) {
const requestUrl = `${this.sockPath}${routeArg}`;
const response = await plugins.smartrequest.request(requestUrl, {
method: methodArg,
headers: {
'Content-Type': 'application/json',
Host: 'docker.sock'
},
requestBody: dataArg
});
return response;
}
async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) {
const requestUrl = `${this.sockPath}${routeArg}`;
const response = await plugins.smartrequest.request(
requestUrl, {
method: methodArg,
headers: {
// 'Content-Type': 'application/json',
Host: 'docker.sock'
},
requestBody: null
},
true
);
console.log(response.statusCode);
console.log(response.body);
return response;
}
}

View File

@ -0,0 +1,14 @@
import * as plugins from './dockersock.plugins';
import { DockerHost } from './docker.classes.host';
export class DockerImage {
/**
* the tags for an image
*/
tags: string[] = [];
static async createFromRegsitry(dockerHostArg: DockerHost): Promise<DockerImage> {
const resultingImage = new DockerImage();
return resultingImage;
}
}

View File

View File

View File

@ -1,133 +0,0 @@
import "typings-global"
import * as plugins from "./dockersock.plugins";
export class Dockersock {
sockPath:string;
constructor(pathArg:string = "http://unix:/var/run/docker.sock:"){
this.sockPath = pathArg;
}
// methods
auth(userArg:string,passArg:string){
let done = plugins.q.defer();
this.request("POST","");
return done.promise;
}
listContainers() {
let done = plugins.q.defer();
this.request("GET","/containers")
.then(done.resolve);
return done.promise;
};
listContainersDetailed() {
let done = plugins.q.defer();
let detailedDataObject = [];
this.listContainers()
.then((dataArg) => {
let recursiveCounter = 0;
let makeDetailed = () => {
if(typeof dataArg[recursiveCounter] != "undefined"){
this.request("GET","/containers/" + dataArg[recursiveCounter].Id)
.then((dataArg2) => {
detailedDataObject.push(dataArg2);
recursiveCounter++;
// recursive call
makeDetailed();
});
} else {
done.resolve(detailedDataObject);
}
};
makeDetailed();
});
return done.promise;
};
listContainersRunning() {
let done = plugins.q.defer();
return done.promise;
}
listContainersStopped() {
let done = plugins.q.defer();
return done.promise;
}
listImages() {
return this.request("GET","/images","?all=true");
}
listImagesDangling(){
return this.request("GET","/images","?dangling=true");
}
pullImage(imageLabel:string){
return this.requestStream("POST","/images/create?fromImage=" + imageLabel);
};
createContainer(imageNameArg,pullFirst:boolean = true){
return this.request("POST","/containers/create","",{
"image":imageNameArg
});
};
getContainerId(){
};
startContainer(containerNameArg){
return this.request("POST","/containers/"+ containerNameArg +"/start");
};
stopContainer(containerNameArg){
return this.request("POST","/containers/"+ containerNameArg +"/stop");
};
removeContainer(containerNameArg){
return this.request("DELETE","/containers/" + containerNameArg + "?v=1");
};
clean() {
let done = plugins.q.defer();
return done.promise;
};
getChange(){
};
request(methodArg:string,routeArg:string,queryArg:string = "", dataArg = {}){
let done = plugins.q.defer();
let jsonArg:string = JSON.stringify(dataArg);
let suffix:string = "";
if(methodArg == "GET") suffix = "/json";
let options = {
method:methodArg,
url:this.sockPath + routeArg + suffix + queryArg,
headers:{
"Content-Type":"application/json"
},
body:jsonArg
};
plugins.request(options,(err, res, body) => {
if (!err && res.statusCode == 200) {
var responseObj = JSON.parse(body);
done.resolve(responseObj);
} else {
console.log(err);
console.log(res);
done.reject(err);
};
});
return done.promise;
}
requestStream(methodArg,routeArg,endArg:boolean = true){
let done = plugins.q.defer();
if(methodArg == "POST"){
let requestStream = plugins.request.post(this.sockPath + routeArg);
requestStream.on("response",(response) => {
if(response.statusCode == 200){
plugins.beautylog.ok("request returned status 200, so we are good!");
} else {
plugins.beautylog.error("request returned error: " + response.statusCode);
done.reject();
}
});
requestStream.on("data",(data:Buffer) => {
let status = JSON.parse(data.toString()).status;
plugins.beautylog.logReduced(status);
});
requestStream.on("end",()=> {
done.resolve();
});
}
return done.promise;
}
}

View File

@ -1,4 +1,19 @@
import "typings-global";
export import beautylog = require("beautylog");
export let q = require("q");
export let request = require("request");
// @pushrocks scope
import * as lik from '@pushrocks/lik';
import * as smartlog from '@pushrocks/smartlog';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
export {
lik,
smartlog,
smartpromise,
smartrequest
};
// third party
import * as rxjs from 'rxjs';
export {
rxjs
};

View File

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

2
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1,2 @@
export * from './label';
export * from './port';

2
ts/interfaces/label.ts Normal file
View File

@ -0,0 +1,2 @@
// tslint:disable-next-line: interface-over-type-literal
export type TLabels = {[key: string]: string };

6
ts/interfaces/port.ts Normal file
View File

@ -0,0 +1,6 @@
export interface IPort {
PrivatePort: 80;
Type: 'tcp';
}
export type TPorts = IPort[];

17
tslint.json Normal file
View File

@ -0,0 +1,17 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}