Compare commits
197 Commits
Author | SHA1 | Date | |
---|---|---|---|
b808a93e46 | |||
a18166260e | |||
cba8de348d | |||
30d4a7bd24 | |||
4ea99426fd | |||
19309f7f45 | |||
4e7d2fd637 | |||
1675c0c4c9 | |||
3a4f59ef9e | |||
90eac3e50a | |||
edec48529d | |||
e622b97097 | |||
23266ca459 | |||
a91e69b6db | |||
015ccfad48 | |||
06d2fcb750 | |||
f3e4bc0350 | |||
6de3abe3bf | |||
eaa4140f2f | |||
b21fe80109 | |||
96a2992432 | |||
870b5f2c07 | |||
212edf1db7 | |||
46dbd81bcc | |||
8f5678502d | |||
959d7aaed1 | |||
5aa10653b6 | |||
e120d6527e | |||
c80da05fbb | |||
b9c3475b86 | |||
de2d7e647b | |||
d9348bd016 | |||
034fbc3994 | |||
a33a6a1f7f | |||
9dd403821b | |||
601d82ea74 | |||
784bb22511 | |||
71c89ac9bc | |||
0b3e3b68c9 | |||
f3779faaaf | |||
73476c2c39 | |||
942f65268d | |||
a965647c1f | |||
db88c7f86c | |||
3f18cb68bf | |||
dae3b59e3b | |||
53062e70d4 | |||
3e70dc465b | |||
49445d93c6 | |||
4f838837f8 | |||
c76968bbe8 | |||
6c5e5644b1 | |||
5cf80944fe | |||
cdb69c5f17 | |||
178c1d2df1 | |||
43d9da808b | |||
15f5c38eb0 | |||
225c1be14c | |||
44f2aab2f6 | |||
b69315f1d3 | |||
7d20804986 | |||
0aab639fbd | |||
794bb60dfc | |||
b182a379af | |||
5c6c06dee6 | |||
a48e1e035e | |||
8836c06b56 | |||
7af8e0739b | |||
684185e951 | |||
21e6fff3fb | |||
83c49a6234 | |||
ad67849d45 | |||
0e4e07a912 | |||
1fbc09f557 | |||
d6201b864c | |||
ea5e552192 | |||
1afe5c6e16 | |||
eb0dc96dbd | |||
55f45b1c3a | |||
87ff0f01bb | |||
dd1939d7b2 | |||
5a2a5f1248 | |||
9767b8767a | |||
546e139b46 | |||
28d70bb49f | |||
b71f134abd | |||
968b3c7449 | |||
d9558f7843 | |||
19e67ffdcc | |||
e983b66c28 | |||
c79f6a698f | |||
0ef098e9c8 | |||
d56350ff28 | |||
a4dc4e7950 | |||
424e911804 | |||
b5c4727bae | |||
b6f3fbf8a9 | |||
7241e7a8fd | |||
ae37148ece | |||
65c37bdd6f | |||
6acbe30e2e | |||
eb6f7889d0 | |||
e39da5fee9 | |||
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 |
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,3 +1,20 @@
|
|||||||
docs/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
152
.gitlab-ci.yml
152
.gitlab-ci.yml
@ -1,53 +1,137 @@
|
|||||||
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:
|
|
||||||
- lossless
|
|
||||||
- priv
|
|
||||||
|
|
||||||
|
|
||||||
test:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test docker
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- priv
|
|
||||||
|
|
||||||
release:
|
|
||||||
image: hosttoday/ht-docker-node:npmts
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci publish npm
|
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
|
testStable:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
script:
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm publish
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: trigger
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
pages:
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
9
.snyk
Normal file
9
.snyk
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||||
|
version: v1.13.5
|
||||||
|
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
|
||||||
|
ignore:
|
||||||
|
SNYK-JS-HTTPSPROXYAGENT-469131:
|
||||||
|
- '@pushrocks/smartnetwork > speedtest-net > https-proxy-agent':
|
||||||
|
reason: None given
|
||||||
|
expires: '2019-11-04T13:59:28.695Z'
|
||||||
|
patch: {}
|
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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -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"]
|
|
28
README.md
28
README.md
@ -1,28 +0,0 @@
|
|||||||
# dockersock
|
|
||||||
easy communication with docker from node, TypeScript ready
|
|
||||||
|
|
||||||
## Status
|
|
||||||
[](https://gitlab.com/pushrocks/dockersock/commits/master)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
We recommend the use of TypeScript for best Intellisense.
|
|
||||||
|
|
||||||
```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"
|
|
||||||
})
|
|
||||||
|
|
||||||
```
|
|
22
dist/dockersock.classes.dockersock.d.ts
vendored
22
dist/dockersock.classes.dockersock.d.ts
vendored
@ -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(optionsArg: any, pullFirstArg?: boolean): any;
|
|
||||||
getContainerId(): void;
|
|
||||||
startContainer(containerNameArg: any): any;
|
|
||||||
stopContainer(containerNameArg: any): any;
|
|
||||||
removeContainer(containerNameArg: any): any;
|
|
||||||
clean(): any;
|
|
||||||
callOnChange(cb: Function): void;
|
|
||||||
request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): any;
|
|
||||||
requestStream(methodArg: any, routeArg: any, endArg?: boolean): any;
|
|
||||||
}
|
|
193
dist/dockersock.classes.dockersock.js
vendored
193
dist/dockersock.classes.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
|
|
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
import "typings-global";
|
|
||||||
export { Dockersock } from "./dockersock.classes.dockersock";
|
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -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=
|
|
@ -1,18 +1,18 @@
|
|||||||
nginx1 :
|
nginx1 :
|
||||||
image: "nginx"
|
image: "nginx"
|
||||||
environment:
|
environment:
|
||||||
VIRTUAL_HOST: "test100.labkomp.de"
|
VIRTUAL_HOST: "test100.bleu.de"
|
||||||
restart: always
|
restart: always
|
||||||
container_name: nginx1
|
container_name: nginx1
|
||||||
nginx2:
|
nginx2:
|
||||||
image: nginx
|
image: nginx
|
||||||
environment:
|
environment:
|
||||||
VIRTUAL_HOST: "test101.labkomp.de"
|
VIRTUAL_HOST: "test101.bleu.de"
|
||||||
restart: always
|
restart: always
|
||||||
container_name: nginx2
|
container_name: nginx2
|
||||||
npmts-test-container:
|
nginx3:
|
||||||
image: "npmts-test-image"
|
image: nginx
|
||||||
volumes:
|
environment:
|
||||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
VIRTUAL_HOST: "test101.bleu.de"
|
||||||
restart: always
|
restart: always
|
||||||
container_name: npmts-test-container
|
container_name: nginx3
|
23
npmextra.json
Normal file
23
npmextra.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"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": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "mojoio",
|
||||||
|
"gitrepo": "docker",
|
||||||
|
"shortDescription": "unofficial docker engine api abstraction package written in TypeScript",
|
||||||
|
"npmPackagename": "@mojoio/docker",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"mode":"default",
|
|
||||||
"coverageTreshold":10
|
|
||||||
}
|
|
11087
package-lock.json
generated
Normal file
11087
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
60
package.json
60
package.json
@ -1,14 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "dockersock",
|
"name": "@mojoio/docker",
|
||||||
"version": "1.0.7",
|
"version": "1.0.99",
|
||||||
"description": "easy communication with docker from node, TypeScript ready",
|
"description": "easy communication with docker remote api from node, TypeScript ready",
|
||||||
"main": "dist/index.js",
|
"private": false,
|
||||||
"typings": "dist/index.d.ts",
|
"main": "dist_ts/index.js",
|
||||||
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npmts --notest && npm run build && npm run startdocker && npm run cleanup",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "docker build -t npmts-test-image .",
|
"build": "(tsbuild --web)"
|
||||||
"startdocker": "docker run -v /var/run/docker.sock:/var/run/docker.sock --name npmts-test-container npmts-test-image",
|
|
||||||
"cleanup": "docker rm npmts-test-container && docker rmi npmts-test-image"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -28,14 +27,41 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
|
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^5.0.12",
|
"@pushrocks/lik": "^4.0.17",
|
||||||
"q": "^1.4.1",
|
"@pushrocks/smartfile": "^8.0.0",
|
||||||
"request": "^2.72.0",
|
"@pushrocks/smartjson": "^3.0.10",
|
||||||
"typings-global": "^1.0.3"
|
"@pushrocks/smartlog": "^2.0.39",
|
||||||
|
"@pushrocks/smartnetwork": "^1.1.22",
|
||||||
|
"@pushrocks/smartpath": "^4.0.3",
|
||||||
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.51",
|
||||||
|
"@pushrocks/smartstring": "^3.0.18",
|
||||||
|
"@pushrocks/smartversion": "^2.0.4",
|
||||||
|
"@tsclass/tsclass": "^3.0.25",
|
||||||
|
"rxjs": "^6.6.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts-g": "^5.2.6",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"should": "^9.0.2",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"typings-test": "^1.0.1"
|
"@gitzone/tstest": "^1.0.48",
|
||||||
}
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
|
"@types/node": "^14.11.2",
|
||||||
|
"tslint": "^6.1.3",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
49
readme.md
Normal file
49
readme.md
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# @mojoio/docker
|
||||||
|
unofficial docker engine api abstraction package written in TypeScript
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [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
|
||||||
|
|
||||||
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
|
npm | [](https://lossless.cloud)
|
||||||
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { DockerHost } from '@mojoio/docker'; // require Dockersock class
|
||||||
|
|
||||||
|
const run = async () => {
|
||||||
|
const myDockerHost = new DockerHost(); // optional: you can pass a domain to the contructor, defaults to /var/run/docker.sock
|
||||||
|
|
||||||
|
const containers = await myDockerHost.getContainers(); // promise, resolve with an array of DockerContainers
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
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)
|
11
scripts/testauth.ts
Normal file
11
scripts/testauth.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import * as docker from '../ts';
|
||||||
|
import * as smartstring from '@pushrocks/smartstring';
|
||||||
|
|
||||||
|
const run = async () => {
|
||||||
|
const dockerHost = new docker.DockerHost();
|
||||||
|
await docker.DockerImage.createFromRegistry(dockerHost, {
|
||||||
|
imageUrl: 'registry.gitlab.com/servezone/private/cloudly:latest'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
run();
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
import "typings-test";
|
|
||||||
import "should";
|
|
37
test/test.js
37
test/test.js
@ -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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUVQLENBQUMsQ0FGYztBQUVmLHNCQUF5QixlQUV6QixDQUFDLENBRnVDO0FBRXhDLFFBQVEsQ0FBQyxZQUFZLEVBQUM7SUFDbEIsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixJQUFJLGNBQXlCLENBQUM7UUFDOUIsRUFBRSxDQUFDLHlDQUF5QyxFQUFDO1lBQ3pDLGNBQWMsR0FBRyxJQUFJLGtCQUFVLEVBQUUsQ0FBQztZQUNsQyxjQUFjLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsa0JBQVUsQ0FBQyxDQUFDO1FBQ3BELENBQUMsQ0FBQyxDQUFDO1FBQ0gsRUFBRSxDQUFDLHdCQUF3QixFQUFDLFVBQVMsSUFBSTtZQUNyQyxjQUFjLENBQUMsY0FBYyxFQUFFO2lCQUMxQixJQUFJLENBQUMsVUFBQyxPQUFPO2dCQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLENBQUM7Z0JBQ3JCLElBQUksRUFBRSxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUM7UUFDWCxDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQyxpQ0FBaUMsRUFBQyxVQUFTLElBQUk7WUFDOUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztZQUNuQixjQUFjLENBQUMsc0JBQXNCLEVBQUU7aUJBQ2xDLElBQUksQ0FBQyxVQUFDLE9BQU87Z0JBQ1YsT0FBTyxDQUFDLEdBQUcsQ0FBQyxPQUFPLENBQUMsQ0FBQztnQkFDckIsSUFBSSxFQUFFLENBQUM7WUFDWCxDQUFDLENBQUMsQ0FBQztRQUNYLENBQUMsQ0FBQyxDQUFDO1FBQ0gsRUFBRSxDQUFDLG9DQUFvQyxFQUFDLFVBQVMsSUFBSTtZQUNqRCxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFDO1lBQ3BCLGNBQWMsQ0FBQyxTQUFTLENBQUMsNkJBQTZCLENBQUM7aUJBQ2xELElBQUksQ0FBQyxVQUFDLE9BQU87Z0JBQ1YsSUFBSSxFQUFFLENBQUM7WUFDWCxDQUFDLEVBQUMsSUFBSSxDQUFDLENBQUM7UUFDaEIsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQztBQUNQLENBQUMsQ0FBQyxDQUFDIiwiZmlsZSI6InRlc3QuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLXRlc3RcIjtcbmltcG9ydCBcInNob3VsZFwiXG5cbmltcG9ydCB7RG9ja2Vyc29ja30gZnJvbSBcIi4uL2Rpc3QvaW5kZXhcIlxuXG5kZXNjcmliZShcImRvY2tlcnNvY2tcIixmdW5jdGlvbigpe1xuICAgIGRlc2NyaWJlKFwiLkRvY2tlcnNvY2soKVwiLGZ1bmN0aW9uKCl7XG4gICAgICAgIGxldCB0ZXN0RG9ja2Vyc29jazpEb2NrZXJzb2NrO1xuICAgICAgICBpdChcInNob3VsZCBjcmVhdGUgYSBuZXcgRG9ja2Vyc29jayBpbnN0YW5jZVwiLGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICB0ZXN0RG9ja2Vyc29jayA9IG5ldyBEb2NrZXJzb2NrKCk7XG4gICAgICAgICAgICB0ZXN0RG9ja2Vyc29jay5zaG91bGQuYmUuaW5zdGFuY2VvZihEb2NrZXJzb2NrKTtcbiAgICAgICAgfSk7XG4gICAgICAgIGl0KFwic2hvdWxkIGxpc3QgY29udGFpbmVyc1wiLGZ1bmN0aW9uKGRvbmUpe1xuICAgICAgICAgICAgdGVzdERvY2tlcnNvY2subGlzdENvbnRhaW5lcnMoKVxuICAgICAgICAgICAgICAgIC50aGVuKChkYXRhQXJnKT0+e1xuICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhkYXRhQXJnKTtcbiAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICB9KTtcbiAgICAgICAgaXQoXCJzaG91bGQgbGlzdCBkZXRhaWxlZCBjb250YWluZXJzXCIsZnVuY3Rpb24oZG9uZSl7XG4gICAgICAgICAgICB0aGlzLnRpbWVvdXQoNTAwMCk7XG4gICAgICAgICAgICB0ZXN0RG9ja2Vyc29jay5saXN0Q29udGFpbmVyc0RldGFpbGVkKClcbiAgICAgICAgICAgICAgICAudGhlbigoZGF0YUFyZyk9PntcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZGF0YUFyZyk7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgICAgIGl0KFwic2hvdWxkIHB1bGwgYW4gaW1hZ2UgZnJvbSBpbWFnZXRhZ1wiLGZ1bmN0aW9uKGRvbmUpe1xuICAgICAgICAgICAgdGhpcy50aW1lb3V0KDMwMDAwKTtcbiAgICAgICAgICAgIHRlc3REb2NrZXJzb2NrLnB1bGxJbWFnZShcImhvc3R0b2RheSUyRmh0LWRvY2tlci1kYmFzZVwiKVxuICAgICAgICAgICAgICAgIC50aGVuKChkYXRhQXJnKT0+e1xuICAgICAgICAgICAgICAgICAgICBkb25lKCk7XG4gICAgICAgICAgICAgICAgfSxkb25lKTtcbiAgICAgICAgfSlcbiAgICB9KTtcbn0pOyJdfQ==
|
|
151
test/test.ts
151
test/test.ts
@ -1,36 +1,119 @@
|
|||||||
import "typings-test";
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import "should"
|
import * as docker from '../ts/index';
|
||||||
|
|
||||||
import {Dockersock} from "../dist/index"
|
let testDockerHost: docker.DockerHost;
|
||||||
|
|
||||||
describe("dockersock",function(){
|
if (process.env.CI) {
|
||||||
describe(".Dockersock()",function(){
|
tap.test('ci placeholder', async () => {});
|
||||||
let testDockersock:Dockersock;
|
tap.start();
|
||||||
it("should create a new Dockersock instance",function(){
|
process.exit(0);
|
||||||
testDockersock = new Dockersock();
|
}
|
||||||
testDockersock.should.be.instanceof(Dockersock);
|
|
||||||
});
|
tap.test('should create a new Dockersock instance', async () => {
|
||||||
it("should list containers",function(done){
|
testDockerHost = new docker.DockerHost('http://unix:/var/run/docker.sock:');
|
||||||
testDockersock.listContainers()
|
return expect(testDockerHost).to.be.instanceof(docker.DockerHost);
|
||||||
.then((dataArg)=>{
|
});
|
||||||
console.log(dataArg);
|
|
||||||
done();
|
tap.test('should create a docker swarm', async () => {
|
||||||
});
|
await testDockerHost.activateSwarm();
|
||||||
});
|
});
|
||||||
it("should list detailed containers",function(done){
|
|
||||||
this.timeout(5000);
|
// Containers
|
||||||
testDockersock.listContainersDetailed()
|
tap.test('should list containers', async () => {
|
||||||
.then((dataArg)=>{
|
const containers = await testDockerHost.getContainers();
|
||||||
console.log(dataArg);
|
console.log(containers);
|
||||||
done();
|
});
|
||||||
});
|
|
||||||
});
|
// Networks
|
||||||
it("should pull an image from imagetag",function(done){
|
tap.test('should list networks', async () => {
|
||||||
this.timeout(30000);
|
const networks = await testDockerHost.getNetworks();
|
||||||
testDockersock.pullImage("hosttoday%2Fht-docker-dbase")
|
console.log(networks);
|
||||||
.then((dataArg)=>{
|
});
|
||||||
done();
|
|
||||||
},done);
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
// SECRETS
|
||||||
|
tap.test('should create a secret', async () => {
|
||||||
|
const mySecret = await docker.DockerSecret.createSecret(testDockerHost, {
|
||||||
|
name: 'testSecret',
|
||||||
|
version: '1.0.3',
|
||||||
|
contentArg: `{ "hi": "wow"}`,
|
||||||
|
labels: {},
|
||||||
|
});
|
||||||
|
console.log(mySecret);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should remove a secret by name', async () => {
|
||||||
|
const mySecret = await docker.DockerSecret.getSecretByName(testDockerHost, 'testSecret');
|
||||||
|
await mySecret.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
// SERVICES
|
||||||
|
tap.test('should activate swarm mode', async () => {
|
||||||
|
await testDockerHost.activateSwarm();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should list all services', async (tools) => {
|
||||||
|
const services = await testDockerHost.getServices();
|
||||||
|
console.log(services);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should create a service', async () => {
|
||||||
|
const testNetwork = await docker.DockerNetwork.createNetwork(testDockerHost, {
|
||||||
|
Name: 'testNetwork',
|
||||||
|
});
|
||||||
|
const testSecret = await docker.DockerSecret.createSecret(testDockerHost, {
|
||||||
|
name: 'testSecret',
|
||||||
|
version: '0.0.1',
|
||||||
|
labels: {},
|
||||||
|
contentArg: '{"hi": "wow"}',
|
||||||
|
});
|
||||||
|
const testImage = await docker.DockerImage.createFromRegistry(testDockerHost, {
|
||||||
|
imageUrl: 'registry.gitlab.com/hosttoday/ht-docker-static',
|
||||||
|
});
|
||||||
|
const testService = await docker.DockerService.createService(testDockerHost, {
|
||||||
|
image: testImage,
|
||||||
|
labels: {},
|
||||||
|
name: 'testService',
|
||||||
|
networks: [testNetwork],
|
||||||
|
networkAlias: 'testService',
|
||||||
|
secrets: [testSecret],
|
||||||
|
ports: ['3000:80'],
|
||||||
|
});
|
||||||
|
|
||||||
|
await testService.remove();
|
||||||
|
await testNetwork.remove();
|
||||||
|
await testSecret.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
docker build -t dockersock-image .
|
|
||||||
docker-compose up
|
|
99
ts/docker.classes.container.ts
Normal file
99
ts/docker.classes.container.ts
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
import { logger } from './docker.logging';
|
||||||
|
|
||||||
|
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) {
|
||||||
|
logger.log('info', 'Container created successfully');
|
||||||
|
} else {
|
||||||
|
logger.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];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
189
ts/docker.classes.host.ts
Normal file
189
ts/docker.classes.host.ts
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import { DockerContainer } from './docker.classes.container';
|
||||||
|
import { DockerNetwork } from './docker.classes.network';
|
||||||
|
import { DockerService } from './docker.classes.service';
|
||||||
|
import { logger } from './docker.logging';
|
||||||
|
|
||||||
|
export interface IAuthData {
|
||||||
|
serveraddress: string;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DockerHost {
|
||||||
|
/**
|
||||||
|
* the path where the docker sock can be found
|
||||||
|
*/
|
||||||
|
public socketPath: string;
|
||||||
|
private registryToken: string = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the constructor to instantiate a new docker sock instance
|
||||||
|
* @param pathArg
|
||||||
|
*/
|
||||||
|
constructor(pathArg?: string) {
|
||||||
|
let pathToUse: string;
|
||||||
|
if (pathArg) {
|
||||||
|
pathToUse = pathArg;
|
||||||
|
} else if (process.env.CI) {
|
||||||
|
pathToUse = 'http://docker:2375/';
|
||||||
|
} else {
|
||||||
|
pathToUse = 'http://unix:/var/run/docker.sock:';
|
||||||
|
}
|
||||||
|
this.socketPath = pathToUse;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* authenticate against a registry
|
||||||
|
* @param userArg
|
||||||
|
* @param passArg
|
||||||
|
*/
|
||||||
|
public async auth(authData: IAuthData) {
|
||||||
|
const response = await this.request('POST', '/auth', authData);
|
||||||
|
if (response.body.Status !== 'Login Succeeded') {
|
||||||
|
console.log(`Login failed with ${response.body.Status}`);
|
||||||
|
throw new Error(response.body.Status);
|
||||||
|
}
|
||||||
|
console.log(response.body.Status);
|
||||||
|
this.registryToken = plugins.smartstring.base64.encode(
|
||||||
|
plugins.smartjson.Smartjson.stringify(authData, {})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the token from the .docker/config.json file for GitLab registry
|
||||||
|
*/
|
||||||
|
public async getGitlabComTokenFromDockerConfig() {
|
||||||
|
const dockerConfigPath = plugins.smartpath.get.home('~/.docker/config.json');
|
||||||
|
const configObject = plugins.smartfile.fs.toObjectSync(dockerConfigPath);
|
||||||
|
const gitlabAuthBase64 = configObject.auths['registry.gitlab.com'].auth;
|
||||||
|
const gitlabAuth: string = plugins.smartstring.base64.decode(gitlabAuthBase64);
|
||||||
|
const gitlabAuthArray = gitlabAuth.split(':');
|
||||||
|
await this.auth({
|
||||||
|
username: gitlabAuthArray[0],
|
||||||
|
password: gitlabAuthArray[1],
|
||||||
|
serveraddress: 'registry.gitlab.com',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets all services
|
||||||
|
*/
|
||||||
|
public async getServices() {
|
||||||
|
const serviceArray = await DockerService.getServices(this);
|
||||||
|
return serviceArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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) {
|
||||||
|
// determine advertisement address
|
||||||
|
let addvertisementIp: string;
|
||||||
|
if (addvertisementIpArg) {
|
||||||
|
addvertisementIp = addvertisementIpArg;
|
||||||
|
} else {
|
||||||
|
const smartnetworkInstance = new plugins.smartnetwork.SmartNetwork();
|
||||||
|
const defaultGateway = await smartnetworkInstance.getDefaultGateway();
|
||||||
|
if (defaultGateway) {
|
||||||
|
addvertisementIp = defaultGateway.ipv4.address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await this.request('POST', '/swarm/init', {
|
||||||
|
ListenAddr: '0.0.0.0:2377',
|
||||||
|
AdvertiseAddr: addvertisementIp,
|
||||||
|
DataPathPort: 4789,
|
||||||
|
DefaultAddrPool: ['10.10.0.0/8', '20.20.0.0/8'],
|
||||||
|
SubnetSize: 24,
|
||||||
|
ForceNewCluster: false,
|
||||||
|
});
|
||||||
|
if (response.statusCode === 200) {
|
||||||
|
logger.log('info', 'created Swam succesfully');
|
||||||
|
} else {
|
||||||
|
logger.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',
|
||||||
|
'X-Registry-Auth': this.registryToken,
|
||||||
|
Host: 'docker.sock',
|
||||||
|
},
|
||||||
|
requestBody: dataArg,
|
||||||
|
keepAlive: false,
|
||||||
|
});
|
||||||
|
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',
|
||||||
|
'X-Registry-Auth': this.registryToken,
|
||||||
|
Host: 'docker.sock',
|
||||||
|
},
|
||||||
|
requestBody: null,
|
||||||
|
keepAlive: false,
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
console.log(response.statusCode);
|
||||||
|
console.log(response.body);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
144
ts/docker.classes.image.ts
Normal file
144
ts/docker.classes.image.ts
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
import { logger } from './docker.logging';
|
||||||
|
|
||||||
|
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);
|
||||||
|
const result = images.find((image) => {
|
||||||
|
if (image.RepoTags) {
|
||||||
|
return image.RepoTags.includes(imageNameArg);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.imageUrl = imageUrl;
|
||||||
|
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) {
|
||||||
|
logger.log('info', `Successfully pulled image ${imageUrlObject.imageUrl} from the registry`);
|
||||||
|
const image = await DockerImage.findImageByName(dockerHostArg, imageUrlObject.imageOriginTag);
|
||||||
|
return image;
|
||||||
|
} else {
|
||||||
|
logger.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];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tag an image
|
||||||
|
* @param newTag
|
||||||
|
*/
|
||||||
|
public async tagImage(newTag) {
|
||||||
|
throw new Error('.tagImage is not yet implemented');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get stuff
|
||||||
|
public async getVersion() {
|
||||||
|
if (this.Labels && this.Labels.version) {
|
||||||
|
return this.Labels.version;
|
||||||
|
} else {
|
||||||
|
return '0.0.0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
118
ts/docker.classes.network.ts
Normal file
118
ts/docker.classes.network.ts
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
import { DockerService } from './docker.classes.service';
|
||||||
|
import { logger } from './docker.logging';
|
||||||
|
|
||||||
|
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) {
|
||||||
|
const dockerNetwork = new DockerNetwork(dockerHost);
|
||||||
|
Object.assign(dockerNetwork, networkObject);
|
||||||
|
dockerNetworks.push(dockerNetwork);
|
||||||
|
}
|
||||||
|
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.${networkCreationDescriptor.NetworkNumber}.0/16`,
|
||||||
|
IPRange: `172.20.${networkCreationDescriptor.NetworkNumber}.0/24`,
|
||||||
|
Gateway: `172.20.${networkCreationDescriptor.NetworkNumber}.11`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, */
|
||||||
|
Internal: false,
|
||||||
|
Attachable: true,
|
||||||
|
Ingress: false,
|
||||||
|
});
|
||||||
|
if (response.statusCode < 300) {
|
||||||
|
logger.log('info', 'Created network successfully');
|
||||||
|
return await DockerNetwork.getNetworkByName(dockerHost, networkCreationDescriptor.Name);
|
||||||
|
} else {
|
||||||
|
logger.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) {
|
||||||
|
this.dockerHost = dockerHostArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes the network
|
||||||
|
*/
|
||||||
|
public async remove() {
|
||||||
|
const response = await this.dockerHost.request('DELETE', `/networks/${this.Id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getContainersOnNetwork(): Promise<
|
||||||
|
Array<{
|
||||||
|
Name: string;
|
||||||
|
EndpointID: string;
|
||||||
|
MacAddress: string;
|
||||||
|
IPv4Address: string;
|
||||||
|
IPv6Address: string;
|
||||||
|
}>
|
||||||
|
> {
|
||||||
|
const returnArray = [];
|
||||||
|
const response = await this.dockerHost.request('GET', `/networks/${this.Id}`);
|
||||||
|
for (const key of Object.keys(response.body.Containers)) {
|
||||||
|
returnArray.push(response.body.Containers[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getContainersOnNetworkForService(serviceArg: DockerService) {
|
||||||
|
const containersOnNetwork = await this.getContainersOnNetwork();
|
||||||
|
const containersOfService = containersOnNetwork.filter((container) => {
|
||||||
|
return container.Name.startsWith(serviceArg.Spec.Name);
|
||||||
|
});
|
||||||
|
return containersOfService;
|
||||||
|
}
|
||||||
|
}
|
92
ts/docker.classes.secret.ts
Normal file
92
ts/docker.classes.secret.ts
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
|
||||||
|
// interfaces
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
export class DockerSecret {
|
||||||
|
// STATIC
|
||||||
|
public static async getSecrets(dockerHostArg: DockerHost) {
|
||||||
|
const response = await dockerHostArg.request('GET', '/secrets');
|
||||||
|
const secrets: DockerSecret[] = [];
|
||||||
|
for (const secret of response.body) {
|
||||||
|
const dockerSecretInstance = new DockerSecret(dockerHostArg);
|
||||||
|
Object.assign(dockerSecretInstance, secret);
|
||||||
|
secrets.push(dockerSecretInstance);
|
||||||
|
}
|
||||||
|
return secrets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getSecretByID(dockerHostArg: DockerHost, idArg: string) {
|
||||||
|
const secrets = await this.getSecrets(dockerHostArg);
|
||||||
|
return secrets.find((secret) => secret.ID === idArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getSecretByName(dockerHostArg: DockerHost, nameArg: string) {
|
||||||
|
const secrets = await this.getSecrets(dockerHostArg);
|
||||||
|
return secrets.find((secret) => secret.Spec.Name === nameArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async createSecret(
|
||||||
|
dockerHostArg: DockerHost,
|
||||||
|
secretDescriptor: interfaces.ISecretCreationDescriptor
|
||||||
|
) {
|
||||||
|
const labels: interfaces.TLabels = {
|
||||||
|
...secretDescriptor.labels,
|
||||||
|
version: secretDescriptor.version,
|
||||||
|
};
|
||||||
|
const response = await dockerHostArg.request('POST', '/secrets/create', {
|
||||||
|
Name: secretDescriptor.name,
|
||||||
|
Labels: labels,
|
||||||
|
Data: plugins.smartstring.base64.encode(secretDescriptor.contentArg),
|
||||||
|
});
|
||||||
|
|
||||||
|
const newSecretInstance = new DockerSecret(dockerHostArg);
|
||||||
|
Object.assign(newSecretInstance, response.body);
|
||||||
|
Object.assign(
|
||||||
|
newSecretInstance,
|
||||||
|
await DockerSecret.getSecretByID(dockerHostArg, newSecretInstance.ID)
|
||||||
|
);
|
||||||
|
return newSecretInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
|
public ID: string;
|
||||||
|
public Spec: {
|
||||||
|
Name: string;
|
||||||
|
Labels: interfaces.TLabels;
|
||||||
|
};
|
||||||
|
public Version: {
|
||||||
|
Index: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
public dockerHost: DockerHost;
|
||||||
|
constructor(dockerHostArg: DockerHost) {
|
||||||
|
this.dockerHost = dockerHostArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates a secret
|
||||||
|
*/
|
||||||
|
public async update(contentArg: string) {
|
||||||
|
const route = `/secrets/${this.ID}/update?=version=${this.Version.Index}`;
|
||||||
|
const response = await this.dockerHost.request(
|
||||||
|
'POST',
|
||||||
|
`/secrets/${this.ID}/update?version=${this.Version.Index}`,
|
||||||
|
{
|
||||||
|
Name: this.Spec.Name,
|
||||||
|
Labels: this.Spec.Labels,
|
||||||
|
Data: plugins.smartstring.base64.encode(contentArg),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async remove() {
|
||||||
|
await this.dockerHost.request('DELETE', `/secrets/${this.ID}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get things
|
||||||
|
public async getVersion() {
|
||||||
|
return this.Spec.Labels.version;
|
||||||
|
}
|
||||||
|
}
|
247
ts/docker.classes.service.ts
Normal file
247
ts/docker.classes.service.ts
Normal file
@ -0,0 +1,247 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
import { DockerImage } from './docker.classes.image';
|
||||||
|
import { DockerSecret } from './docker.classes.secret';
|
||||||
|
import { logger } from './docker.logging';
|
||||||
|
|
||||||
|
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) {
|
||||||
|
const dockerService = new DockerService(dockerHost);
|
||||||
|
Object.assign(dockerService, serviceObject);
|
||||||
|
services.push(dockerService);
|
||||||
|
}
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getServiceByName(
|
||||||
|
dockerHost: DockerHost,
|
||||||
|
networkName: string
|
||||||
|
): Promise<DockerService> {
|
||||||
|
const allServices = await DockerService.getServices(dockerHost);
|
||||||
|
const wantedService = allServices.find((service) => {
|
||||||
|
return service.Spec.Name === networkName;
|
||||||
|
});
|
||||||
|
return wantedService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a service
|
||||||
|
*/
|
||||||
|
public static async createService(
|
||||||
|
dockerHost: DockerHost,
|
||||||
|
serviceCreationDescriptor: interfaces.IServiceCreationDescriptor
|
||||||
|
): Promise<DockerService> {
|
||||||
|
// lets get the image
|
||||||
|
logger.log('info', `now creating service ${serviceCreationDescriptor.name}`);
|
||||||
|
|
||||||
|
// await serviceCreationDescriptor.image.pullLatestImageFromRegistry();
|
||||||
|
const serviceVersion = await serviceCreationDescriptor.image.getVersion();
|
||||||
|
|
||||||
|
const labels: interfaces.TLabels = {
|
||||||
|
...serviceCreationDescriptor.labels,
|
||||||
|
version: serviceVersion,
|
||||||
|
};
|
||||||
|
|
||||||
|
const mounts: Array<{
|
||||||
|
/**
|
||||||
|
* the target inside the container
|
||||||
|
*/
|
||||||
|
Target: string;
|
||||||
|
/**
|
||||||
|
* The Source from which to mount the data (Volume or host path)
|
||||||
|
*/
|
||||||
|
Source: string;
|
||||||
|
Type: 'bind' | 'volume' | 'tmpfs' | 'npipe';
|
||||||
|
ReadOnly: boolean;
|
||||||
|
Consistency: 'default' | 'consistent' | 'cached' | 'delegated';
|
||||||
|
}> = [];
|
||||||
|
if (serviceCreationDescriptor.accessHostDockerSock) {
|
||||||
|
mounts.push({
|
||||||
|
Target: '/var/run/docker.sock',
|
||||||
|
Source: '/var/run/docker.sock',
|
||||||
|
Consistency: 'default',
|
||||||
|
ReadOnly: false,
|
||||||
|
Type: 'bind',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serviceCreationDescriptor.resources && serviceCreationDescriptor.resources.volumeMounts) {
|
||||||
|
for (const volumeMount of serviceCreationDescriptor.resources.volumeMounts) {
|
||||||
|
mounts.push({
|
||||||
|
Target: volumeMount.containerFsPath,
|
||||||
|
Source: volumeMount.hostFsPath,
|
||||||
|
Consistency: 'default',
|
||||||
|
ReadOnly: false,
|
||||||
|
Type: 'bind',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const networkArray: Array<{
|
||||||
|
Target: string;
|
||||||
|
Aliases: string[];
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
for (const network of serviceCreationDescriptor.networks) {
|
||||||
|
networkArray.push({
|
||||||
|
Target: network.Name,
|
||||||
|
Aliases: [serviceCreationDescriptor.networkAlias],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const ports = [];
|
||||||
|
for (const port of serviceCreationDescriptor.ports) {
|
||||||
|
const portArray = port.split(':');
|
||||||
|
const hostPort = portArray[0];
|
||||||
|
const containerPort = portArray[1];
|
||||||
|
ports.push({
|
||||||
|
Protocol: 'tcp',
|
||||||
|
PublishedPort: parseInt(hostPort, 10),
|
||||||
|
TargetPort: parseInt(containerPort, 10),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// lets configure secrets
|
||||||
|
const secretArray: any[] = [];
|
||||||
|
for (const secret of serviceCreationDescriptor.secrets) {
|
||||||
|
secretArray.push({
|
||||||
|
File: {
|
||||||
|
Name: 'secret.json', // TODO: make sure that works with multiple secrets
|
||||||
|
UID: '33',
|
||||||
|
GID: '33',
|
||||||
|
Mode: 384,
|
||||||
|
},
|
||||||
|
SecretID: secret.ID,
|
||||||
|
SecretName: secret.Spec.Name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// lets configure limits
|
||||||
|
|
||||||
|
const memoryLimitMB =
|
||||||
|
serviceCreationDescriptor.resources && serviceCreationDescriptor.resources.memorySizeMB
|
||||||
|
? serviceCreationDescriptor.resources.memorySizeMB
|
||||||
|
: 1000;
|
||||||
|
|
||||||
|
const limits = {
|
||||||
|
MemoryBytes: memoryLimitMB * 1000000,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (serviceCreationDescriptor.resources) {
|
||||||
|
limits.MemoryBytes = serviceCreationDescriptor.resources.memorySizeMB * 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await dockerHost.request('POST', '/services/create', {
|
||||||
|
Name: serviceCreationDescriptor.name,
|
||||||
|
TaskTemplate: {
|
||||||
|
ContainerSpec: {
|
||||||
|
Image: serviceCreationDescriptor.image.RepoTags[0],
|
||||||
|
Labels: labels,
|
||||||
|
Secrets: secretArray,
|
||||||
|
Mounts: mounts,
|
||||||
|
/* DNSConfig: {
|
||||||
|
Nameservers: ['1.1.1.1']
|
||||||
|
} */
|
||||||
|
},
|
||||||
|
UpdateConfig: {
|
||||||
|
Parallelism: 0,
|
||||||
|
Delay: 0,
|
||||||
|
FailureAction: 'pause',
|
||||||
|
Monitor: 15000000000,
|
||||||
|
MaxFailureRatio: 0.15,
|
||||||
|
},
|
||||||
|
ForceUpdate: 1,
|
||||||
|
Resources: {
|
||||||
|
Limits: limits,
|
||||||
|
},
|
||||||
|
LogDriver: {
|
||||||
|
Name: 'json-file',
|
||||||
|
Options: {
|
||||||
|
'max-file': '3',
|
||||||
|
'max-size': '10M',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Labels: labels,
|
||||||
|
Networks: networkArray,
|
||||||
|
EndpointSpec: {
|
||||||
|
Ports: ports,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const createdService = await DockerService.getServiceByName(
|
||||||
|
dockerHost,
|
||||||
|
serviceCreationDescriptor.name
|
||||||
|
);
|
||||||
|
return createdService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
|
public dockerHostRef: DockerHost;
|
||||||
|
|
||||||
|
public ID: string;
|
||||||
|
public Version: { Index: number };
|
||||||
|
public CreatedAt: string;
|
||||||
|
public UpdatedAt: string;
|
||||||
|
public Spec: {
|
||||||
|
Name: string;
|
||||||
|
Labels: interfaces.TLabels;
|
||||||
|
TaskTemplate: {
|
||||||
|
ContainerSpec: {
|
||||||
|
Image: string;
|
||||||
|
Isolation: string;
|
||||||
|
Secrets: Array<{
|
||||||
|
File: {
|
||||||
|
Name: string;
|
||||||
|
UID: string;
|
||||||
|
GID: string;
|
||||||
|
Mode: number;
|
||||||
|
};
|
||||||
|
SecretID: string;
|
||||||
|
SecretName: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
ForceUpdate: 0;
|
||||||
|
};
|
||||||
|
Mode: {};
|
||||||
|
Networks: [any[]];
|
||||||
|
};
|
||||||
|
public Endpoint: { Spec: {}; VirtualIPs: [any[]] };
|
||||||
|
|
||||||
|
constructor(dockerHostArg: DockerHost) {
|
||||||
|
this.dockerHostRef = dockerHostArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async remove() {
|
||||||
|
await this.dockerHostRef.request('DELETE', `/services/${this.ID}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async reReadFromDockerEngine() {
|
||||||
|
const dockerData = await this.dockerHostRef.request('GET', `/services/${this.ID}`);
|
||||||
|
// TODO: Better assign: Object.assign(this, dockerData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async needsUpdate(): Promise<boolean> {
|
||||||
|
// TODO: implement digest based update recognition
|
||||||
|
|
||||||
|
await this.reReadFromDockerEngine();
|
||||||
|
const dockerImage = await DockerImage.createFromRegistry(this.dockerHostRef, {
|
||||||
|
imageUrl: this.Spec.TaskTemplate.ContainerSpec.Image,
|
||||||
|
});
|
||||||
|
|
||||||
|
const imageVersion = new plugins.smartversion.SmartVersion(dockerImage.Labels.version);
|
||||||
|
const serviceVersion = new plugins.smartversion.SmartVersion(this.Spec.Labels.version);
|
||||||
|
if (imageVersion.greaterThan(serviceVersion)) {
|
||||||
|
console.log(`service ${this.Spec.Name} needs to be updated`);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
console.log(`service ${this.Spec.Name} is up to date.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
ts/docker.logging.ts
Normal file
3
ts/docker.logging.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import * as plugins from './docker.plugins';
|
||||||
|
|
||||||
|
export const logger = new plugins.smartlog.ConsoleLog();
|
39
ts/docker.plugins.ts
Normal file
39
ts/docker.plugins.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// node native path
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
export { path };
|
||||||
|
|
||||||
|
// @pushrocks scope
|
||||||
|
import * as lik from '@pushrocks/lik';
|
||||||
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
|
import * as smartjson from '@pushrocks/smartjson';
|
||||||
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
|
import * as smartnetwork from '@pushrocks/smartnetwork';
|
||||||
|
import * as smartpath from '@pushrocks/smartpath';
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
import * as smartstring from '@pushrocks/smartstring';
|
||||||
|
import * as smartversion from '@pushrocks/smartversion';
|
||||||
|
|
||||||
|
export {
|
||||||
|
lik,
|
||||||
|
smartfile,
|
||||||
|
smartjson,
|
||||||
|
smartlog,
|
||||||
|
smartnetwork,
|
||||||
|
smartpath,
|
||||||
|
smartpromise,
|
||||||
|
smartrequest,
|
||||||
|
smartstring,
|
||||||
|
smartversion,
|
||||||
|
};
|
||||||
|
|
||||||
|
// @tsclass scope
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
export { tsclass };
|
||||||
|
|
||||||
|
// third party
|
||||||
|
import * as rxjs from 'rxjs';
|
||||||
|
|
||||||
|
export { rxjs };
|
@ -1,168 +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(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;
|
|
||||||
};
|
|
||||||
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,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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
import "typings-global";
|
|
||||||
export import beautylog = require("beautylog");
|
|
||||||
export let q = require("q");
|
|
||||||
export let request = require("request");
|
|
@ -1,2 +1,6 @@
|
|||||||
import "typings-global";
|
export * from './docker.classes.host';
|
||||||
export {Dockersock} from "./dockersock.classes.dockersock"
|
export * from './docker.classes.container';
|
||||||
|
export * from './docker.classes.image';
|
||||||
|
export * from './docker.classes.network';
|
||||||
|
export * from './docker.classes.secret';
|
||||||
|
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;
|
||||||
|
}
|
7
ts/interfaces/index.ts
Normal file
7
ts/interfaces/index.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export * from './container';
|
||||||
|
export * from './image';
|
||||||
|
export * from './label';
|
||||||
|
export * from './network';
|
||||||
|
export * from './port';
|
||||||
|
export * from './secret';
|
||||||
|
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[];
|
8
ts/interfaces/secret.ts
Normal file
8
ts/interfaces/secret.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import * as interfaces from './';
|
||||||
|
|
||||||
|
export interface ISecretCreationDescriptor {
|
||||||
|
name: string;
|
||||||
|
version: string;
|
||||||
|
contentArg: any;
|
||||||
|
labels: interfaces.TLabels;
|
||||||
|
}
|
21
ts/interfaces/service.ts
Normal file
21
ts/interfaces/service.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import * as plugins from '../docker.plugins';
|
||||||
|
|
||||||
|
import * as interfaces from './';
|
||||||
|
import { DockerNetwork } from '../docker.classes.network';
|
||||||
|
import { DockerSecret } from '../docker.classes.secret';
|
||||||
|
import { DockerImage } from '../docker.classes.image';
|
||||||
|
|
||||||
|
export interface IServiceCreationDescriptor {
|
||||||
|
name: string;
|
||||||
|
image: DockerImage;
|
||||||
|
labels: interfaces.TLabels;
|
||||||
|
networks: DockerNetwork[];
|
||||||
|
networkAlias: string;
|
||||||
|
secrets: DockerSecret[];
|
||||||
|
ports: string[];
|
||||||
|
accessHostDockerSock?: boolean;
|
||||||
|
resources?: {
|
||||||
|
memorySizeMB?: number;
|
||||||
|
volumeMounts?: plugins.tsclass.container.IVolumeMount[];
|
||||||
|
};
|
||||||
|
}
|
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