Compare commits

..

4 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
7 changed files with 93 additions and 61 deletions

View File

@ -1,13 +1,16 @@
# @mojoio/docker # @mojoio/docker
unofficial docker engine api abstraction package written in TypeScript unofficial docker engine api abstraction package written in TypeScript
## Availabililty and Links ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/docker)
* [gitlab.com (source)](https://gitlab.com/mojoio/docker) - [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/docker)
* [github.com (source mirror)](https://github.com/mojoio/docker) - [gitlab.com (source)](https://gitlab.com/mojoio/docker)
* [docs (typedoc)](https://mojoio.gitlab.io/docker/) - [github.com (source mirror)](https://github.com/mojoio/docker)
- [docs (typedoc)](https://mojoio.gitlab.io/docker/)
## Status for master ## Status for master
[![build status](https://gitlab.com/mojoio/docker/badges/master/build.svg)](https://gitlab.com/mojoio/docker/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/docker/badges/master/coverage.svg)](https://gitlab.com/mojoio/docker/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/@mojoio/docker.svg)](https://www.npmjs.com/package/@mojoio/docker) [![npm downloads per month](https://img.shields.io/npm/dm/@mojoio/docker.svg)](https://www.npmjs.com/package/@mojoio/docker)
@ -21,27 +24,18 @@ unofficial docker engine api abstraction package written in TypeScript
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) > | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/docker", "name": "@mojoio/docker",
"version": "1.0.35", "version": "1.0.37",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/docker", "name": "@mojoio/docker",
"version": "1.0.35", "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",

View File

@ -4,9 +4,7 @@ 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
@ -26,35 +24,36 @@ export class DockerContainer {
* gets an container by Id * gets an container by Id
* @param containerId * @param containerId
*/ */
public static async getContainerById(containerId: string) {} public static async getContainerById(containerId: string) {
// TODO: implement get container by id
}
/** /**
* create a container * create a container
*/ */
public static async create(creationSpecifier: interfaces.IContainerCreationSpecifier) {} 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;
@ -73,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,21 +21,27 @@ 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 => {
@ -60,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: {
@ -73,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

@ -3,4 +3,41 @@ import * as interfaces from './interfaces';
import { DockerHost } from './docker.classes.host'; import { DockerHost } from './docker.classes.host';
export class DockerNetwork {} 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

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