Compare commits

...

6 Commits

Author SHA1 Message Date
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
13 changed files with 1522 additions and 234 deletions

View File

@ -1,62 +1,139 @@
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:dind
# gitzone standard
image: hosttoday/ht-docker-node:npmci
cache:
paths:
- .yarn/
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- test
- release
- trigger
- pages
- security
- test
- release
- 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
script:
- npmci test stable
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- priv
- docker
- priv
release:
image: hosttoday/ht-docker-node:npmci
stage: release
script:
- npmci publish npm
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- lossless
- priv
- 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
trigger:
image: hosttoday/ht-docker-node:npmci
stage: trigger
stage: metadata
script:
- npmci trigger
- npmci trigger
only:
- tags
- tags
tags:
- lossless
- priv
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: pages
stage: metadata
script:
- npmci command yarn global add npmpage
- npmci command npmpage --publish gitlab
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags:
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
- public
allow_failure: true

1425
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@mojoio/docker",
"version": "1.0.24",
"version": "1.0.27",
"description": "easy communication with docker remote api from node, TypeScript ready",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@ -26,14 +26,18 @@
},
"homepage": "https://gitlab.com/pushrocks/dockersock#README",
"dependencies": {
"@pushrocks/lik": "^3.0.1",
"@pushrocks/smartlog": "^2.0.1",
"@pushrocks/lik": "^3.0.4",
"@pushrocks/smartlog": "^2.0.9",
"@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartrequest": "^1.0.17",
"rxjs": "^6.2.2"
"@pushrocks/smartrequest": "^1.1.14",
"rxjs": "^6.3.3"
},
"devDependencies": {
"@pushrocks/tapbundle": "^3.0.1"
"@gitzone/tsrun": "^1.1.17",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.18",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0"
},
"private": false
}

View File

@ -13,16 +13,17 @@ tap.test('should list containers', async () => {
console.log(containers);
});
/*
tap.test('should pull an image from imagetag', async () => {
await testDockerHost.pullImage('hosttoday/ht-docker-node:npmci');
tap.skip.test('should pull an image from imagetag', async () => {
// await testDockerHost.pullImage('hosttoday/ht-docker-node:npmci');
});
tap.skip.test('should return a change Objservable', async () => {
let myObservable = testDockerHost.getChangeObservable();
testDockerHost.endRequests();
let testPromise = observableToPromise(myObservable);
return await expect(testPromise).to.eventually.be.fulfilled;
}); */
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();

View File

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

View File

@ -1,10 +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 = [];
await dockerHostArg.request('GET', '/containers/json')
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;
}

View File

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

@ -11,4 +11,4 @@ export class DockerImage {
const resultingImage = new DockerImage();
return resultingImage;
}
}
}

View File

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

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"
}