Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
55acb39071 | |||
f7b17a4684 | |||
d95f6c8e7f | |||
001cdadb6b | |||
82655623d1 | |||
ea117bc391 | |||
57594728df | |||
8430a4d6e0 | |||
7f38868510 | |||
7a80718d27 | |||
1d0c4c3cf9 | |||
a037cba454 | |||
7009e07ecc | |||
7b8ef33e21 | |||
3011e599e8 | |||
8adb636db3 | |||
dd35e5d7d2 |
135
.gitlab-ci.yml
135
.gitlab-ci.yml
@ -1,62 +1,139 @@
|
|||||||
image: hosttoday/ht-docker-dbase:npmci
|
# gitzone standard
|
||||||
services:
|
image: hosttoday/ht-docker-node:npmci
|
||||||
- docker:dind
|
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .yarn/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- security
|
||||||
- release
|
- test
|
||||||
- trigger
|
- release
|
||||||
- pages
|
- metadata
|
||||||
|
|
||||||
before_script:
|
# ====================
|
||||||
- npmci prepare docker-gitlab
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci git mirror
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
test:
|
snyk:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install -g snyk
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command snyk test
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
sast:
|
||||||
|
stage: security
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||||
|
variables:
|
||||||
|
DOCKER_DRIVER: overlay2
|
||||||
|
allow_failure: true
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||||
|
- docker run
|
||||||
|
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
||||||
|
--volume "$PWD:/code"
|
||||||
|
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
||||||
|
artifacts:
|
||||||
|
reports:
|
||||||
|
sast: gl-sast-report.json
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
|
testSTABLE:
|
||||||
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test stable
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci publish npm
|
- npmci node install stable
|
||||||
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- docker
|
||||||
- priv
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
image: docker:stable
|
||||||
|
allow_failure: true
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
script:
|
||||||
|
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||||
|
- docker run
|
||||||
|
--env SOURCE_CODE="$PWD"
|
||||||
|
--volume "$PWD":/code
|
||||||
|
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||||
|
artifacts:
|
||||||
|
paths: [codeclimate.json]
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
stage: metadata
|
||||||
stage: trigger
|
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- docker
|
||||||
- priv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: pages
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add npmpage
|
- npmci command npm install -g typedoc typescript
|
||||||
- npmci command npmpage --publish gitlab
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
# dockersock
|
# @mojoio/dockersock
|
||||||
|
|
||||||
easy communication with docker remote api from node, TypeScript ready
|
easy communication with docker remote api from node, TypeScript ready
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/dockersock)
|
[](https://www.npmjs.com/package/dockersock)
|
||||||
[](https://GitLab.com/mojoio/dockersock)
|
[](https://GitLab.com/mojoio/dockersock)
|
||||||
[](https://github.com/mojoio/dockersock)
|
[](https://github.com/mojoio/dockersock)
|
||||||
[](https://mojoio.gitlab.io/dockersock/)
|
[](https://mojoio.gitlab.io/dockersock/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
|
||||||
[](https://GitLab.com/mojoio/dockersock/commits/master)
|
[](https://GitLab.com/mojoio/dockersock/commits/master)
|
||||||
[](https://GitLab.com/mojoio/dockersock/commits/master)
|
[](https://GitLab.com/mojoio/dockersock/commits/master)
|
||||||
[](https://www.npmjs.com/package/dockersock)
|
[](https://www.npmjs.com/package/dockersock)
|
||||||
@ -19,6 +22,7 @@ easy communication with docker remote api from node, TypeScript ready
|
|||||||
[](http://standardjs.com/)
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
```TypeScript
|
```TypeScript
|
||||||
@ -38,12 +42,11 @@ myDockersock.startContainer({ // starts a already present container
|
|||||||
myDockersock.newContainer({ // start new Container, equals "docker run" shell command
|
myDockersock.newContainer({ // start new Container, equals "docker run" shell command
|
||||||
image: "someimagetag"
|
image: "someimagetag"
|
||||||
})
|
})
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
[](https://mojo.io)
|
[](https://mojo.io)
|
||||||
|
33
dist/dockersock.classes.dockersock.d.ts
vendored
33
dist/dockersock.classes.dockersock.d.ts
vendored
@ -1,33 +0,0 @@
|
|||||||
/// <reference types="request" />
|
|
||||||
/// <reference types="q" />
|
|
||||||
import "typings-global";
|
|
||||||
import * as plugins from "./dockersock.plugins";
|
|
||||||
import { Observable } from "rxjs";
|
|
||||||
import { Objectmap } from 'lik';
|
|
||||||
export declare class Dockersock {
|
|
||||||
sockPath: string;
|
|
||||||
requestObjectmap: Objectmap<plugins.request.Request>;
|
|
||||||
constructor(pathArg?: string);
|
|
||||||
auth(userArg: string, passArg: string): plugins.q.Promise<{}>;
|
|
||||||
listContainers(): plugins.q.Promise<{}>;
|
|
||||||
listContainersDetailed(): plugins.q.Promise<{}>;
|
|
||||||
listContainersRunning(): plugins.q.Promise<{}>;
|
|
||||||
listContainersStopped(): plugins.q.Promise<{}>;
|
|
||||||
listImages(): plugins.q.Promise<{}>;
|
|
||||||
listImagesDangling(): plugins.q.Promise<{}>;
|
|
||||||
pullImage(imageLabelArg: string): plugins.q.Promise<{}>;
|
|
||||||
createContainer(optionsArg: any, pullFirstArg?: boolean): plugins.q.Promise<{}>;
|
|
||||||
getContainerId(): void;
|
|
||||||
startContainer(containerNameArg: any): plugins.q.Promise<{}>;
|
|
||||||
stopContainer(containerNameArg: any): plugins.q.Promise<{}>;
|
|
||||||
removeContainer(containerNameArg: any): plugins.q.Promise<{}>;
|
|
||||||
clean(): plugins.q.Promise<{}>;
|
|
||||||
callOnChange(cb: Function): void;
|
|
||||||
/**
|
|
||||||
* gets you an observable that reports changes in the docker infrastructure
|
|
||||||
*/
|
|
||||||
getChangeObservable(): Observable<{}>;
|
|
||||||
request(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>;
|
|
||||||
requestStream(methodArg: string, routeArg: string, queryArg?: string, dataArg?: {}): plugins.q.Promise<{}>;
|
|
||||||
endRequests(): void;
|
|
||||||
}
|
|
261
dist/dockersock.classes.dockersock.js
vendored
261
dist/dockersock.classes.dockersock.js
vendored
File diff suppressed because one or more lines are too long
6
dist/dockersock.plugins.d.ts
vendored
6
dist/dockersock.plugins.d.ts
vendored
@ -1,6 +0,0 @@
|
|||||||
import "typings-global";
|
|
||||||
export import beautylog = require("beautylog");
|
|
||||||
export import lik = require("lik");
|
|
||||||
export import q = require("q");
|
|
||||||
export import request = require("request");
|
|
||||||
export import rxjs = require("rxjs");
|
|
9
dist/dockersock.plugins.js
vendored
9
dist/dockersock.plugins.js
vendored
@ -1,9 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
require("typings-global");
|
|
||||||
exports.beautylog = require("beautylog");
|
|
||||||
exports.lik = require("lik");
|
|
||||||
exports.q = require("q");
|
|
||||||
exports.request = require("request");
|
|
||||||
exports.rxjs = require("rxjs");
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvZG9ja2Vyc29jay5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsMEJBQXdCO0FBQ3hCLHlDQUErQztBQUMvQyw2QkFBbUM7QUFDbkMseUJBQStCO0FBQy9CLHFDQUEyQztBQUMzQywrQkFBcUMifQ==
|
|
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";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
require("typings-global");
|
|
||||||
var dockersock_classes_dockersock_1 = require("./dockersock.classes.dockersock");
|
|
||||||
exports.Dockersock = dockersock_classes_dockersock_1.Dockersock;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF3QjtBQUN4QixpRkFBNkQ7QUFBcEQscURBQUEsVUFBVSxDQUFBIn0=
|
|
@ -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
|
@ -1,49 +0,0 @@
|
|||||||
# dockersock
|
|
||||||
easy communication with docker remote api from node, TypeScript ready
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
[](https://www.npmjs.com/package/dockersock)
|
|
||||||
[](https://GitLab.com/mojoio/dockersock)
|
|
||||||
[](https://github.com/mojoio/dockersock)
|
|
||||||
[](https://mojoio.gitlab.io/dockersock/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://GitLab.com/mojoio/dockersock/commits/master)
|
|
||||||
[](https://GitLab.com/mojoio/dockersock/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/dockersock)
|
|
||||||
[](https://david-dm.org/mojoio/dockersock)
|
|
||||||
[](https://www.bithound.io/github/mojoio/dockersock/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/mojoio/dockersock)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
```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"
|
|
||||||
})
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://mojo.io)
|
|
@ -1,17 +1,13 @@
|
|||||||
{
|
{
|
||||||
"npmts":{
|
"npmdocker": {
|
||||||
"mode":"default",
|
"baseImage": "hosttoday/ht-docker-node:npmci",
|
||||||
"coverageTreshold":10
|
"command":
|
||||||
},
|
"(ls -a && rm -r node_modules && yarn global add npmts && yarn install && npmts)",
|
||||||
"npmdocker":{
|
"dockerSock": true
|
||||||
"baseImage":"hosttoday/ht-docker-node:npmci",
|
},
|
||||||
"command":"(npmci command yarn global add npmts) && npmts",
|
"npmci": {
|
||||||
"dockerSock":"true"
|
"npmGlobalTools": [],
|
||||||
},
|
"npmAccessLevel": "public",
|
||||||
"npmci": {
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
"globalNpmTools": [
|
}
|
||||||
"npmts",
|
}
|
||||||
"npmdocker"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
1575
package-lock.json
generated
Normal file
1575
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "dockersock",
|
"name": "@mojoio/docker",
|
||||||
"version": "1.0.20",
|
"version": "1.0.29",
|
||||||
"description": "easy communication with docker remote api from node, TypeScript ready",
|
"description": "easy communication with docker remote api from node, TypeScript ready",
|
||||||
|
"private": false,
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npmdocker"
|
"test": "tstest test/",
|
||||||
|
"build": "tsbuild"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,17 +27,19 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
|
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "1.x.x",
|
"@pushrocks/lik": "^3.0.4",
|
||||||
"@types/request": "0.x.x",
|
"@pushrocks/smartlog": "^2.0.9",
|
||||||
"beautylog": "^6.1.5",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"lik": "^1.0.27",
|
"@pushrocks/smartrequest": "^1.1.14",
|
||||||
"q": "^1.5.0",
|
"rxjs": "^6.3.3"
|
||||||
"request": "^2.81.0",
|
|
||||||
"rxjs": "^5.2.0",
|
|
||||||
"typings-global": "^1.0.14"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"observable-to-promise": "^0.5.0",
|
"@gitzone/tsbuild": "^2.1.4",
|
||||||
"tapbundle": "^1.0.5"
|
"@gitzone/tsrun": "^1.1.17",
|
||||||
|
"@gitzone/tstest": "^1.0.18",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
|
"@types/node": "^10.12.18",
|
||||||
|
"tslint": "^5.12.0",
|
||||||
|
"tslint-config-prettier": "^1.17.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
53
test/test.ts
53
test/test.ts
@ -1,36 +1,29 @@
|
|||||||
import "typings-global";
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import { expect, tap } from 'tapbundle'
|
import { DockerHost } from '../ts/index';
|
||||||
import * as observableToPromise from 'observable-to-promise'
|
|
||||||
import { Dockersock } from "../dist/index";
|
|
||||||
|
|
||||||
let testDockersock: Dockersock;
|
let testDockerHost: DockerHost;
|
||||||
|
|
||||||
tap.test("should create a new Dockersock instance", async () => {
|
tap.test('should create a new Dockersock instance', async () => {
|
||||||
testDockersock = new Dockersock();
|
testDockerHost = new DockerHost();
|
||||||
return expect(testDockersock).to.be.instanceof(Dockersock);
|
return expect(testDockerHost).to.be.instanceof(DockerHost);
|
||||||
}).catch(tap.threw);
|
});
|
||||||
|
|
||||||
tap.test("should list containers", async () => {
|
tap.test('should list containers', async () => {
|
||||||
await testDockersock.listContainers()
|
const containers = await testDockerHost.getContainers();
|
||||||
.then(async (dataArg) => {
|
console.log(containers);
|
||||||
console.log(dataArg);
|
});
|
||||||
});
|
|
||||||
}).catch(tap.threw);
|
|
||||||
|
|
||||||
tap.test("should list detailed containers", async () => {
|
tap.skip.test('should pull an image from imagetag', async () => {
|
||||||
await testDockersock.listContainersDetailed()
|
// await testDockerHost.pullImage('hosttoday/ht-docker-node:npmci');
|
||||||
.then(async (dataArg) => {
|
});
|
||||||
console.log(dataArg);
|
|
||||||
});
|
|
||||||
}).catch(tap.threw);
|
|
||||||
|
|
||||||
tap.test("should pull an image from imagetag", async () => {
|
tap.test('should return a change Objservable', async tools => {
|
||||||
await testDockersock.pullImage("hosttoday/ht-docker-node:npmci")
|
const testObservable = await testDockerHost.getEventObservable();
|
||||||
}).catch(tap.threw);
|
const subscription = testObservable.subscribe(changeObject => {
|
||||||
|
console.log(changeObject);
|
||||||
|
});
|
||||||
|
await tools.delayFor(2000);
|
||||||
|
subscription.unsubscribe();
|
||||||
|
});
|
||||||
|
|
||||||
/*tap.test("should return a change Objservable", async () => {
|
tap.start();
|
||||||
let myObservable = testDockersock.getChangeObservable();
|
|
||||||
testDockersock.endRequests();
|
|
||||||
let testPromise = observableToPromise(myObservable)
|
|
||||||
return await expect(testPromise).to.eventually.be.fulfilled
|
|
||||||
}).catch(tap.threw);*/
|
|
||||||
|
1
ts/docker.changes.ts
Normal file
1
ts/docker.changes.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
import * as plugins from './dockersock.plugins';
|
71
ts/docker.classes.container.ts
Normal file
71
ts/docker.classes.container.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import * as plugins from './dockersock.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
|
||||||
|
export class DockerContainer {
|
||||||
|
// ======
|
||||||
|
// STATIC
|
||||||
|
// ======
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get all containers
|
||||||
|
*/
|
||||||
|
static async getContainers(dockerHostArg: DockerHost): Promise<DockerContainer[]> {
|
||||||
|
const result: DockerContainer[] = [];
|
||||||
|
const response = await dockerHostArg.request('GET', '/containers/json');
|
||||||
|
for (const containerResult of response.body) {
|
||||||
|
result.push(new DockerContainer(containerResult));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param containerId
|
||||||
|
*/
|
||||||
|
static async getContainerById(containerId: string) {}
|
||||||
|
static async create() {}
|
||||||
|
|
||||||
|
// ========
|
||||||
|
// INSTANCE
|
||||||
|
// ========
|
||||||
|
|
||||||
|
constructor(dockerContainerObjectArg: any) {
|
||||||
|
Object.keys(dockerContainerObjectArg).forEach(keyArg => {
|
||||||
|
this[keyArg] = dockerContainerObjectArg[keyArg];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Id: string;
|
||||||
|
Names: string[];
|
||||||
|
Image: string;
|
||||||
|
ImageID: string;
|
||||||
|
Command: string;
|
||||||
|
Created: number;
|
||||||
|
Ports: interfaces.TPorts;
|
||||||
|
Labels: interfaces.TLabels;
|
||||||
|
State: string;
|
||||||
|
Status: string;
|
||||||
|
HostConfig: any;
|
||||||
|
NetworkSettings: {
|
||||||
|
Networks: {
|
||||||
|
[key: string]: {
|
||||||
|
IPAMConfig: any;
|
||||||
|
Links: any;
|
||||||
|
Aliases: any;
|
||||||
|
NetworkID: string;
|
||||||
|
EndpointID: string;
|
||||||
|
Gateway: string;
|
||||||
|
IPAddress: string;
|
||||||
|
IPPrefixLen: number;
|
||||||
|
IPv6Gateway: string;
|
||||||
|
GlobalIPv6Address: string;
|
||||||
|
GlobalIPv6PrefixLen: number;
|
||||||
|
MacAddress: string;
|
||||||
|
DriverOpts: any;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
Mounts: any;
|
||||||
|
}
|
88
ts/docker.classes.host.ts
Normal file
88
ts/docker.classes.host.ts
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
import * as plugins from './dockersock.plugins';
|
||||||
|
import { DockerContainer } from './docker.classes.container';
|
||||||
|
|
||||||
|
export class DockerHost {
|
||||||
|
/**
|
||||||
|
* the path where the docker sock can be found
|
||||||
|
*/
|
||||||
|
sockPath: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* keeping track of currently active requests to safely end this module at any time
|
||||||
|
*/
|
||||||
|
requestObjectmap = new plugins.lik.Objectmap<any>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the constructor to instantiate a new docker sock instance
|
||||||
|
* @param pathArg
|
||||||
|
*/
|
||||||
|
constructor(pathArg: string = 'http://unix:/var/run/docker.sock:') {
|
||||||
|
this.sockPath = pathArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* authenticate against a registry
|
||||||
|
* @param userArg
|
||||||
|
* @param passArg
|
||||||
|
*/
|
||||||
|
auth(registryArg: string, userArg: string, passArg: string) {
|
||||||
|
let done = plugins.smartpromise.defer();
|
||||||
|
this.request('POST', '');
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async getContainers() {
|
||||||
|
const containerArray = await DockerContainer.getContainers(this);
|
||||||
|
return containerArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getEventObservable(): Promise<plugins.rxjs.Observable<any>> {
|
||||||
|
const response = await this.requestStreaming('GET', '/events');
|
||||||
|
return plugins.rxjs.Observable.create(observer => {
|
||||||
|
response.on('data', data => {
|
||||||
|
observer.next(data.toString());
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
response.emit('end');
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fire a request
|
||||||
|
*/
|
||||||
|
async request(methodArg: string, routeArg: string, dataArg = {}) {
|
||||||
|
const requestUrl = `${this.sockPath}${routeArg}`;
|
||||||
|
const response = await plugins.smartrequest.request(requestUrl, {
|
||||||
|
method: methodArg,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Host: 'docker.sock'
|
||||||
|
},
|
||||||
|
requestBody: dataArg
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) {
|
||||||
|
const requestUrl = `${this.sockPath}${routeArg}`;
|
||||||
|
const response = await plugins.smartrequest.request(
|
||||||
|
requestUrl,
|
||||||
|
{
|
||||||
|
method: methodArg,
|
||||||
|
headers: {
|
||||||
|
// 'Content-Type': 'application/json',
|
||||||
|
Host: 'docker.sock'
|
||||||
|
},
|
||||||
|
requestBody: null
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
console.log(response.statusCode);
|
||||||
|
console.log(response.body);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
14
ts/docker.classes.image.ts
Normal file
14
ts/docker.classes.image.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import * as plugins from './dockersock.plugins';
|
||||||
|
import { DockerHost } from './docker.classes.host';
|
||||||
|
|
||||||
|
export class DockerImage {
|
||||||
|
/**
|
||||||
|
* the tags for an image
|
||||||
|
*/
|
||||||
|
tags: string[] = [];
|
||||||
|
|
||||||
|
static async createFromRegsitry(dockerHostArg: DockerHost): Promise<DockerImage> {
|
||||||
|
const resultingImage = new DockerImage();
|
||||||
|
return resultingImage;
|
||||||
|
}
|
||||||
|
}
|
0
ts/docker.classes.network.ts
Normal file
0
ts/docker.classes.network.ts
Normal file
0
ts/docker.classes.service.ts
Normal file
0
ts/docker.classes.service.ts
Normal file
@ -1,243 +0,0 @@
|
|||||||
import "typings-global"
|
|
||||||
import * as plugins from "./dockersock.plugins";
|
|
||||||
import { Observable } from "rxjs";
|
|
||||||
|
|
||||||
// interfaces
|
|
||||||
import { Objectmap } from 'lik'
|
|
||||||
|
|
||||||
export class Dockersock {
|
|
||||||
sockPath: string;
|
|
||||||
requestObjectmap = new plugins.lik.Objectmap<plugins.request.Request>();
|
|
||||||
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(imageLabelArg: string) {
|
|
||||||
let imageLabel = encodeURI(imageLabelArg);
|
|
||||||
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", () => {
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets you an observable that reports changes in the docker infrastructure
|
|
||||||
*/
|
|
||||||
getChangeObservable() {
|
|
||||||
let options = {
|
|
||||||
method: "GET",
|
|
||||||
url: this.sockPath + "/events",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Host": "docker.sock"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let requestStream = plugins.request(options, (err, res, body) => {
|
|
||||||
if (!err && res.statusCode == 200) {
|
|
||||||
} else {
|
|
||||||
console.log(err);
|
|
||||||
console.log(res);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
let incomingMessage
|
|
||||||
requestStream.on("response", (response) => {
|
|
||||||
incomingMessage = response
|
|
||||||
this.requestObjectmap.add(incomingMessage);
|
|
||||||
if (response.statusCode == 200) {
|
|
||||||
plugins.beautylog.ok("request returned status 200, so we are good!");
|
|
||||||
} else {
|
|
||||||
plugins.beautylog.error("request returned error: " + response.statusCode);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let changeObservable = Observable.fromEvent(requestStream, "data");
|
|
||||||
requestStream.on("end", () => {
|
|
||||||
this.requestObjectmap.remove(incomingMessage);
|
|
||||||
});
|
|
||||||
return changeObservable;
|
|
||||||
}
|
|
||||||
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",
|
|
||||||
"Host": "docker.sock"
|
|
||||||
},
|
|
||||||
body: jsonArg
|
|
||||||
};
|
|
||||||
//console.log(options);
|
|
||||||
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: string, routeArg: string, queryArg: string = "", dataArg = {}) {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
let jsonArg: string = JSON.stringify(dataArg);
|
|
||||||
let suffix: string = "";
|
|
||||||
let options = {
|
|
||||||
method: methodArg,
|
|
||||||
url: this.sockPath + routeArg + suffix + queryArg,
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Host": "docker.sock"
|
|
||||||
},
|
|
||||||
body: jsonArg
|
|
||||||
};
|
|
||||||
let requestStream = plugins.request(options, (err, res, body) => {
|
|
||||||
if (!err && res.statusCode == 200) {
|
|
||||||
done.resolve();
|
|
||||||
} else {
|
|
||||||
console.log(err);
|
|
||||||
console.log(res);
|
|
||||||
done.reject(err);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
let incomingMessage
|
|
||||||
requestStream.on("response", (response) => {
|
|
||||||
incomingMessage = response
|
|
||||||
this.requestObjectmap.add(incomingMessage);
|
|
||||||
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(response);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
requestStream.on("data", (data: Buffer) => {
|
|
||||||
let status;
|
|
||||||
status = JSON.parse(data.toString()).status;
|
|
||||||
plugins.beautylog.logReduced(status);
|
|
||||||
});
|
|
||||||
requestStream.on("end", () => {
|
|
||||||
this.requestObjectmap.remove(incomingMessage);
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
endRequests() {
|
|
||||||
setTimeout(() => {
|
|
||||||
this.requestObjectmap.forEach((itemArg: plugins.request.Request) => {
|
|
||||||
itemArg.emit("end");
|
|
||||||
});
|
|
||||||
this.requestObjectmap.wipe();
|
|
||||||
}, 5000);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,6 +1,12 @@
|
|||||||
import "typings-global";
|
// @pushrocks scope
|
||||||
export import beautylog = require("beautylog");
|
import * as lik from '@pushrocks/lik';
|
||||||
export import lik = require("lik");
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
export import q = require("q");
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
export import request = require("request");
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
export import rxjs = require("rxjs");
|
|
||||||
|
export { lik, smartlog, smartpromise, smartrequest };
|
||||||
|
|
||||||
|
// third party
|
||||||
|
import * as rxjs from 'rxjs';
|
||||||
|
|
||||||
|
export { rxjs };
|
||||||
|
@ -1,2 +1 @@
|
|||||||
import "typings-global";
|
export { DockerHost } from './docker.classes.host';
|
||||||
export { Dockersock } from "./dockersock.classes.dockersock";
|
|
||||||
|
2
ts/interfaces/index.ts
Normal file
2
ts/interfaces/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export * from './label';
|
||||||
|
export * from './port';
|
2
ts/interfaces/label.ts
Normal file
2
ts/interfaces/label.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// tslint:disable-next-line: interface-over-type-literal
|
||||||
|
export type TLabels = { [key: string]: string };
|
6
ts/interfaces/port.ts
Normal file
6
ts/interfaces/port.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export interface IPort {
|
||||||
|
PrivatePort: 80;
|
||||||
|
Type: 'tcp';
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TPorts = IPort[];
|
17
tslint.json
Normal file
17
tslint.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
|
}
|
Reference in New Issue
Block a user