Modules
- fsutil
Some synchronous utilities functions for manipulate the file system.
- usdocker
Helper class to run docker commands/action
Classes
- Config
Class to handle the configuration of the script
- DockerListWrapper
Wrapper for the "docker list" command line
- DockerRunWrapper
Wrapper for the "docker run" command line
- DockerWrapper
Abstract class for implement docker wrapper class
- Output
Handle the output of the modules instead to console.log
- ScriptContainer
Handle where to locate and how to load and run the string
fsutil
Some synchronous utilities functions for manipulate the file system.
usdocker
Helper class to run docker commands/action
- usdocker
- .pull(image, callback)
- .up(instance, dockerRunWrapper, callback)
- .down(instance, callback)
- .outputRaw(option, dockerrunwrapper) ⇒
* - .restart(instance, dockerRunWrapper, callback)
- .status(instance, callback)
- .run(sc, script, command, setup)
- .runUsingApi(dockerrunwrapper)
- .runUsingCli(dockerrunwrapper)
- .exec(instance, cmd, callback)
- .ask(question, defaultValue, optYes, optNo, yesFn, noFn)
- .config(script) ⇒
Config - .configGlobal() ⇒
Config - .dockerRunWrapper() ⇒
DockerRunWrapper - .fsutil() ⇒
fsutil - .getHostIpAddress() ⇒
Array - .getDockerInstance(host) ⇒
Docker
usdocker.pull(image, callback)
Pull an docker image
Kind: static method of usdocker
| Param | Type | Description |
|---|---|---|
| image | string |
The image name |
| callback | The callback function |
Example
usdocker.pull('ubuntu:16.04', function(err) {
if (err) {
console.log(err);
return;
}
// Do if is OK
});
usdocker.up(instance, dockerRunWrapper, callback)
Create and run a container based on the DockerRunWrapper parameter.
Kind: static method of usdocker
| Param | Type |
|---|---|
| instance | string |
| dockerRunWrapper | DockerRunWrapper |
| callback |
Example
let docker = usdocker.dockerRunWrapper(configGlobal);
docker.image('ubuntu:16.04').isInteractive(true).isDetached(false).commandParam('bash');
usdocker.up('ubuntu-container', docker, function(normal, verbose) {
// do something
});
usdocker.down(instance, callback)
Shutdown a container defined by the name. The container suffix will be added automatically
Kind: static method of usdocker
| Param | Type |
|---|---|
| instance | string |
| callback |
Example
usdocker.down('ubuntu-container', function(normal, verbose) {
// do something
});
usdocker.outputRaw(option, dockerrunwrapper) ⇒ *
Return the RAW docker wrapper command.
Kind: static method of usdocker
| Param | Type | Description |
|---|---|---|
| option | string |
Can be "api" to return the json for the docker API or CLI to return the document command. |
| dockerrunwrapper |
usdocker.restart(instance, dockerRunWrapper, callback)
Restart a container defined by the name. The container suffix will be added automatically
Kind: static method of usdocker
| Param | Type |
|---|---|
| instance | string |
| dockerRunWrapper | DockerRunWrapper |
| callback |
Example
let docker = usdocker.dockerRunWrapper(configGlobal);
docker.image('ubuntu:16.04').isInteractive(true).isDetached(false).commandParam('bash');
usdocker.down('ubuntu-container', docker, function(normal, verbose) {
// do something
});
usdocker.status(instance, callback)
Get the container running status. The container suffix will be added automatically
Kind: static method of usdocker
| Param | Type |
|---|---|
| instance | string |
| callback |
Example
usdocker.status('ubuntu-container', function(normal, verbose) {
// do something
});
usdocker.run(sc, script, command, setup)
Run a method of the script.
Kind: static method of usdocker
| Param | Type |
|---|---|
| sc | ScriptContainer |
| script | Config |
| command | string |
| setup | boolean |
usdocker.runUsingApi(dockerrunwrapper)
Run a container based on the DockerRunWrapper definition
Kind: static method of usdocker
| Param | Type |
|---|---|
| dockerrunwrapper | DockerRunWrapper |
usdocker.runUsingCli(dockerrunwrapper)
Run a container based on the DockerRunWrapper definition
Kind: static method of usdocker
| Param | Type |
|---|---|
| dockerrunwrapper | DockerRunWrapper |
usdocker.exec(instance, cmd, callback)
Exec a container and attach a terminal
Kind: static method of usdocker
| Param | Type |
|---|---|
| instance | string |
| cmd | Array |
| callback |
Example
usdocker.exec('mysql-container', ['bash'], function(err) {
if (err) console.log(err);
// do something
});
usdocker.ask(question, defaultValue, optYes, optNo, yesFn, noFn)
Helper for ask a question
Kind: static method of usdocker
| Param | Type | Description |
|---|---|---|
| question | string |
|
| defaultValue | boolean |
|
| optYes | boolean |
|
| optNo | boolean |
|
| yesFn | Callback for the result in case of success | |
| noFn | Callback for the result in case of success |
usdocker.config(script) ⇒ Config
Return a new Config object
Kind: static method of usdocker
| Param |
|---|
| script |
usdocker.configGlobal() ⇒ Config
Return a new Config object with Global setup
Kind: static method of usdocker
usdocker.dockerRunWrapper() ⇒ DockerRunWrapper
Return a new DockerRunWrapper
Kind: static method of usdocker
usdocker.fsutil() ⇒ fsutil
Get an fsutil module
Kind: static method of usdocker
usdocker.getHostIpAddress() ⇒ Array
Get the IPAddress on the host system.
Kind: static method of usdocker
usdocker.getDockerInstance(host) ⇒ Docker
Static method to return an instance of a DockerWrapper
Kind: static method of usdocker
| Param | Type |
|---|---|
| host | string |
Config
Class to handle the configuration of the script
Kind: global class
- Config
- new Config(script, alternateHome)
- .reload()
- .save()
- .copyToUserDir(source) ⇒
boolean - .copyToDataDir(source) ⇒
boolean - .getUserDir(name) ⇒
string - .getDataDir() ⇒
string - .set(key, value)
- .setEmpty(key, value)
- .get(key, defaultValue) ⇒
* - .clear(key)
- .dump()
- .getLocalTimeZone() ⇒
string
new Config(script, alternateHome)
Constructor
| Param | Type | Description |
|---|---|---|
| script | string |
The script |
| alternateHome | string |
(optional) Setup an alternate home directory |
config.reload()
Force reload from disk
Kind: instance method of Config
config.save()
Save configuration to disk
Kind: instance method of Config
config.copyToUserDir(source) ⇒ boolean
Copy a folder from the script directory to the user directory
Kind: instance method of Config
| Param | Type | Description |
|---|---|---|
| source | string |
Path |
config.copyToDataDir(source) ⇒ boolean
Copy a folder from the script directory to the data directory
Kind: instance method of Config
| Param | Type | Description |
|---|---|---|
| source | string |
Path |
config.getUserDir(name) ⇒ string
Get the full path of the folder "name" in the user directory area
Kind: instance method of Config
| Param | Type |
|---|---|
| name | string |
config.getDataDir() ⇒ string
Get the full path of the data directory
Kind: instance method of Config
config.set(key, value)
Set a key/value pair into the config and save to the disk
Kind: instance method of Config
| Param | Type |
|---|---|
| key | string |
| value | string | array |
config.setEmpty(key, value)
Set a key/value pair into the config ONLY if does not exists and do nothing if exists.
Kind: instance method of Config
| Param | Type |
|---|---|
| key | string |
| value | string | array |
config.get(key, defaultValue) ⇒ *
Get a value defined by the key or the value defined in defaultValue if not exists
Kind: instance method of Config
| Param | Type |
|---|---|
| key | string |
| defaultValue | string | array |
config.clear(key)
Remove a key
Kind: instance method of Config
| Param | Type |
|---|---|
| key | string |
config.dump()
Dump the config
Kind: instance method of Config
config.getLocalTimeZone() ⇒ string
Get the time zone of the system
Kind: instance method of Config
DockerListWrapper
Wrapper for the "docker list" command line
Kind: global class
new DockerListWrapper(usdocker)
Constructor
| Param | Type |
|---|---|
| usdocker | usdocker |
dockerListWrapper.getAll(callback)
Get all containers (including the stopped)
Kind: instance method of DockerListWrapper
| Param |
|---|
| callback |
dockerListWrapper.getRunning(callback)
Get only the running containers
Kind: instance method of DockerListWrapper
| Param |
|---|
| callback |
dockerListWrapper.get(limit, filters, callback)
Get a container based on the filter
Kind: instance method of DockerListWrapper
| Param | Type | Description |
|---|---|---|
| limit | integer |
The maximum number of results |
| filters | string |
The filter '{"label": ["staging","env=green"]}' |
| callback |
DockerRunWrapper
Wrapper for the "docker run" command line
Kind: global class
- DockerRunWrapper
- new DockerRunWrapper(usdocker)
- .port(host, container) ⇒
Array|DockerRunWrapper - .volume(host, container) ⇒
Array|DockerRunWrapper - .link(source, target) ⇒
Array|DockerRunWrapper - .linkRunning(cb)
- .env(variable, value) ⇒
Array|DockerRunWrapper - .dockerParamSet(param) ⇒
Array|DockerRunWrapper - .dockerParamAdd(param) ⇒
Array|DockerRunWrapper - .isDetached(value) ⇒
boolean|DockerRunWrapper - .isInteractive(value) ⇒
boolean|DockerRunWrapper - .isRemove(value) ⇒
boolean|DockerRunWrapper - .containerName(value) ⇒
string|DockerRunWrapper - .imageName(value) ⇒
string|DockerRunWrapper - .commandParam(param) ⇒
Array|DockerRunWrapper - .buildConsole() ⇒
Array - .buildApi() ⇒
Array
new DockerRunWrapper(usdocker)
Construtor
| Param | Type |
|---|---|
| usdocker | usdocker |
dockerRunWrapper.port(host, container) ⇒ Array | DockerRunWrapper
Map the port. Equals to -p parameter
Kind: instance method of DockerRunWrapper
| Param | Type | Description |
|---|---|---|
| host | int |
Port on host (if empty returns the string "host:container" |
| container | int |
Port on container |
dockerRunWrapper.volume(host, container) ⇒ Array | DockerRunWrapper
Map the volume. Equals to -v parameter
Kind: instance method of DockerRunWrapper
| Param | Type | Description |
|---|---|---|
| host | string |
Path on the host (if empty returns the string "host:container") |
| container | string |
Path on container |
dockerRunWrapper.link(source, target) ⇒ Array | DockerRunWrapper
Create a link to an existing docker container. Equals to --link parameter
Kind: instance method of DockerRunWrapper
| Param | Type | Description |
|---|---|---|
| source | string |
Container name |
| target | string |
Link name |
dockerRunWrapper.linkRunning(cb)
Create a link with all running containers. Equals to --link parameter
Kind: instance method of DockerRunWrapper
| Param | Description |
|---|---|
| cb | The callback (async method); |
dockerRunWrapper.env(variable, value) ⇒ Array | DockerRunWrapper
Set an environment variable on the container. Equals to --env parameter
Kind: instance method of DockerRunWrapper
| Param | Type | Description |
|---|---|---|
| variable | string |
(if empty returns the string "variable=value") |
| value | string |
dockerRunWrapper.dockerParamSet(param) ⇒ Array | DockerRunWrapper
Kind: instance method of DockerRunWrapper
| Param |
|---|
| param |
dockerRunWrapper.dockerParamAdd(param) ⇒ Array | DockerRunWrapper
Kind: instance method of DockerRunWrapper
| Param |
|---|
| param |
dockerRunWrapper.isDetached(value) ⇒ boolean | DockerRunWrapper
Defines if the container will be detached. Equals to -d
Kind: instance method of DockerRunWrapper
| Param | Type | Description |
|---|---|---|
| value | boolean |
(if empty returns true or false) |
dockerRunWrapper.isInteractive(value) ⇒ boolean | DockerRunWrapper
Defines if the container will be a terminal interactive. Equals to -it parameter.
Kind: instance method of DockerRunWrapper
| Param | Type | Description |
|---|---|---|
| value | boolean |
(if empty returns true or false) |
dockerRunWrapper.isRemove(value) ⇒ boolean | DockerRunWrapper
Defines if the container removed on the end. Equals to --rm parameter.
Kind: instance method of DockerRunWrapper
| Param | Type | Description |
|---|---|---|
| value | boolean |
(if empty returns true or false) |
dockerRunWrapper.containerName(value) ⇒ string | DockerRunWrapper
Defines the container name. Equals to --name parameter.
Kind: instance method of DockerRunWrapper
| Param | Type | Description |
|---|---|---|
| value | string |
(if empty returns the container name) |
dockerRunWrapper.imageName(value) ⇒ string | DockerRunWrapper
Defines the image name.
Kind: instance method of DockerRunWrapper
| Param | Type | Description |
|---|---|---|
| value | string |
(if empty returns the image name) |
dockerRunWrapper.commandParam(param) ⇒ Array | DockerRunWrapper
Defines the command paramters.
Kind: instance method of DockerRunWrapper
| Param | Type | Description |
|---|---|---|
| param | string |
(if empty returns the array of parameters) |
dockerRunWrapper.buildConsole() ⇒ Array
Return the full command line
Kind: instance method of DockerRunWrapper
dockerRunWrapper.buildApi() ⇒ Array
Returns the object to be used in the docker API.
Kind: instance method of DockerRunWrapper
DockerWrapper
Abstract class for implement docker wrapper class
new DockerWrapper(usdocker)
Constructor
| Param | Type |
|---|---|
| usdocker | usdocker |
Output
Handle the output of the modules instead to console.log
Kind: global class
new Output(verbosity)
Constructor
| Param | Type | Description |
|---|---|---|
| verbosity | boolean |
True is verbosity |
output.print(normal, verbose)
Print a message according to the verbosity.
Kind: instance method of Output
| Param | Type | Description |
|---|---|---|
| normal | string |
Print this string if verbositity is false |
| verbose | string |
Print this string if verbositity is true. If null, return the "normal" string |
output.warn(normal, verbose)
Output a warn message
Kind: instance method of Output
| Param | Type | Description |
|---|---|---|
| normal | string |
Print this string if verbositity is false |
| verbose | string |
Print this string if verbositity is true. If null, return the "normal" string |
output.printErr(err)
Output the Error.message. If verbosity is true, return the stack trace also
Kind: instance method of Output
| Param | Type |
|---|---|
| err | Error |
ScriptContainer
Handle where to locate and how to load and run the string
Kind: global class
- ScriptContainer
- new ScriptContainer(config, search)
- .isLoaded() ⇒
boolean - .load(force) ⇒
true|false|null - .loadModules(item)
- .existsScript(script) ⇒
boolean - .availableScripts() ⇒
Array - .availableCommands(script) ⇒
* - .getScript(script) ⇒
Object|* - .cc(name)
new ScriptContainer(config, search)
Construtor
| Param | Type | Description |
|---|---|---|
| config | Config |
|
| search | string |
(optional) |
scriptContainer.isLoaded() ⇒ boolean
Check if the script container data is loaded
Kind: instance method of ScriptContainer
scriptContainer.load(force) ⇒ true | false | null
Load the string container data from the cache or create one if does not exists.
Kind: instance method of ScriptContainer
Returns: true | false | null - True if it is created; False if it is loaded; null if get from cache.
| Param | Type | Description |
|---|---|---|
| force | boolean |
If force always will be recreate the cache. |
scriptContainer.loadModules(item)
Search for a module and create the instance.
Kind: instance method of ScriptContainer
| Param |
|---|
| item |
scriptContainer.existsScript(script) ⇒ boolean
Check if the script exists
Kind: instance method of ScriptContainer
| Param | Type |
|---|---|
| script | string |
scriptContainer.availableScripts() ⇒ Array
Return the list of available scripts
Kind: instance method of ScriptContainer
scriptContainer.availableCommands(script) ⇒ *
Return the list of the available commands in the script;
Kind: instance method of ScriptContainer
| Param | Type |
|---|---|
| script | string |
scriptContainer.getScript(script) ⇒ Object | *
Load a script into the memory
Kind: instance method of ScriptContainer
| Param | Type |
|---|---|
| script | string |
scriptContainer.cc(name)
Convert a parameter 'name-second' into a camel case "nameSecond"
Kind: instance method of ScriptContainer
| Param | Type |
|---|---|
| name | string |