Compare commits

..

16 Commits

Author SHA1 Message Date
a202d05e9c 1.0.37 2019-08-14 23:21:54 +02:00
6e97a7d83c fix(core): update 2019-08-14 23:21:54 +02:00
04bb3b9ed0 1.0.36 2019-08-14 21:02:06 +02:00
29e502a32e fix(core): update 2019-08-14 21:02:06 +02:00
75a118183e 1.0.35 2019-08-14 20:58:10 +02:00
aa1fe594e8 fix(core): update 2019-08-14 20:58:10 +02:00
cf761e19bf 1.0.34 2019-08-14 20:57:43 +02:00
af7590c8de fix(core): update 2019-08-14 20:57:43 +02:00
ee2e4fb856 1.0.33 2019-08-14 20:56:57 +02:00
ff5cecb07e fix(core): update 2019-08-14 20:56:57 +02:00
e50b028c00 1.0.32 2019-08-14 14:19:46 +02:00
867dda8e7c fix(core): update 2019-08-14 14:19:45 +02:00
d12d595f21 1.0.31 2019-01-18 02:42:13 +01:00
6117228ea4 fix(core): update 2019-01-18 02:42:13 +01:00
b6b584f808 1.0.30 2019-01-10 00:43:46 +01:00
48fe6ce0a8 fix(core): update 2019-01-10 00:43:45 +01:00
14 changed files with 778 additions and 507 deletions

22
.gitignore vendored
View File

@ -1,4 +1,22 @@
.yarn/ .nogit/
node_modules/
# artifacts
coverage/ coverage/
public/ public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,5 +1,5 @@
# gitzone standard # gitzone ci_default
image: hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
@ -34,52 +34,38 @@ snyk:
- docker - docker
- notpriv - 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 # test stage
# ==================== # ====================
testSTABLE: testLTS:
image: hosttoday/ht-docker-dbase:npmci
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install stable - npmci node install lts
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- priv - notpriv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install stable - npmci node install lts
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
@ -92,19 +78,11 @@ release:
# ==================== # ====================
codequality: codequality:
stage: metadata stage: metadata
image: docker:stable
allow_failure: true allow_failure: true
services:
- docker:stable-dind
script: script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') - npmci command npm install -g tslint typescript
- docker run - npmci npm install
--env SOURCE_CODE="$PWD" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
--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: tags:
- docker - docker
- priv - priv
@ -120,13 +98,15 @@ trigger:
- notpriv - notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-dbase:npmci
services:
- docker:18-dind
stage: metadata stage: metadata
script: script:
- npmci command npm install -g typedoc typescript - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/ - npmci command tsdoc
tags: tags:
- docker - docker
- notpriv - notpriv

View File

@ -1,52 +1,41 @@
# @mojoio/dockersock # @mojoio/docker
easy communication with docker remote api from node, TypeScript ready unofficial docker engine api abstraction package written in TypeScript
## Availabililty ## Availabililty and Links
[![npm](https://mojoio.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/dockersock) - [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/docker)
[![git](https://mojoio.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/mojoio/dockersock) - [gitlab.com (source)](https://gitlab.com/mojoio/docker)
[![git](https://mojoio.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/mojoio/dockersock) - [github.com (source mirror)](https://github.com/mojoio/docker)
[![docs](https://mojoio.gitlab.io/assets/repo-button-docs.svg)](https://mojoio.gitlab.io/dockersock/) - [docs (typedoc)](https://mojoio.gitlab.io/docker/)
## Status for master ## Status for master
[![build status](https://GitLab.com/mojoio/dockersock/badges/master/build.svg)](https://GitLab.com/mojoio/dockersock/commits/master) [![build status](https://gitlab.com/mojoio/docker/badges/master/build.svg)](https://gitlab.com/mojoio/docker/commits/master)
[![coverage report](https://GitLab.com/mojoio/dockersock/badges/master/coverage.svg)](https://GitLab.com/mojoio/dockersock/commits/master) [![coverage report](https://gitlab.com/mojoio/docker/badges/master/coverage.svg)](https://gitlab.com/mojoio/docker/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/dockersock.svg)](https://www.npmjs.com/package/dockersock) [![npm downloads per month](https://img.shields.io/npm/dm/@mojoio/docker.svg)](https://www.npmjs.com/package/@mojoio/docker)
[![Dependency Status](https://david-dm.org/mojoio/dockersock.svg)](https://david-dm.org/mojoio/dockersock) [![Known Vulnerabilities](https://snyk.io/test/npm/@mojoio/docker/badge.svg)](https://snyk.io/test/npm/@mojoio/docker)
[![bitHound Dependencies](https://www.bithound.io/github/mojoio/dockersock/badges/dependencies.svg)](https://www.bithound.io/github/mojoio/dockersock/master/dependencies/npm) [![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![bitHound Code](https://www.bithound.io/github/mojoio/dockersock/badges/code.svg)](https://www.bithound.io/github/mojoio/dockersock) [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage ## Usage
Use TypeScript for best in class instellisense. Use TypeScript for best in class instellisense.
```TypeScript ```typescript
import {Dockersock} from "dockersock"; // require Dockersock class import { DockerHost } from '@mojoio/docker'; // require Dockersock class
let myDockersock = new Dockersock(); // optional: you can pass a domain to the contructor, defaults to /var/run/docker.sock const run = async () => {
const myDockerHost = new DockerHost(); // optional: you can pass a domain to the contructor, defaults to /var/run/docker.sock
myDockersock.listContainers() // promise, resolve gets container data const containers = await myDockerHost.getContainers(); // promise, resolve with an array of DockerContainers
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. 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)
[![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://mojo.io) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,13 +1,22 @@
{ {
"npmdocker": { "npmdocker": {
"baseImage": "hosttoday/ht-docker-node:npmci", "baseImage": "hosttoday/ht-docker-node:npmci",
"command": "command": "(ls -a && rm -r node_modules && yarn global add npmts && yarn install && npmts)",
"(ls -a && rm -r node_modules && yarn global add npmts && yarn install && npmts)",
"dockerSock": true "dockerSock": true
}, },
"npmci": { "npmci": {
"npmGlobalTools": [], "npmGlobalTools": [],
"npmAccessLevel": "public", "npmAccessLevel": "public",
"npmRegistryUrl": "registry.npmjs.org" "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"
}
} }
} }

888
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/docker", "name": "@mojoio/docker",
"version": "1.0.29", "version": "1.0.37",
"description": "easy communication with docker remote api from node, TypeScript ready", "description": "easy communication with docker remote api from node, TypeScript ready",
"private": false, "private": false,
"main": "dist/index.js", "main": "dist/index.js",
@ -27,19 +27,30 @@
}, },
"homepage": "https://gitlab.com/pushrocks/dockersock#README", "homepage": "https://gitlab.com/pushrocks/dockersock#README",
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.4", "@pushrocks/lik": "^3.0.10",
"@pushrocks/smartlog": "^2.0.9", "@pushrocks/smartlog": "^2.0.19",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartrequest": "^1.1.14", "@pushrocks/smartrequest": "^1.1.16",
"rxjs": "^6.3.3" "rxjs": "^6.5.2"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.4", "@gitzone/tsbuild": "^2.1.11",
"@gitzone/tsrun": "^1.1.17", "@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.18", "@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.0.11",
"@types/node": "^10.12.18", "@types/node": "^12.7.1",
"tslint": "^5.12.0", "tslint": "^5.18.0",
"tslint-config-prettier": "^1.17.0" "tslint-config-prettier": "^1.18.0"
} },
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
} }

View File

@ -4,16 +4,16 @@ import * as interfaces from './interfaces';
import { DockerHost } from './docker.classes.host'; import { DockerHost } from './docker.classes.host';
export class DockerContainer { export class DockerContainer {
// ======
// STATIC // STATIC
// ======
/** /**
* get all containers * get all containers
*/ */
static async getContainers(dockerHostArg: DockerHost): Promise<DockerContainer[]> { public static async getContainers(dockerHostArg: DockerHost): Promise<DockerContainer[]> {
const result: DockerContainer[] = []; const result: DockerContainer[] = [];
const response = await dockerHostArg.request('GET', '/containers/json'); const response = await dockerHostArg.request('GET', '/containers/json');
// TODO: Think about getting the config by inpsecting the container
for (const containerResult of response.body) { for (const containerResult of response.body) {
result.push(new DockerContainer(containerResult)); result.push(new DockerContainer(containerResult));
} }
@ -21,34 +21,39 @@ export class DockerContainer {
} }
/** /**
* * gets an container by Id
* @param containerId * @param containerId
*/ */
static async getContainerById(containerId: string) {} public static async getContainerById(containerId: string) {
static async create() {} // TODO: implement get container by id
}
/**
* create a container
*/
public static async create(dockerHost: DockerHost, containerCreationDescriptor: interfaces.IContainerCreationDescriptor) {
// TODO implement creating a container
}
// ========
// INSTANCE // INSTANCE
// ========
constructor(dockerContainerObjectArg: any) { constructor(dockerContainerObjectArg: any) {
Object.keys(dockerContainerObjectArg).forEach(keyArg => { Object.keys(dockerContainerObjectArg).forEach(keyArg => {
this[keyArg] = dockerContainerObjectArg[keyArg]; this[keyArg] = dockerContainerObjectArg[keyArg];
}); });
} }
Id: string; public Id: string;
Names: string[]; public Names: string[];
Image: string; public Image: string;
ImageID: string; public ImageID: string;
Command: string; public Command: string;
Created: number; public Created: number;
Ports: interfaces.TPorts; public Ports: interfaces.TPorts;
Labels: interfaces.TLabels; public Labels: interfaces.TLabels;
State: string; public State: string;
Status: string; public Status: string;
HostConfig: any; public HostConfig: any;
NetworkSettings: { public NetworkSettings: {
Networks: { Networks: {
[key: string]: { [key: string]: {
IPAMConfig: any; IPAMConfig: any;
@ -67,5 +72,5 @@ export class DockerContainer {
}; };
}; };
}; };
Mounts: any; public Mounts: any;
} }

View File

@ -1,23 +1,19 @@
import * as plugins from './dockersock.plugins'; import * as plugins from './dockersock.plugins';
import { DockerContainer } from './docker.classes.container'; import { DockerContainer } from './docker.classes.container';
import { DockerNetwork } from './docker.classes.network';
export class DockerHost { export class DockerHost {
/** /**
* the path where the docker sock can be found * the path where the docker sock can be found
*/ */
sockPath: string; public socketPath: 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 * the constructor to instantiate a new docker sock instance
* @param pathArg * @param pathArg
*/ */
constructor(pathArg: string = 'http://unix:/var/run/docker.sock:') { constructor(pathArg: string = 'http://unix:/var/run/docker.sock:') {
this.sockPath = pathArg; this.socketPath = pathArg;
} }
/** /**
@ -25,25 +21,37 @@ export class DockerHost {
* @param userArg * @param userArg
* @param passArg * @param passArg
*/ */
auth(registryArg: string, userArg: string, passArg: string) { public async auth(registryArg: string, userArg: string, passArg: string) {
let done = plugins.smartpromise.defer(); // TODO: implement Docker Registry authentication
this.request('POST', ''); await this.request('POST', '');
return done.promise;
} }
/** /**
* * gets all networks
*/ */
async getContainers() { public async getNetworks() {
DockerNetwork.getNetworks(this);
}
/**
* gets all containers
*/
public async getContainers() {
const containerArray = await DockerContainer.getContainers(this); const containerArray = await DockerContainer.getContainers(this);
return containerArray; return containerArray;
} }
async getEventObservable(): Promise<plugins.rxjs.Observable<any>> { public async getEventObservable(): Promise<plugins.rxjs.Observable<any>> {
const response = await this.requestStreaming('GET', '/events'); const response = await this.requestStreaming('GET', '/events');
return plugins.rxjs.Observable.create(observer => { return plugins.rxjs.Observable.create(observer => {
response.on('data', data => { response.on('data', data => {
observer.next(data.toString()); const eventString = data.toString();
try {
const eventObject = JSON.parse(eventString);
observer.next(eventObject);
} catch (e) {
console.log(e);
}
}); });
return () => { return () => {
response.emit('end'); response.emit('end');
@ -54,8 +62,8 @@ export class DockerHost {
/** /**
* fire a request * fire a request
*/ */
async request(methodArg: string, routeArg: string, dataArg = {}) { public async request(methodArg: string, routeArg: string, dataArg = {}) {
const requestUrl = `${this.sockPath}${routeArg}`; const requestUrl = `${this.socketPath}${routeArg}`;
const response = await plugins.smartrequest.request(requestUrl, { const response = await plugins.smartrequest.request(requestUrl, {
method: methodArg, method: methodArg,
headers: { headers: {
@ -67,8 +75,8 @@ export class DockerHost {
return response; return response;
} }
async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) { public async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) {
const requestUrl = `${this.sockPath}${routeArg}`; const requestUrl = `${this.socketPath}${routeArg}`;
const response = await plugins.smartrequest.request( const response = await plugins.smartrequest.request(
requestUrl, requestUrl,
{ {

View File

@ -2,13 +2,37 @@ import * as plugins from './dockersock.plugins';
import { DockerHost } from './docker.classes.host'; import { DockerHost } from './docker.classes.host';
export class DockerImage { 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 * the tags for an image
*/ */
tags: string[] = []; public tags: string[] = [];
static async createFromRegsitry(dockerHostArg: DockerHost): Promise<DockerImage> { /**
const resultingImage = new DockerImage(); * returns a boolean wether the image has a upstream image
return resultingImage; */
public isUpstreamImage(): boolean {
// TODO: implement isUpastreamImage
return true;
}
/**
*
*/
public async pullLatestImageFromRegistry(): Promise<boolean> {
// TODO: implement pullLatestImageFromRegistry
return true;
} }
} }

View File

@ -0,0 +1,43 @@
import * as plugins from './dockersock.plugins';
import * as interfaces from './interfaces';
import { DockerHost } from './docker.classes.host';
export class DockerNetwork {
public static async getNetworks(dockerHost: DockerHost): Promise<DockerNetwork[]> {
const dockerNetworks: DockerNetwork[] = [];
return dockerNetworks;
}
public static async createNetwork(dockerHost: DockerHost, networkCreationDescriptor) {
// TODO: implement create network
}
constructor(dockerNetworkObjectArg: any) {
Object.keys(dockerNetworkObjectArg).forEach(keyArg => {
this[keyArg] = dockerNetworkObjectArg[keyArg];
});
}
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
}
]
};
}

View 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 {}

View File

@ -1 +1,5 @@
export { DockerHost } from './docker.classes.host'; 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';

View File

@ -0,0 +1,7 @@
import { DockerNetwork } from '../docker.classes.network';
export interface IContainerCreationDescriptor {
hostname: string;
domainName: string;
networks?: DockerNetwork[];
}

View File

@ -1,2 +1,3 @@
export * from './container';
export * from './label'; export * from './label';
export * from './port'; export * from './port';