Compare commits

..

10 Commits

Author SHA1 Message Date
55acb39071 1.0.29 2019-01-10 00:37:32 +01:00
f7b17a4684 fix(core): update 2019-01-10 00:37:32 +01:00
d95f6c8e7f 1.0.28 2019-01-10 00:31:49 +01:00
001cdadb6b fix(core): update 2019-01-10 00:31:48 +01:00
82655623d1 1.0.27 2019-01-10 00:28:13 +01:00
ea117bc391 fix(core): update 2019-01-10 00:28:12 +01:00
57594728df 1.0.26 2019-01-10 00:24:35 +01:00
8430a4d6e0 fix(core): update 2019-01-10 00:24:35 +01:00
7f38868510 1.0.25 2018-07-17 08:39:38 +02:00
7a80718d27 fix(core): update 2018-07-17 08:39:37 +02:00
14 changed files with 1579 additions and 243 deletions

View File

@ -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
- 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 - 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

View File

@ -1,8 +1,4 @@
{ {
"npmts": {
"mode": "default",
"coverageTreshold": 10
},
"npmdocker": { "npmdocker": {
"baseImage": "hosttoday/ht-docker-node:npmci", "baseImage": "hosttoday/ht-docker-node:npmci",
"command": "command":
@ -10,6 +6,8 @@
"dockerSock": true "dockerSock": true
}, },
"npmci": { "npmci": {
"globalNpmTools": ["npmts", "npmdocker"] "npmGlobalTools": [],
"npmAccessLevel": "public",
"npmRegistryUrl": "registry.npmjs.org"
} }
} }

1473
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,13 @@
{ {
"name": "@mojoio/docker", "name": "@mojoio/docker",
"version": "1.0.24", "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": "tsrun test/test.ts", "test": "tstest test/",
"build": "(npmts --notest && npmdocker)" "build": "tsbuild"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -26,14 +27,19 @@
}, },
"homepage": "https://gitlab.com/pushrocks/dockersock#README", "homepage": "https://gitlab.com/pushrocks/dockersock#README",
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.1", "@pushrocks/lik": "^3.0.4",
"@pushrocks/smartlog": "^2.0.1", "@pushrocks/smartlog": "^2.0.9",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartrequest": "^1.0.17", "@pushrocks/smartrequest": "^1.1.14",
"rxjs": "^6.2.2" "rxjs": "^6.3.3"
}, },
"devDependencies": { "devDependencies": {
"@pushrocks/tapbundle": "^3.0.1" "@gitzone/tsbuild": "^2.1.4",
}, "@gitzone/tsrun": "^1.1.17",
"private": false "@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"
}
} }

View File

@ -13,16 +13,17 @@ tap.test('should list containers', async () => {
console.log(containers); console.log(containers);
}); });
/* tap.skip.test('should pull an image from imagetag', async () => {
tap.test('should pull an image from imagetag', async () => { // await testDockerHost.pullImage('hosttoday/ht-docker-node:npmci');
await testDockerHost.pullImage('hosttoday/ht-docker-node:npmci');
}); });
tap.skip.test('should return a change Objservable', async () => { tap.test('should return a change Objservable', async tools => {
let myObservable = testDockerHost.getChangeObservable(); const testObservable = await testDockerHost.getEventObservable();
testDockerHost.endRequests(); const subscription = testObservable.subscribe(changeObject => {
let testPromise = observableToPromise(myObservable); console.log(changeObject);
return await expect(testPromise).to.eventually.be.fulfilled; });
}); */ await tools.delayFor(2000);
subscription.unsubscribe();
});
tap.start(); tap.start();

View File

@ -1,2 +1 @@
import * as plugins from './dockersock.plugins'; import * as plugins from './dockersock.plugins';

View File

@ -1,10 +1,71 @@
import * as plugins from './dockersock.plugins'; import * as plugins from './dockersock.plugins';
import * as interfaces from './interfaces';
import { DockerHost } from './docker.classes.host'; import { DockerHost } from './docker.classes.host';
export class DockerContainer { export class DockerContainer {
// ======
// STATIC
// ======
/**
* get all containers
*/
static async getContainers(dockerHostArg: DockerHost): Promise<DockerContainer[]> { static async getContainers(dockerHostArg: DockerHost): Promise<DockerContainer[]> {
const result = []; const result: DockerContainer[] = [];
await dockerHostArg.request('GET', '/containers/json') const response = await dockerHostArg.request('GET', '/containers/json');
for (const containerResult of response.body) {
result.push(new DockerContainer(containerResult));
}
return result; 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;
} }

View File

@ -1,5 +1,5 @@
import * as plugins from "./dockersock.plugins"; import * as plugins from './dockersock.plugins';
import { DockerContainer } from "./docker.classes.container"; import { DockerContainer } from './docker.classes.container';
export class DockerHost { export class DockerHost {
/** /**
@ -16,7 +16,7 @@ export class DockerHost {
* 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.sockPath = pathArg;
} }
@ -27,7 +27,7 @@ export class DockerHost {
*/ */
auth(registryArg: string, userArg: string, passArg: string) { auth(registryArg: string, userArg: string, passArg: string) {
let done = plugins.smartpromise.defer(); let done = plugins.smartpromise.defer();
this.request("POST", ""); this.request('POST', '');
return done.promise; return done.promise;
} }
@ -39,20 +39,50 @@ export class DockerHost {
return containerArray; 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 * fire a request
*/ */
async request(methodArg: string, routeArg: string, dataArg = {}) { async request(methodArg: string, routeArg: string, dataArg = {}) {
const requestUrl = `${this.sockPath}${routeArg}` const requestUrl = `${this.sockPath}${routeArg}`;
console.log(requestUrl);
const response = await plugins.smartrequest.request(requestUrl, { const response = await plugins.smartrequest.request(requestUrl, {
method: methodArg, method: methodArg,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
"Host": "docker.sock" Host: 'docker.sock'
}, },
requestBody: dataArg requestBody: dataArg
}); });
return response 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;
} }
} }

View File

@ -1,6 +1,12 @@
import 'typings-global'; // @pushrocks scope
export import smartlog = require('@pushrocks/smartlog'); import * as lik from '@pushrocks/lik';
export import lik = require('@pushrocks/lik'); import * as smartlog from '@pushrocks/smartlog';
export import smartpromise = require('@pushrocks/smartpromise'); import * as smartpromise from '@pushrocks/smartpromise';
export import smartrequest = require('@pushrocks/smartrequest'); 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 };

2
ts/interfaces/index.ts Normal file
View File

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

2
ts/interfaces/label.ts Normal file
View 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
View File

@ -0,0 +1,6 @@
export interface IPort {
PrivatePort: 80;
Type: 'tcp';
}
export type TPorts = IPort[];

17
tslint.json Normal file
View 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"
}