Compare commits
77 Commits
Author | SHA1 | Date | |
---|---|---|---|
b6b584f808 | |||
48fe6ce0a8 | |||
55acb39071 | |||
f7b17a4684 | |||
d95f6c8e7f | |||
001cdadb6b | |||
82655623d1 | |||
ea117bc391 | |||
57594728df | |||
8430a4d6e0 | |||
7f38868510 | |||
7a80718d27 | |||
1d0c4c3cf9 | |||
a037cba454 | |||
7009e07ecc | |||
7b8ef33e21 | |||
3011e599e8 | |||
8adb636db3 | |||
dd35e5d7d2 | |||
91d7f583e2 | |||
a77ed42e9f | |||
499c6cc3b7 | |||
19283fb695 | |||
b2d84b1399 | |||
7cc2374130 | |||
526bb5bbd0 | |||
14b2105a49 | |||
37efeffe69 | |||
943f46d620 | |||
cfb7c1ce06 | |||
489a47b9bf | |||
28fa5349d7 | |||
cc82b3af04 | |||
6a8751afd2 | |||
56612f9ac9 | |||
2a1fcd8cdb | |||
09911328b2 | |||
548e32419e | |||
2b2b06b48b | |||
37028a9b1f | |||
3cba5844d8 | |||
a3ceb68eab | |||
be659a2dbd | |||
144f963d8a | |||
0c7cd35448 | |||
4e3446cb2f | |||
cec9555908 | |||
14803c1569 | |||
2d2449890f | |||
5fd3a63822 | |||
5ae04ce5c2 | |||
2b3b991372 | |||
487ba592a7 | |||
60e3239d99 | |||
f23cc2eb82 | |||
de05d432b1 | |||
4a90510ff4 | |||
bfda5177a6 | |||
ad2a1ac03d | |||
99db0b902e | |||
515d2d4970 | |||
abf2234480 | |||
b4c6bff74d | |||
4da7f5194a | |||
c356042075 | |||
1d75c1334f | |||
0824d5b910 | |||
0575e618f2 | |||
6b22f12051 | |||
51bf5cfd72 | |||
5cbcba2f1e | |||
16ffe53f30 | |||
4eae29cec9 | |||
188c7af749 | |||
49e7cc010b | |||
c58dad05cd | |||
38dca0c9a0 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
docs/
|
||||
coverage/
|
||||
.yarn/
|
||||
node_modules/
|
||||
coverage/
|
||||
public/
|
||||
|
154
.gitlab-ci.yml
154
.gitlab-ci.yml
@ -1,53 +1,141 @@
|
||||
image: hosttoday/ht-docker-dbase
|
||||
services:
|
||||
- docker:dind
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npmci prepare docker-gitlab
|
||||
|
||||
|
||||
build:
|
||||
stage: build
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npm install
|
||||
- npm test
|
||||
- npmci build docker
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- lossless
|
||||
- priv
|
||||
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
test:
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
sast:
|
||||
stage: security
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
||||
--volume "$PWD:/code"
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
||||
artifacts:
|
||||
reports:
|
||||
sast: gl-sast-report.json
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testSTABLE:
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:dind
|
||||
stage: test
|
||||
script:
|
||||
- npmci test docker
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- priv
|
||||
- docker
|
||||
- priv
|
||||
|
||||
release:
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish npm
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- priv
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- master
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- priv
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
@ -1,3 +0,0 @@
|
||||
FROM hosttoday/ht-docker-node:lts
|
||||
COPY ./node_modules /app-node/node_modules
|
||||
COPY ./dist /app-node/dist
|
36
README.md
36
README.md
@ -1,11 +1,29 @@
|
||||
# dockersock
|
||||
easy communication with docker from node, TypeScript ready
|
||||
# @mojoio/dockersock
|
||||
|
||||
## Status
|
||||
[](https://gitlab.com/pushrocks/dockersock/commits/master)
|
||||
easy communication with docker remote api from node, TypeScript ready
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/dockersock)
|
||||
[](https://GitLab.com/mojoio/dockersock)
|
||||
[](https://github.com/mojoio/dockersock)
|
||||
[](https://mojoio.gitlab.io/dockersock/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/mojoio/dockersock/commits/master)
|
||||
[](https://GitLab.com/mojoio/dockersock/commits/master)
|
||||
[](https://www.npmjs.com/package/dockersock)
|
||||
[](https://david-dm.org/mojoio/dockersock)
|
||||
[](https://www.bithound.io/github/mojoio/dockersock/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/mojoio/dockersock)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](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)
|
||||
|
||||
[](https://mojo.io)
|
||||
|
12
dist/dockersock.class.dockersock.d.ts
vendored
12
dist/dockersock.class.dockersock.d.ts
vendored
@ -1,12 +0,0 @@
|
||||
import "typings-global";
|
||||
export declare class dockersock {
|
||||
sockPath: string;
|
||||
constructor(pathArg?: string);
|
||||
listContainers(): any;
|
||||
listContainersDetailed(): any;
|
||||
listContainersRunning(): any;
|
||||
listContainersStopped(): any;
|
||||
listImages(): any;
|
||||
clean(): any;
|
||||
request(methodArg: string, routeArg: string, dataArg?: {}): any;
|
||||
}
|
87
dist/dockersock.class.dockersock.js
vendored
87
dist/dockersock.class.dockersock.js
vendored
File diff suppressed because one or more lines are too long
4
dist/dockersock.plugins.d.ts
vendored
4
dist/dockersock.plugins.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export declare let q: any;
|
||||
export declare let request: any;
|
7
dist/dockersock.plugins.js
vendored
7
dist/dockersock.plugins.js
vendored
@ -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
|
18
docker-compose.yml
Normal file
18
docker-compose.yml
Normal file
@ -0,0 +1,18 @@
|
||||
nginx1 :
|
||||
image: "nginx"
|
||||
environment:
|
||||
VIRTUAL_HOST: "test100.bleu.de"
|
||||
restart: always
|
||||
container_name: nginx1
|
||||
nginx2:
|
||||
image: nginx
|
||||
environment:
|
||||
VIRTUAL_HOST: "test101.bleu.de"
|
||||
restart: always
|
||||
container_name: nginx2
|
||||
nginx3:
|
||||
image: nginx
|
||||
environment:
|
||||
VIRTUAL_HOST: "test101.bleu.de"
|
||||
restart: always
|
||||
container_name: nginx3
|
13
npmextra.json
Normal file
13
npmextra.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"npmdocker": {
|
||||
"baseImage": "hosttoday/ht-docker-node:npmci",
|
||||
"command":
|
||||
"(ls -a && rm -r node_modules && yarn global add npmts && yarn install && npmts)",
|
||||
"dockerSock": true
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public",
|
||||
"npmRegistryUrl": "registry.npmjs.org"
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"mode":"default"
|
||||
}
|
1575
package-lock.json
generated
Normal file
1575
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
package.json
29
package.json
@ -1,11 +1,13 @@
|
||||
{
|
||||
"name": "dockersock",
|
||||
"version": "1.0.2",
|
||||
"description": "easy communication with docker from node, TypeScript ready",
|
||||
"name": "@mojoio/docker",
|
||||
"version": "1.0.30",
|
||||
"description": "easy communication with docker remote api from node, TypeScript ready",
|
||||
"private": false,
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "npmts",
|
||||
"testindocker": "npmts && docker-machine start default; eval \"$(docker-machine env default)\" && docker build -t test-image . && docker run test-image"
|
||||
"test": "tstest test/",
|
||||
"build": "tsbuild"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -25,12 +27,19 @@
|
||||
},
|
||||
"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"
|
||||
"@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"
|
||||
"@gitzone/tsbuild": "^2.1.4",
|
||||
"@gitzone/tsrun": "^1.1.17",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.12.18",
|
||||
"tslint": "^5.12.0",
|
||||
"tslint-config-prettier": "^1.17.0"
|
||||
}
|
||||
}
|
||||
|
29
test/test.ts
Normal file
29
test/test.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import { DockerHost } from '../ts/index';
|
||||
|
||||
let testDockerHost: DockerHost;
|
||||
|
||||
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();
|
1
ts/docker.changes.ts
Normal file
1
ts/docker.changes.ts
Normal file
@ -0,0 +1 @@
|
||||
import * as plugins from './dockersock.plugins';
|
71
ts/docker.classes.container.ts
Normal file
71
ts/docker.classes.container.ts
Normal file
@ -0,0 +1,71 @@
|
||||
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;
|
||||
}
|
88
ts/docker.classes.host.ts
Normal file
88
ts/docker.classes.host.ts
Normal file
@ -0,0 +1,88 @@
|
||||
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;
|
||||
}
|
||||
}
|
14
ts/docker.classes.image.ts
Normal file
14
ts/docker.classes.image.ts
Normal 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;
|
||||
}
|
||||
}
|
0
ts/docker.classes.network.ts
Normal file
0
ts/docker.classes.network.ts
Normal file
0
ts/docker.classes.service.ts
Normal file
0
ts/docker.classes.service.ts
Normal file
@ -1,79 +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
|
||||
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 = function(){
|
||||
if(typeof dataArg[recursiveCounter] != "undefined"){
|
||||
this.request.get("GET","/containers/" + dataArg[recursiveCounter].Id)
|
||||
.then((data) => {
|
||||
recursiveCounter++;
|
||||
detailedDataObject.push(data);
|
||||
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() {
|
||||
let done = plugins.q.defer();
|
||||
return done.promise;
|
||||
}
|
||||
clean() {
|
||||
let done = plugins.q.defer();
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
request(methodArg:string,routeArg:string,dataArg = {}){
|
||||
let done = plugins.q.defer();
|
||||
let jsonArg:string = JSON.stringify(dataArg);
|
||||
let options = {
|
||||
method:methodArg,
|
||||
url:this.sockPath + routeArg + "/json",
|
||||
headers:{
|
||||
"Content-Type":"application/json"
|
||||
},
|
||||
body:jsonArg
|
||||
};
|
||||
plugins.request(options,function(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;
|
||||
}
|
||||
}
|
@ -1,4 +1,12 @@
|
||||
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 };
|
||||
|
1
ts/index.ts
Normal file
1
ts/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export { DockerHost } from './docker.classes.host';
|
2
ts/interfaces/index.ts
Normal file
2
ts/interfaces/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './label';
|
||||
export * from './port';
|
2
ts/interfaces/label.ts
Normal file
2
ts/interfaces/label.ts
Normal 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
6
ts/interfaces/port.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export interface IPort {
|
||||
PrivatePort: 80;
|
||||
Type: 'tcp';
|
||||
}
|
||||
|
||||
export type TPorts = IPort[];
|
17
tslint.json
Normal file
17
tslint.json
Normal 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"
|
||||
}
|
Reference in New Issue
Block a user