Compare commits
92 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
7049ddc5f2 | |||
2b6088b1d7 | |||
880655b4e2 |
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,3 +1,22 @@
|
||||
docs/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
|
||||
# custom
|
132
.gitlab-ci.yml
132
.gitlab-ci.yml
@ -1,55 +1,119 @@
|
||||
image: hosttoday/ht-docker-dbase
|
||||
services:
|
||||
- docker:dind
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npmci prepare docker-gitlab
|
||||
|
||||
|
||||
build:
|
||||
stage: build
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npm install
|
||||
- npm test
|
||||
- npmci build docker
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- lossless
|
||||
- priv
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
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
|
||||
script:
|
||||
- npmci test docker
|
||||
only:
|
||||
- master
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- priv
|
||||
- docker
|
||||
- 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:
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish npm
|
||||
- npmci node install lts
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- priv
|
||||
- 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
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- master
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- priv
|
||||
- docker
|
||||
- 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
|
||||
|
@ -1,3 +0,0 @@
|
||||
FROM hosttoday/ht-docker-node:lts
|
||||
COPY ./node_modules /app-node/node_modules
|
||||
COPY ./dist /app-node/dist
|
53
README.md
53
README.md
@ -1,28 +1,41 @@
|
||||
# dockersock
|
||||
easy communication with docker from node, TypeScript ready
|
||||
# @mojoio/docker
|
||||
|
||||
## Status
|
||||
[](https://gitlab.com/pushrocks/dockersock/commits/master)
|
||||
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
|
||||
|
||||
[](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
|
||||
We recommend the use of TypeScript for best Intellisense.
|
||||
|
||||
```TypeScript
|
||||
import {Dockersock} from "dockersock"; // require Dockersock class
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
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
|
||||
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"
|
||||
})
|
||||
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
|
||||
};
|
||||
```
|
||||
|
||||
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)
|
||||
|
6
dist/dockersock.class.dockersock.d.ts
vendored
6
dist/dockersock.class.dockersock.d.ts
vendored
@ -1,6 +0,0 @@
|
||||
import "typings-global";
|
||||
export declare class dockersock {
|
||||
sockPath: string;
|
||||
constructor(pathArg: string);
|
||||
request(methodArg: string, routeArg: string, dataArg?: {}): any;
|
||||
}
|
38
dist/dockersock.class.dockersock.js
vendored
38
dist/dockersock.class.dockersock.js
vendored
@ -1,38 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
var plugins = require("./dockersock.plugins");
|
||||
var dockersock = (function () {
|
||||
function dockersock(pathArg) {
|
||||
this.sockPath = pathArg;
|
||||
}
|
||||
dockersock.prototype.request = function (methodArg, routeArg, dataArg) {
|
||||
if (dataArg === void 0) { dataArg = {}; }
|
||||
var done = plugins.q.defer();
|
||||
var jsonArg = JSON.stringify(dataArg);
|
||||
var options = {
|
||||
method: methodArg,
|
||||
url: "http://unix:/var/run/docker.sock:" + 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;
|
||||
};
|
||||
return dockersock;
|
||||
}());
|
||||
exports.dockersock = dockersock;
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRvY2tlcnNvY2suY2xhc3MuZG9ja2Vyc29jay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBQ3ZCLElBQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFFaEQ7SUFFSSxvQkFBWSxPQUFjO1FBQ3RCLElBQUksQ0FBQyxRQUFRLEdBQUcsT0FBTyxDQUFDO0lBQzVCLENBQUM7SUFFRCw0QkFBTyxHQUFQLFVBQVEsU0FBZ0IsRUFBQyxRQUFlLEVBQUMsT0FBWTtRQUFaLHVCQUFZLEdBQVosWUFBWTtRQUNqRCxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQzdCLElBQUksT0FBTyxHQUFVLElBQUksQ0FBQyxTQUFTLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDN0MsSUFBSSxPQUFPLEdBQUc7WUFDVixNQUFNLEVBQUMsU0FBUztZQUNoQixHQUFHLEVBQUMsbUNBQW1DLEdBQUcsUUFBUSxHQUFHLE9BQU87WUFDNUQsT0FBTyxFQUFDO2dCQUNKLGNBQWMsRUFBQyxrQkFBa0I7YUFDcEM7WUFDRCxJQUFJLEVBQUMsT0FBTztTQUNmLENBQUM7UUFDRixPQUFPLENBQUMsT0FBTyxDQUFDLE9BQU8sRUFBQyxVQUFTLEdBQUcsRUFBRSxHQUFHLEVBQUUsSUFBSTtZQUMzQyxFQUFFLENBQUMsQ0FBQyxDQUFDLEdBQUcsSUFBSSxHQUFHLENBQUMsVUFBVSxJQUFJLEdBQUcsQ0FBQyxDQUFDLENBQUM7Z0JBQ2hDLElBQUksV0FBVyxHQUFHLElBQUksQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLENBQUM7Z0JBQ25DLElBQUksQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7WUFDOUIsQ0FBQztZQUFDLElBQUksQ0FBQyxDQUFDO2dCQUNKLE9BQU8sQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUM7Z0JBQ2pCLE9BQU8sQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUM7Z0JBQ2pCLElBQUksQ0FBQyxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUM7WUFDckIsQ0FBQztZQUFBLENBQUM7UUFDTixDQUFDLENBQUMsQ0FBQztRQUNILE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0lBQ3hCLENBQUM7SUFDTCxpQkFBQztBQUFELENBN0JBLEFBNkJDLElBQUE7QUE3Qlksa0JBQVUsYUE2QnRCLENBQUEiLCJmaWxlIjoiZG9ja2Vyc29jay5jbGFzcy5kb2NrZXJzb2NrLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIlxuaW1wb3J0ICogYXMgcGx1Z2lucyBmcm9tIFwiLi9kb2NrZXJzb2NrLnBsdWdpbnNcIjtcblxuZXhwb3J0IGNsYXNzIGRvY2tlcnNvY2sge1xuICAgIHNvY2tQYXRoOnN0cmluZztcbiAgICBjb25zdHJ1Y3RvcihwYXRoQXJnOnN0cmluZyl7XG4gICAgICAgIHRoaXMuc29ja1BhdGggPSBwYXRoQXJnO1xuICAgIH1cbiAgICBcbiAgICByZXF1ZXN0KG1ldGhvZEFyZzpzdHJpbmcscm91dGVBcmc6c3RyaW5nLGRhdGFBcmcgPSB7fSl7XG4gICAgICAgIGxldCBkb25lID0gcGx1Z2lucy5xLmRlZmVyKCk7XG4gICAgICAgIGxldCBqc29uQXJnOnN0cmluZyA9IEpTT04uc3RyaW5naWZ5KGRhdGFBcmcpO1xuICAgICAgICBsZXQgb3B0aW9ucyA9IHtcbiAgICAgICAgICAgIG1ldGhvZDptZXRob2RBcmcsXG4gICAgICAgICAgICB1cmw6XCJodHRwOi8vdW5peDovdmFyL3J1bi9kb2NrZXIuc29jazpcIiArIHJvdXRlQXJnICsgXCIvanNvblwiLFxuICAgICAgICAgICAgaGVhZGVyczp7XG4gICAgICAgICAgICAgICAgXCJDb250ZW50LVR5cGVcIjpcImFwcGxpY2F0aW9uL2pzb25cIlxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGJvZHk6anNvbkFyZ1xuICAgICAgICB9O1xuICAgICAgICBwbHVnaW5zLnJlcXVlc3Qob3B0aW9ucyxmdW5jdGlvbihlcnIsIHJlcywgYm9keSl7XG4gICAgICAgICAgICBpZiAoIWVyciAmJiByZXMuc3RhdHVzQ29kZSA9PSAyMDApIHtcbiAgICAgICAgICAgICAgICB2YXIgcmVzcG9uc2VPYmogPSBKU09OLnBhcnNlKGJvZHkpO1xuICAgICAgICAgICAgICAgIGRvbmUucmVzb2x2ZShyZXNwb25zZU9iaik7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycik7XG4gICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzKTtcbiAgICAgICAgICAgICAgICBkb25lLnJlamVjdChlcnIpO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgfSk7XG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XG4gICAgfVxufSJdfQ==
|
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",
|
||||
"version": "1.0.1",
|
||||
"description": "easy communication with docker from node, TypeScript ready",
|
||||
"name": "@mojoio/docker",
|
||||
"version": "1.0.36",
|
||||
"description": "easy communication with docker remote api from node, TypeScript ready",
|
||||
"private": false,
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "npmts",
|
||||
"testindocker": "npmts && docker-machine start default; eval \"$(docker-machine env default)\" && docker build -t test-image . && docker run test-image"
|
||||
"test": "tstest test/",
|
||||
"build": "tsbuild"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -25,12 +27,30 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
|
||||
"dependencies": {
|
||||
"beautylog": "^5.0.10",
|
||||
"q": "^1.4.1",
|
||||
"request": "^2.72.0",
|
||||
"typings-global": "^1.0.3"
|
||||
"@pushrocks/lik": "^3.0.10",
|
||||
"@pushrocks/smartlog": "^2.0.19",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@pushrocks/smartrequest": "^1.1.16",
|
||||
"rxjs": "^6.5.2"
|
||||
},
|
||||
"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"
|
||||
]
|
||||
}
|
||||
|
29
test/test.ts
Normal file
29
test/test.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import { DockerHost } from '../ts/index';
|
||||
|
||||
let testDockerHost: DockerHost;
|
||||
|
||||
tap.test('should create a new Dockersock instance', async () => {
|
||||
testDockerHost = new DockerHost();
|
||||
return expect(testDockerHost).to.be.instanceof(DockerHost);
|
||||
});
|
||||
|
||||
tap.test('should list containers', async () => {
|
||||
const containers = await testDockerHost.getContainers();
|
||||
console.log(containers);
|
||||
});
|
||||
|
||||
tap.skip.test('should pull an image from imagetag', async () => {
|
||||
// await testDockerHost.pullImage('hosttoday/ht-docker-node:npmci');
|
||||
});
|
||||
|
||||
tap.test('should return a change Objservable', async tools => {
|
||||
const testObservable = await testDockerHost.getEventObservable();
|
||||
const subscription = testObservable.subscribe(changeObject => {
|
||||
console.log(changeObject);
|
||||
});
|
||||
await tools.delayFor(2000);
|
||||
subscription.unsubscribe();
|
||||
});
|
||||
|
||||
tap.start();
|
1
ts/docker.changes.ts
Normal file
1
ts/docker.changes.ts
Normal file
@ -0,0 +1 @@
|
||||
import * as plugins from './dockersock.plugins';
|
77
ts/docker.classes.container.ts
Normal file
77
ts/docker.classes.container.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import * as plugins from './dockersock.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(containerResult));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets an container by Id
|
||||
* @param containerId
|
||||
*/
|
||||
public static async getContainerById(containerId: string) {}
|
||||
|
||||
/**
|
||||
* create a container
|
||||
*/
|
||||
public static async create(creationSpecifier: interfaces.IContainerCreationSpecifier) {}
|
||||
|
||||
// ========
|
||||
// INSTANCE
|
||||
// ========
|
||||
|
||||
constructor(dockerContainerObjectArg: any) {
|
||||
Object.keys(dockerContainerObjectArg).forEach(keyArg => {
|
||||
this[keyArg] = dockerContainerObjectArg[keyArg];
|
||||
});
|
||||
}
|
||||
|
||||
Id: string;
|
||||
Names: string[];
|
||||
Image: string;
|
||||
ImageID: string;
|
||||
Command: string;
|
||||
Created: number;
|
||||
Ports: interfaces.TPorts;
|
||||
Labels: interfaces.TLabels;
|
||||
State: string;
|
||||
Status: string;
|
||||
HostConfig: any;
|
||||
NetworkSettings: {
|
||||
Networks: {
|
||||
[key: string]: {
|
||||
IPAMConfig: any;
|
||||
Links: any;
|
||||
Aliases: any;
|
||||
NetworkID: string;
|
||||
EndpointID: string;
|
||||
Gateway: string;
|
||||
IPAddress: string;
|
||||
IPPrefixLen: number;
|
||||
IPv6Gateway: string;
|
||||
GlobalIPv6Address: string;
|
||||
GlobalIPv6PrefixLen: number;
|
||||
MacAddress: string;
|
||||
DriverOpts: any;
|
||||
};
|
||||
};
|
||||
};
|
||||
Mounts: any;
|
||||
}
|
94
ts/docker.classes.host.ts
Normal file
94
ts/docker.classes.host.ts
Normal file
@ -0,0 +1,94 @@
|
||||
import * as plugins from './dockersock.plugins';
|
||||
import { DockerContainer } from './docker.classes.container';
|
||||
|
||||
export class DockerHost {
|
||||
/**
|
||||
* the path where the docker sock can be found
|
||||
*/
|
||||
sockPath: string;
|
||||
|
||||
/**
|
||||
* keeping track of currently active requests to safely end this module at any time
|
||||
*/
|
||||
requestObjectmap = new plugins.lik.Objectmap<any>();
|
||||
|
||||
/**
|
||||
* the constructor to instantiate a new docker sock instance
|
||||
* @param pathArg
|
||||
*/
|
||||
constructor(pathArg: string = 'http://unix:/var/run/docker.sock:') {
|
||||
this.sockPath = pathArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* authenticate against a registry
|
||||
* @param userArg
|
||||
* @param passArg
|
||||
*/
|
||||
auth(registryArg: string, userArg: string, passArg: string) {
|
||||
let done = plugins.smartpromise.defer();
|
||||
this.request('POST', '');
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async getContainers() {
|
||||
const containerArray = await DockerContainer.getContainers(this);
|
||||
return containerArray;
|
||||
}
|
||||
|
||||
async getEventObservable(): Promise<plugins.rxjs.Observable<any>> {
|
||||
const response = await this.requestStreaming('GET', '/events');
|
||||
return plugins.rxjs.Observable.create(observer => {
|
||||
response.on('data', data => {
|
||||
const eventString = data.toString();
|
||||
try {
|
||||
const eventObject = JSON.parse(eventString);
|
||||
observer.next(eventObject);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
response.emit('end');
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* fire a request
|
||||
*/
|
||||
async request(methodArg: string, routeArg: string, dataArg = {}) {
|
||||
const requestUrl = `${this.sockPath}${routeArg}`;
|
||||
const response = await plugins.smartrequest.request(requestUrl, {
|
||||
method: methodArg,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Host: 'docker.sock'
|
||||
},
|
||||
requestBody: dataArg
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) {
|
||||
const requestUrl = `${this.sockPath}${routeArg}`;
|
||||
const response = await plugins.smartrequest.request(
|
||||
requestUrl,
|
||||
{
|
||||
method: methodArg,
|
||||
headers: {
|
||||
// 'Content-Type': 'application/json',
|
||||
Host: 'docker.sock'
|
||||
},
|
||||
requestBody: null
|
||||
},
|
||||
true
|
||||
);
|
||||
console.log(response.statusCode);
|
||||
console.log(response.body);
|
||||
return response;
|
||||
}
|
||||
}
|
38
ts/docker.classes.image.ts
Normal file
38
ts/docker.classes.image.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import * as plugins from './dockersock.plugins';
|
||||
import { DockerHost } from './docker.classes.host';
|
||||
|
||||
export class DockerImage {
|
||||
// STATIC
|
||||
public static async createFromRegistry(
|
||||
dockerHostArg: DockerHost,
|
||||
dockerImageTag
|
||||
): Promise<DockerImage> {
|
||||
const resultingImage = new DockerImage();
|
||||
|
||||
return resultingImage;
|
||||
}
|
||||
|
||||
public static async createFromExistingImage(dockerHostArg: DockerHost, dockerImageTag) {}
|
||||
|
||||
// INSTANCE
|
||||
/**
|
||||
* the tags for an image
|
||||
*/
|
||||
public tags: string[] = [];
|
||||
|
||||
/**
|
||||
* returns a boolean wether the image has a upstream image
|
||||
*/
|
||||
public isUpstreamImage(): boolean {
|
||||
// TODO: implement isUpastreamImage
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public async pullLatestImageFromRegistry(): Promise<boolean> {
|
||||
// TODO: implement pullLatestImageFromRegistry
|
||||
return true;
|
||||
}
|
||||
}
|
6
ts/docker.classes.network.ts
Normal file
6
ts/docker.classes.network.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import * as plugins from './dockersock.plugins';
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
import { DockerHost } from './docker.classes.host';
|
||||
|
||||
export class DockerNetwork {}
|
6
ts/docker.classes.service.ts
Normal file
6
ts/docker.classes.service.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import * as plugins from './dockersock.plugins';
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
import { DockerHost } from './docker.classes.host';
|
||||
|
||||
export class DockerService {}
|
@ -1,33 +0,0 @@
|
||||
import "typings-global"
|
||||
import * as plugins from "./dockersock.plugins";
|
||||
|
||||
export class dockersock {
|
||||
sockPath:string;
|
||||
constructor(pathArg:string){
|
||||
this.sockPath = pathArg;
|
||||
}
|
||||
|
||||
request(methodArg:string,routeArg:string,dataArg = {}){
|
||||
let done = plugins.q.defer();
|
||||
let jsonArg:string = JSON.stringify(dataArg);
|
||||
let options = {
|
||||
method:methodArg,
|
||||
url:"http://unix:/var/run/docker.sock:" + routeArg + "/json",
|
||||
headers:{
|
||||
"Content-Type":"application/json"
|
||||
},
|
||||
body:jsonArg
|
||||
};
|
||||
plugins.request(options,function(err, res, body){
|
||||
if (!err && res.statusCode == 200) {
|
||||
var responseObj = JSON.parse(body);
|
||||
done.resolve(responseObj);
|
||||
} else {
|
||||
console.log(err);
|
||||
console.log(res);
|
||||
done.reject(err);
|
||||
};
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
}
|
@ -1,4 +1,12 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export let q = require("q");
|
||||
export let request = require("request");
|
||||
// @pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
|
||||
export { lik, smartlog, smartpromise, smartrequest };
|
||||
|
||||
// third party
|
||||
import * as rxjs from 'rxjs';
|
||||
|
||||
export { rxjs };
|
||||
|
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 IContainerCreationSpecifier {
|
||||
hostname: string;
|
||||
domainName: string;
|
||||
networks?: DockerNetwork[];
|
||||
}
|
3
ts/interfaces/index.ts
Normal file
3
ts/interfaces/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './container';
|
||||
export * from './label';
|
||||
export * from './port';
|
2
ts/interfaces/label.ts
Normal file
2
ts/interfaces/label.ts
Normal file
@ -0,0 +1,2 @@
|
||||
// tslint:disable-next-line: interface-over-type-literal
|
||||
export type TLabels = { [key: string]: string };
|
6
ts/interfaces/port.ts
Normal file
6
ts/interfaces/port.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export interface IPort {
|
||||
PrivatePort: 80;
|
||||
Type: 'tcp';
|
||||
}
|
||||
|
||||
export type TPorts = IPort[];
|
17
tslint.json
Normal file
17
tslint.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user