Compare commits
111 Commits
Author | SHA1 | Date | |
---|---|---|---|
b07628bb0b | |||
5815f9b202 | |||
846ea9997e | |||
de54db33ad | |||
314cb692ac | |||
73f8ded3fe | |||
a28b10ac51 | |||
927e2e0acc | |||
c496405818 | |||
020737e21b | |||
fe3560caac | |||
b2a7e67868 | |||
f772ca15ef | |||
71cfad146f | |||
43b1c13256 | |||
2c8b17f029 | |||
c6521d9160 | |||
72c74e44b5 | |||
2fb628213d | |||
373a4e2eac | |||
a202d05e9c | |||
6e97a7d83c | |||
04bb3b9ed0 | |||
29e502a32e | |||
75a118183e | |||
aa1fe594e8 | |||
cf761e19bf | |||
af7590c8de | |||
ee2e4fb856 | |||
ff5cecb07e | |||
e50b028c00 | |||
867dda8e7c | |||
d12d595f21 | |||
6117228ea4 | |||
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 |
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,3 +1,22 @@
|
|||||||
docs/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
120
.gitlab-ci.yml
120
.gitlab-ci.yml
@ -1,53 +1,119 @@
|
|||||||
image: hosttoday/ht-docker-dbase
|
# gitzone ci_default
|
||||||
services:
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
- docker:dind
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .npmci_cache/
|
||||||
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- build
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- trigger
|
- metadata
|
||||||
|
|
||||||
before_script:
|
# ====================
|
||||||
- npmci prepare docker-gitlab
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
build:
|
stage: security
|
||||||
stage: build
|
|
||||||
script:
|
script:
|
||||||
- npm install
|
- npmci git mirror
|
||||||
- npm test
|
|
||||||
- npmci build docker
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- docker
|
||||||
- priv
|
- notpriv
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
test:
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test docker
|
- npmci npm prepare
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- docker
|
||||||
- priv
|
- notpriv
|
||||||
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
image: hosttoday/ht-docker-node:npmts
|
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci publish npm
|
- npmci node install lts
|
||||||
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
allow_failure: true
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: trigger
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- master
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- docker
|
||||||
- priv
|
- notpriv
|
||||||
|
|
||||||
|
pages:
|
||||||
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
|
services:
|
||||||
|
- docker:18-dind
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
FROM hosttoday/ht-docker-node:lts
|
|
||||||
COPY ./node_modules /app-node/node_modules
|
|
||||||
COPY ./dist /app-node/dist
|
|
50
README.md
50
README.md
@ -1,28 +1,38 @@
|
|||||||
# dockersock
|
# @mojoio/docker
|
||||||
easy communication with docker from node, TypeScript ready
|
unofficial docker engine api abstraction package written in TypeScript
|
||||||
|
|
||||||
## Status
|
## Availabililty and Links
|
||||||
[](https://gitlab.com/pushrocks/dockersock/commits/master)
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/docker)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/mojoio/docker)
|
||||||
|
* [github.com (source mirror)](https://github.com/mojoio/docker)
|
||||||
|
* [docs (typedoc)](https://mojoio.gitlab.io/docker/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[](https://gitlab.com/mojoio/docker/commits/master)
|
||||||
|
[](https://gitlab.com/mojoio/docker/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/@mojoio/docker)
|
||||||
|
[](https://snyk.io/test/npm/@mojoio/docker)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](https://prettier.io/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
We recommend the use of TypeScript for best Intellisense.
|
|
||||||
|
|
||||||
```TypeScript
|
Use TypeScript for best in class instellisense.
|
||||||
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
|
```typescript
|
||||||
|
import { DockerHost } from '@mojoio/docker'; // require Dockersock class
|
||||||
|
|
||||||
myDockersock.listContainers() // promise, resolve gets container data
|
const run = async () => {
|
||||||
myDockersock.listContainersDetailed() // promise, resolve gets more detailed container data (by combining several requests internally)
|
const myDockerHost = new DockerHost(); // optional: you can pass a domain to the contructor, defaults to /var/run/docker.sock
|
||||||
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"
|
|
||||||
})
|
|
||||||
|
|
||||||
|
const containers = await myDockerHost.getContainers(); // promise, resolve with an array of DockerContainers
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
||||||
|
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
|
22
npmextra.json
Normal file
22
npmextra.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "mojoio",
|
||||||
|
"gitrepo": "docker",
|
||||||
|
"shortDescription": "unofficial docker engine api abstraction package written in TypeScript",
|
||||||
|
"npmPackagename": "@mojoio/docker",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"mode":"default"
|
|
||||||
}
|
|
1741
package-lock.json
generated
Normal file
1741
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
42
package.json
42
package.json
@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "dockersock",
|
"name": "@mojoio/docker",
|
||||||
"version": "1.0.2",
|
"version": "1.0.47",
|
||||||
"description": "easy communication with docker from node, TypeScript ready",
|
"description": "easy communication with docker remote api from node, TypeScript ready",
|
||||||
|
"private": false,
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npmts",
|
"test": "tstest test/",
|
||||||
"testindocker": "npmts && docker-machine start default; eval \"$(docker-machine env default)\" && docker build -t test-image . && docker run test-image"
|
"build": "tsbuild"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,12 +27,30 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
|
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^5.0.10",
|
"@pushrocks/lik": "^3.0.10",
|
||||||
"q": "^1.4.1",
|
"@pushrocks/smartlog": "^2.0.19",
|
||||||
"request": "^2.72.0",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"typings-global": "^1.0.3"
|
"@pushrocks/smartrequest": "^1.1.16",
|
||||||
|
"rxjs": "^6.5.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts-g": "^5.2.6"
|
"@gitzone/tsbuild": "^2.1.11",
|
||||||
}
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
|
"@gitzone/tstest": "^1.0.24",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.11",
|
||||||
|
"@types/node": "^12.7.1",
|
||||||
|
"tslint": "^5.18.0",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/*",
|
||||||
|
"ts_web/*",
|
||||||
|
"dist/*",
|
||||||
|
"dist_web/*",
|
||||||
|
"dist_ts_web/*",
|
||||||
|
"assets/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
81
test/test.ts
Normal file
81
test/test.ts
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as docker from '../ts/index';
|
||||||
|
import { DockerService } from '../ts/index';
|
||||||
|
|
||||||
|
let testDockerHost: docker.DockerHost;
|
||||||
|
|
||||||
|
tap.test('should create a new Dockersock instance', async () => {
|
||||||
|
testDockerHost = new docker.DockerHost();
|
||||||
|
return expect(testDockerHost).to.be.instanceof(docker.DockerHost);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Containers
|
||||||
|
tap.test('should list containers', async () => {
|
||||||
|
const containers = await testDockerHost.getContainers();
|
||||||
|
console.log(containers);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Networks
|
||||||
|
tap.test('should list networks', async () => {
|
||||||
|
const networks = await testDockerHost.getNetworks();
|
||||||
|
console.log(networks);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should create a network', async () => {
|
||||||
|
const newNetwork = await docker.DockerNetwork.createNetwork(testDockerHost, {
|
||||||
|
Name: 'webgateway'
|
||||||
|
});
|
||||||
|
expect(newNetwork).to.be.instanceOf(docker.DockerNetwork);
|
||||||
|
expect(newNetwork.Name).to.equal('webgateway');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should remove a network', async () => {
|
||||||
|
const webgateway = await docker.DockerNetwork.getNetworkByName(testDockerHost, 'webgateway');
|
||||||
|
await webgateway.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Images
|
||||||
|
tap.test('should pull an image from imagetag', async () => {
|
||||||
|
const image = await docker.DockerImage.createFromRegistry(testDockerHost, {
|
||||||
|
imageUrl: 'hosttoday/ht-docker-node',
|
||||||
|
imageTag: 'alpine'
|
||||||
|
});
|
||||||
|
expect(image).to.be.instanceOf(docker.DockerImage);
|
||||||
|
console.log(image);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should return a change Observable', async tools => {
|
||||||
|
const testObservable = await testDockerHost.getEventObservable();
|
||||||
|
const subscription = testObservable.subscribe(changeObject => {
|
||||||
|
console.log(changeObject);
|
||||||
|
});
|
||||||
|
await tools.delayFor(2000);
|
||||||
|
subscription.unsubscribe();
|
||||||
|
});
|
||||||
|
|
||||||
|
// SERVICES
|
||||||
|
tap.test('should activate swarm mode', async () => {
|
||||||
|
await testDockerHost.activateSwarm();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should list all services', async tools => {
|
||||||
|
const services = await docker.DockerService.getServices(testDockerHost);
|
||||||
|
console.log(services);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should create a service', async () => {
|
||||||
|
const testNetwork = await docker.DockerNetwork.createNetwork(testDockerHost, {
|
||||||
|
Name: 'testNetwork'
|
||||||
|
});
|
||||||
|
await DockerService.createService(testDockerHost, {
|
||||||
|
Image: 'nginx:latest',
|
||||||
|
Labels: {
|
||||||
|
'testlabel': 'hi'
|
||||||
|
},
|
||||||
|
Name: 'testService',
|
||||||
|
networks: [testNetwork],
|
||||||
|
networkAlias: 'testService'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
101
ts/docker.classes.container.ts
Normal file
101
ts/docker.classes.container.ts
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
|
||||||
|
export class DockerContainer {
|
||||||
|
// STATIC
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get all containers
|
||||||
|
*/
|
||||||
|
public static async getContainers(dockerHostArg: DockerHost): Promise<DockerContainer[]> {
|
||||||
|
const result: DockerContainer[] = [];
|
||||||
|
const response = await dockerHostArg.request('GET', '/containers/json');
|
||||||
|
|
||||||
|
// TODO: Think about getting the config by inpsecting the container
|
||||||
|
for (const containerResult of response.body) {
|
||||||
|
result.push(new DockerContainer(dockerHostArg, containerResult));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets an container by Id
|
||||||
|
* @param containerId
|
||||||
|
*/
|
||||||
|
public static async getContainerById(containerId: string) {
|
||||||
|
// TODO: implement get container by id
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create a container
|
||||||
|
*/
|
||||||
|
public static async create(
|
||||||
|
dockerHost: DockerHost,
|
||||||
|
containerCreationDescriptor: interfaces.IContainerCreationDescriptor
|
||||||
|
) {
|
||||||
|
// check for unique hostname
|
||||||
|
const existingContainers = await DockerContainer.getContainers(dockerHost);
|
||||||
|
const sameHostNameContainer = existingContainers.find(container => {
|
||||||
|
// TODO implement HostName Detection;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
const response = await dockerHost.request('POST', '/containers/create', {
|
||||||
|
Hostname: containerCreationDescriptor.Hostname,
|
||||||
|
Domainname: containerCreationDescriptor.Domainname,
|
||||||
|
User: 'root'
|
||||||
|
});
|
||||||
|
if (response.statusCode < 300) {
|
||||||
|
plugins.smartlog.defaultLogger.log('info', 'Container created successfully');
|
||||||
|
} else {
|
||||||
|
plugins.smartlog.defaultLogger.log(
|
||||||
|
'error',
|
||||||
|
'There has been a problem when creating the container'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
|
// references
|
||||||
|
public dockerHost: DockerHost;
|
||||||
|
|
||||||
|
// properties
|
||||||
|
public Id: string;
|
||||||
|
public Names: string[];
|
||||||
|
public Image: string;
|
||||||
|
public ImageID: string;
|
||||||
|
public Command: string;
|
||||||
|
public Created: number;
|
||||||
|
public Ports: interfaces.TPorts;
|
||||||
|
public Labels: interfaces.TLabels;
|
||||||
|
public State: string;
|
||||||
|
public Status: string;
|
||||||
|
public HostConfig: any;
|
||||||
|
public 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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
public Mounts: any;
|
||||||
|
constructor(dockerHostArg: DockerHost, dockerContainerObjectArg: any) {
|
||||||
|
this.dockerHost = dockerHostArg;
|
||||||
|
Object.keys(dockerContainerObjectArg).forEach(keyArg => {
|
||||||
|
this[keyArg] = dockerContainerObjectArg[keyArg];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
121
ts/docker.classes.host.ts
Normal file
121
ts/docker.classes.host.ts
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import { DockerContainer } from './docker.classes.container';
|
||||||
|
import { DockerNetwork } from './docker.classes.network';
|
||||||
|
|
||||||
|
export class DockerHost {
|
||||||
|
/**
|
||||||
|
* the path where the docker sock can be found
|
||||||
|
*/
|
||||||
|
public socketPath: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the constructor to instantiate a new docker sock instance
|
||||||
|
* @param pathArg
|
||||||
|
*/
|
||||||
|
constructor(pathArg: string = 'http://unix:/var/run/docker.sock:') {
|
||||||
|
this.socketPath = pathArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* authenticate against a registry
|
||||||
|
* @param userArg
|
||||||
|
* @param passArg
|
||||||
|
*/
|
||||||
|
public async auth(registryArg: string, userArg: string, passArg: string) {
|
||||||
|
// TODO: implement Docker Registry authentication
|
||||||
|
await this.request('POST', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets all networks
|
||||||
|
*/
|
||||||
|
public async getNetworks() {
|
||||||
|
return await DockerNetwork.getNetworks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets all containers
|
||||||
|
*/
|
||||||
|
public async getContainers() {
|
||||||
|
const containerArray = await DockerContainer.getContainers(this);
|
||||||
|
return containerArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public async getEventObservable(): Promise<plugins.rxjs.Observable<any>> {
|
||||||
|
const response = await this.requestStreaming('GET', '/events');
|
||||||
|
return plugins.rxjs.Observable.create(observer => {
|
||||||
|
response.on('data', data => {
|
||||||
|
const eventString = data.toString();
|
||||||
|
try {
|
||||||
|
const eventObject = JSON.parse(eventString);
|
||||||
|
observer.next(eventObject);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
response.emit('end');
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* activates docker swarm
|
||||||
|
*/
|
||||||
|
public async activateSwarm(addvertisementIpArg?: string) {
|
||||||
|
const response = await this.request('POST', '/swarm/init', {
|
||||||
|
ListenAddr: '0.0.0.0:2377',
|
||||||
|
AdvertiseAddr: addvertisementIpArg ? `${addvertisementIpArg}:2377` : undefined,
|
||||||
|
DataPathPort: 4789,
|
||||||
|
DefaultAddrPool: ['10.10.0.0/8', '20.20.0.0/8'],
|
||||||
|
SubnetSize: 24,
|
||||||
|
ForceNewCluster: false
|
||||||
|
});
|
||||||
|
if (response.statusCode === 200) {
|
||||||
|
plugins.smartlog.defaultLogger.log('info', 'created Swam succesfully');
|
||||||
|
} else {
|
||||||
|
plugins.smartlog.defaultLogger.log('error', 'could not initiate swarm');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fire a request
|
||||||
|
*/
|
||||||
|
public async request(methodArg: string, routeArg: string, dataArg = {}) {
|
||||||
|
const requestUrl = `${this.socketPath}${routeArg}`;
|
||||||
|
const response = await plugins.smartrequest.request(requestUrl, {
|
||||||
|
method: methodArg,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Host: 'docker.sock'
|
||||||
|
},
|
||||||
|
requestBody: dataArg
|
||||||
|
});
|
||||||
|
if (response.statusCode !== 200) {
|
||||||
|
console.log(response.body);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) {
|
||||||
|
const requestUrl = `${this.socketPath}${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;
|
||||||
|
}
|
||||||
|
}
|
128
ts/docker.classes.image.ts
Normal file
128
ts/docker.classes.image.ts
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
|
||||||
|
export class DockerImage {
|
||||||
|
// STATIC
|
||||||
|
public static async getImages(dockerHost: DockerHost) {
|
||||||
|
const images: DockerImage[] = [];
|
||||||
|
const response = await dockerHost.request('GET', '/images/json');
|
||||||
|
for (const imageObject of response.body) {
|
||||||
|
images.push(new DockerImage(dockerHost, imageObject));
|
||||||
|
}
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async findImageByName(dockerHost: DockerHost, imageNameArg: string) {
|
||||||
|
const images = await this.getImages(dockerHost);
|
||||||
|
return images.find(image => {
|
||||||
|
return image.RepoTags.includes(imageNameArg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async createFromRegistry(
|
||||||
|
dockerHostArg: DockerHost,
|
||||||
|
creationObject: interfaces.IImageCreationDescriptor
|
||||||
|
): Promise<DockerImage> {
|
||||||
|
|
||||||
|
// lets create a sanatized imageUrlObject
|
||||||
|
const imageUrlObject: {
|
||||||
|
imageUrl: string;
|
||||||
|
imageTag: string;
|
||||||
|
imageOriginTag: string;
|
||||||
|
} = {
|
||||||
|
imageUrl: creationObject.imageUrl,
|
||||||
|
imageTag: creationObject.imageTag,
|
||||||
|
imageOriginTag: null
|
||||||
|
};
|
||||||
|
if (imageUrlObject.imageUrl.includes(':')) {
|
||||||
|
const imageUrl = imageUrlObject.imageUrl.split(':')[0];
|
||||||
|
const imageTag = imageUrlObject.imageUrl.split(':')[1];
|
||||||
|
if (imageUrlObject.imageTag) {
|
||||||
|
throw new Error(
|
||||||
|
`imageUrl ${imageUrlObject.imageUrl} can't be tagged with ${
|
||||||
|
imageUrlObject.imageTag
|
||||||
|
} because it is already tagged with ${imageTag}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
imageUrlObject.imageTag = imageTag;
|
||||||
|
}
|
||||||
|
} else if (!imageUrlObject.imageTag) {
|
||||||
|
imageUrlObject.imageTag = 'latest';
|
||||||
|
}
|
||||||
|
imageUrlObject.imageOriginTag = `${imageUrlObject.imageUrl}:${imageUrlObject.imageTag}`;
|
||||||
|
|
||||||
|
// lets actually create the image
|
||||||
|
const response = await dockerHostArg.request(
|
||||||
|
'POST',
|
||||||
|
`/images/create?fromImage=${encodeURIComponent(
|
||||||
|
imageUrlObject.imageUrl
|
||||||
|
)}&tag=${encodeURIComponent(imageUrlObject.imageTag)}`
|
||||||
|
);
|
||||||
|
if (response.statusCode < 300) {
|
||||||
|
plugins.smartlog.defaultLogger.log(
|
||||||
|
'info',
|
||||||
|
`Successfully pulled image ${imageUrlObject.imageUrl} from the registry`
|
||||||
|
);
|
||||||
|
const image = await DockerImage.findImageByName(dockerHostArg, imageUrlObject.imageOriginTag);
|
||||||
|
return image;
|
||||||
|
} else {
|
||||||
|
plugins.smartlog.defaultLogger.log('error', `Failed at the attempt of creating a new image`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async tagImageByIdOrName(
|
||||||
|
dockerHost: DockerHost,
|
||||||
|
idOrNameArg: string,
|
||||||
|
newTagArg: string
|
||||||
|
) {
|
||||||
|
const response = await dockerHost.request(
|
||||||
|
'POST',
|
||||||
|
`/images/${encodeURIComponent(idOrNameArg)}/${encodeURIComponent(newTagArg)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async buildImage(dockerHostArg: DockerHost, dockerImageTag) {
|
||||||
|
// TODO: implement building an image
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
|
// references
|
||||||
|
public dockerHost: DockerHost;
|
||||||
|
|
||||||
|
// properties
|
||||||
|
/**
|
||||||
|
* the tags for an image
|
||||||
|
*/
|
||||||
|
public Containers: number;
|
||||||
|
public Created: number;
|
||||||
|
public Id: string;
|
||||||
|
public Labels: interfaces.TLabels;
|
||||||
|
public ParentId: string;
|
||||||
|
public RepoDigests: string[];
|
||||||
|
public RepoTags: string[];
|
||||||
|
public SharedSize: number;
|
||||||
|
public Size: number;
|
||||||
|
public VirtualSize: number;
|
||||||
|
|
||||||
|
constructor(dockerHostArg, dockerImageObjectArg: any) {
|
||||||
|
this.dockerHost = dockerHostArg;
|
||||||
|
Object.keys(dockerImageObjectArg).forEach(keyArg => {
|
||||||
|
this[keyArg] = dockerImageObjectArg[keyArg];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public tagImage(newTag) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pulls the latest version from the registry
|
||||||
|
*/
|
||||||
|
public async pullLatestImageFromRegistry(): Promise<boolean> {
|
||||||
|
const updatedImage = await DockerImage.createFromRegistry(this.dockerHost, {
|
||||||
|
imageUrl: this.RepoTags[0]
|
||||||
|
});
|
||||||
|
Object.assign(this, updatedImage);
|
||||||
|
// TODO: Compare image digists before and after
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
94
ts/docker.classes.network.ts
Normal file
94
ts/docker.classes.network.ts
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
|
||||||
|
export class DockerNetwork {
|
||||||
|
public static async getNetworks(dockerHost: DockerHost): Promise<DockerNetwork[]> {
|
||||||
|
const dockerNetworks: DockerNetwork[] = [];
|
||||||
|
const response = await dockerHost.request('GET', '/networks');
|
||||||
|
for (const networkObject of response.body) {
|
||||||
|
dockerNetworks.push(new DockerNetwork(dockerHost, networkObject));
|
||||||
|
}
|
||||||
|
return dockerNetworks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getNetworkByName(dockerHost: DockerHost, dockerNetworkNameArg: string) {
|
||||||
|
const networks = await DockerNetwork.getNetworks(dockerHost);
|
||||||
|
return networks.find(dockerNetwork => dockerNetwork.Name === dockerNetworkNameArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async createNetwork(
|
||||||
|
dockerHost: DockerHost,
|
||||||
|
networkCreationDescriptor: interfaces.INetworkCreationDescriptor
|
||||||
|
): Promise<DockerNetwork> {
|
||||||
|
const response = await dockerHost.request('POST', '/networks/create', {
|
||||||
|
Name: networkCreationDescriptor.Name,
|
||||||
|
CheckDuplicate: true,
|
||||||
|
Driver: 'overlay',
|
||||||
|
EnableIPv6: false,
|
||||||
|
IPAM: {
|
||||||
|
Driver: 'default',
|
||||||
|
Config: [
|
||||||
|
{
|
||||||
|
Subnet: '172.20.10.0/16',
|
||||||
|
IPRange: '172.20.10.0/24',
|
||||||
|
Gateway: '172.20.10.11'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Internal: true,
|
||||||
|
Attachable: true,
|
||||||
|
Ingress: false
|
||||||
|
});
|
||||||
|
if (response.statusCode < 300) {
|
||||||
|
plugins.smartlog.defaultLogger.log('info', 'Created network successfully');
|
||||||
|
return await DockerNetwork.getNetworkByName(dockerHost, networkCreationDescriptor.Name);
|
||||||
|
} else {
|
||||||
|
plugins.smartlog.defaultLogger.log(
|
||||||
|
'error',
|
||||||
|
'There has been an error creating the wanted network'
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
|
// references
|
||||||
|
public dockerHost: DockerHost;
|
||||||
|
|
||||||
|
// properties
|
||||||
|
public Name: string;
|
||||||
|
public Id: string;
|
||||||
|
public Created: string;
|
||||||
|
public Scope: string;
|
||||||
|
public Driver: string;
|
||||||
|
public EnableIPv6: boolean;
|
||||||
|
public Internal: boolean;
|
||||||
|
public Attachable: boolean;
|
||||||
|
public Ingress: false;
|
||||||
|
public IPAM: {
|
||||||
|
Driver: 'default' | 'bridge' | 'overlay';
|
||||||
|
Config: [
|
||||||
|
{
|
||||||
|
Subnet: string;
|
||||||
|
IPRange: string;
|
||||||
|
Gateway: string;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(dockerHostArg: DockerHost, dockerNetworkObjectArg: any) {
|
||||||
|
this.dockerHost = dockerHostArg;
|
||||||
|
Object.keys(dockerNetworkObjectArg).forEach(keyArg => {
|
||||||
|
this[keyArg] = dockerNetworkObjectArg[keyArg];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes the network
|
||||||
|
*/
|
||||||
|
public async remove() {
|
||||||
|
const response = await this.dockerHost.request('DELETE', `/networks/${this.Id}`);
|
||||||
|
}
|
||||||
|
}
|
63
ts/docker.classes.service.ts
Normal file
63
ts/docker.classes.service.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
import { DockerImage } from './docker.classes.image';
|
||||||
|
|
||||||
|
export class DockerService {
|
||||||
|
// STATIC
|
||||||
|
public static async getServices(dockerHost: DockerHost) {
|
||||||
|
const services: DockerService[] = [];
|
||||||
|
const response = await dockerHost.request('GET', '/services');
|
||||||
|
for (const serviceObject of response.body) {
|
||||||
|
services.push(new DockerService(dockerHost, serviceObject));
|
||||||
|
}
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a service
|
||||||
|
*/
|
||||||
|
public static async createService(
|
||||||
|
dockerHost: DockerHost,
|
||||||
|
serviceCreationDescriptor: interfaces.IServiceCreationDescriptor
|
||||||
|
) {
|
||||||
|
// lets get the image
|
||||||
|
plugins.smartlog.defaultLogger.log('info', `downloading image for service ${serviceCreationDescriptor.Name}`);
|
||||||
|
const serviceImage = await DockerImage.createFromRegistry(dockerHost, {
|
||||||
|
imageUrl: serviceCreationDescriptor.Image
|
||||||
|
});
|
||||||
|
|
||||||
|
const networkArray: any[] = [];
|
||||||
|
for (const network of serviceCreationDescriptor.networks) {
|
||||||
|
networkArray.push({
|
||||||
|
Target: network.Name,
|
||||||
|
Aliases: [serviceCreationDescriptor.networkAlias]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
dockerHost.request('POST', '/services/create', {
|
||||||
|
Name: serviceCreationDescriptor.Name,
|
||||||
|
TaskTemplate: {
|
||||||
|
ContainerSpec: {
|
||||||
|
Image: serviceCreationDescriptor.Image,
|
||||||
|
Labels: serviceCreationDescriptor.Labels
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Labels: serviceCreationDescriptor.Labels,
|
||||||
|
Networks: networkArray
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
|
public dockerHost: DockerHost;
|
||||||
|
|
||||||
|
constructor(dockerHostArg: DockerHost, serviceObject) {
|
||||||
|
this.dockerHost = dockerHostArg;
|
||||||
|
Object.assign(this, serviceObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
// TODO: implemnt updating service
|
||||||
|
}
|
||||||
|
}
|
14
ts/docker.plugins.ts
Normal file
14
ts/docker.plugins.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// @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';
|
||||||
|
|
||||||
|
smartlog.defaultLogger.enableConsole();
|
||||||
|
|
||||||
|
export { lik, smartlog, smartpromise, smartrequest };
|
||||||
|
|
||||||
|
// third party
|
||||||
|
import * as rxjs from 'rxjs';
|
||||||
|
|
||||||
|
export { rxjs };
|
@ -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 +0,0 @@
|
|||||||
import "typings-global";
|
|
||||||
export import beautylog = require("beautylog");
|
|
||||||
export let q = require("q");
|
|
||||||
export let request = require("request");
|
|
5
ts/index.ts
Normal file
5
ts/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export * from './docker.classes.host';
|
||||||
|
export * from './docker.classes.container';
|
||||||
|
export * from './docker.classes.image';
|
||||||
|
export * from './docker.classes.network';
|
||||||
|
export * from './docker.classes.service';
|
7
ts/interfaces/container.ts
Normal file
7
ts/interfaces/container.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { DockerNetwork } from '../docker.classes.network';
|
||||||
|
|
||||||
|
export interface IContainerCreationDescriptor {
|
||||||
|
Hostname: string;
|
||||||
|
Domainname: string;
|
||||||
|
networks?: DockerNetwork[];
|
||||||
|
}
|
4
ts/interfaces/image.ts
Normal file
4
ts/interfaces/image.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface IImageCreationDescriptor {
|
||||||
|
imageUrl: string;
|
||||||
|
imageTag?: string;
|
||||||
|
}
|
6
ts/interfaces/index.ts
Normal file
6
ts/interfaces/index.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export * from './container';
|
||||||
|
export * from './image';
|
||||||
|
export * from './label';
|
||||||
|
export * from './network';
|
||||||
|
export * from './port';
|
||||||
|
export * from './service';
|
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/network.ts
Normal file
6
ts/interfaces/network.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* creates a new Network
|
||||||
|
*/
|
||||||
|
export interface INetworkCreationDescriptor {
|
||||||
|
Name: 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[];
|
10
ts/interfaces/service.ts
Normal file
10
ts/interfaces/service.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import * as interfaces from './';
|
||||||
|
import { DockerNetwork } from '../docker.classes.network';
|
||||||
|
|
||||||
|
export interface IServiceCreationDescriptor {
|
||||||
|
Name: string;
|
||||||
|
Image: string;
|
||||||
|
Labels: interfaces.TLabels;
|
||||||
|
networks: DockerNetwork[];
|
||||||
|
networkAlias: string;
|
||||||
|
}
|
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