Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
a202d05e9c | |||
6e97a7d83c | |||
04bb3b9ed0 | |||
29e502a32e |
32
README.md
32
README.md
@ -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
|
||||||
|
|
||||||
[](https://gitlab.com/mojoio/docker/commits/master)
|
[](https://gitlab.com/mojoio/docker/commits/master)
|
||||||
[](https://gitlab.com/mojoio/docker/commits/master)
|
[](https://gitlab.com/mojoio/docker/commits/master)
|
||||||
[](https://www.npmjs.com/package/@mojoio/docker)
|
[](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)
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
[](https://maintainedby.lossless.com)
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -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": {
|
||||||
|
@ -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",
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
{
|
{
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -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[];
|
||||||
|
Reference in New Issue
Block a user