mirror of
https://github.com/valentineus/simple-container.git
synced 2025-04-29 00:51:25 +03:00
Adding a description
This commit is contained in:
parent
27771e6654
commit
496c90871c
@ -9,7 +9,7 @@ import { statSync } from 'fs';
|
|||||||
export default class Container extends Item {
|
export default class Container extends Item {
|
||||||
/**
|
/**
|
||||||
* @constructs Container
|
* @constructs Container
|
||||||
* @param {Object} options
|
* @param {Object=} [options] - Service connection settings
|
||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super();
|
super();
|
||||||
@ -17,7 +17,8 @@ export default class Container extends Item {
|
|||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
* @description
|
* @description Docker class service management.
|
||||||
|
* https://github.com/apocas/dockerode
|
||||||
*/
|
*/
|
||||||
this._docker = null;
|
this._docker = null;
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ export default class Container extends Item {
|
|||||||
var stats = statSync(socket);
|
var stats = statSync(socket);
|
||||||
|
|
||||||
if (!stats.isSocket()) {
|
if (!stats.isSocket()) {
|
||||||
throw new Error('');
|
throw new Error('Local service is not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
this._docker = new Docker({
|
this._docker = new Docker({
|
||||||
@ -40,27 +41,22 @@ export default class Container extends Item {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @param {Object|String} options
|
* @param {Object|String} options - Container parameters
|
||||||
* @description
|
* @description Creates and registers a container in the system.
|
||||||
*/
|
*/
|
||||||
create(options) {
|
create(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var name = null;
|
|
||||||
|
|
||||||
if (!self._isString(options) && !self._isObject(options)) {
|
if (!self._isString(options) && !self._isObject(options)) {
|
||||||
throw new Error('The variable \'options\' is not correct.');
|
throw new Error('The variable \'options\' is not correct.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self._isString(options)) {
|
if (self._isString(options)) {
|
||||||
name = options;
|
var Image = options;
|
||||||
options = { Image: name };
|
options = { Image };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self._isObject(options)) {
|
self._pullImage(options.Image, (error) => {
|
||||||
name = options.Image;
|
|
||||||
}
|
|
||||||
|
|
||||||
self._pullImage(name, (error) => {
|
|
||||||
self._handlerError(error);
|
self._handlerError(error);
|
||||||
self._createContainer(options);
|
self._createContainer(options);
|
||||||
});
|
});
|
||||||
@ -68,32 +64,33 @@ export default class Container extends Item {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @description
|
* @description Stops and destroys the container.
|
||||||
*/
|
*/
|
||||||
destroy() {}
|
destroy() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @param {String} name
|
* @param {String} image - Name of the image
|
||||||
* @param {Function} callback
|
* @param {Function} callback - Called function
|
||||||
* @description
|
* @description Pulls out the image of the container.
|
||||||
*/
|
*/
|
||||||
_pullImage(name, callback) {
|
_pullImage(image, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self._docker.pull(name).then(stream => {
|
self._docker.pull(image).then(stream => {
|
||||||
self._docker.modem.followProgress(stream, callback, self.debug);
|
self._docker.modem.followProgress(stream, callback, self.debug);
|
||||||
}).catch(error => self._handlerError(error));
|
}).catch(error => self._handlerError(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @param {Object} options
|
* @param {Object} options - Container settings
|
||||||
* @description
|
* @description Creating a container and registering management.
|
||||||
*/
|
*/
|
||||||
_createContainer(options) {
|
_createContainer(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self._docker.createContainer(options).then(container => {
|
self._docker.createContainer(options).then(container => {
|
||||||
/* @todo Регистрация класса */
|
/* @todo Class registration */
|
||||||
|
self.debug(container);
|
||||||
}).catch(error => self._handlerError(error));
|
}).catch(error => self._handlerError(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +98,7 @@ export default class Container extends Item {
|
|||||||
* @protected
|
* @protected
|
||||||
* @param {*} value - The variable to check
|
* @param {*} value - The variable to check
|
||||||
* @returns {Boolean} Result of checking
|
* @returns {Boolean} Result of checking
|
||||||
* @description Checks the type of the variable
|
* @description Checks the type of the variable.
|
||||||
*/
|
*/
|
||||||
_isString(value) {
|
_isString(value) {
|
||||||
return typeof value === 'string';
|
return typeof value === 'string';
|
||||||
@ -111,7 +108,7 @@ export default class Container extends Item {
|
|||||||
* @protected
|
* @protected
|
||||||
* @param {*} value - The variable to check
|
* @param {*} value - The variable to check
|
||||||
* @returns {Boolean} Result of checking
|
* @returns {Boolean} Result of checking
|
||||||
* @description Checks the type of the variable
|
* @description Checks the type of the variable.
|
||||||
*/
|
*/
|
||||||
_isObject(value) {
|
_isObject(value) {
|
||||||
return typeof value === 'object';
|
return typeof value === 'object';
|
||||||
@ -119,19 +116,18 @@ export default class Container extends Item {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @param {*} error
|
* @param {*} error - A string with an error
|
||||||
* @description
|
* @description Handles the error if present.
|
||||||
*/
|
*/
|
||||||
_handlerError(error) {
|
_handlerError(error) {
|
||||||
if (!!error) {
|
if (error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @param {*} Any variables
|
||||||
* @param {*}
|
* @description A simple debugger.
|
||||||
* @description
|
|
||||||
*/
|
*/
|
||||||
debug() {
|
debug() {
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user