2018-05-18 11:09:14 +00:00
|
|
|
import * as plugins from './npmdocker.plugins';
|
|
|
|
import * as paths from './npmdocker.paths';
|
2017-02-11 22:37:01 +00:00
|
|
|
|
|
|
|
// modules
|
2018-05-18 11:09:14 +00:00
|
|
|
import * as ConfigModule from './npmdocker.config';
|
|
|
|
import * as DockerModule from './npmdocker.docker';
|
2017-04-21 11:44:18 +00:00
|
|
|
|
2018-05-18 11:09:14 +00:00
|
|
|
let npmdockerCli = new plugins.smartcli.Smartcli();
|
2017-02-11 22:37:01 +00:00
|
|
|
|
|
|
|
export let run = () => {
|
2018-05-18 11:17:52 +00:00
|
|
|
npmdockerCli.standardTask().subscribe(async argvArg => {
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.figletSync('npmdocker');
|
|
|
|
let configArg = await ConfigModule.run().then(DockerModule.run);
|
2017-02-11 22:37:01 +00:00
|
|
|
if (configArg.exitCode === 0) {
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.success('container ended all right!');
|
2017-02-11 22:37:01 +00:00
|
|
|
} else {
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.error(`container ended with error! Exit Code is ${configArg.exitCode}`);
|
|
|
|
process.exit(1);
|
2017-02-11 22:37:01 +00:00
|
|
|
}
|
2018-05-18 11:09:14 +00:00
|
|
|
});
|
2017-02-11 22:37:01 +00:00
|
|
|
|
2017-07-16 11:58:41 +00:00
|
|
|
/**
|
|
|
|
* this command is executed inside docker and meant for use from outside docker
|
|
|
|
*/
|
2018-05-18 11:17:52 +00:00
|
|
|
npmdockerCli.addCommand('runinside').subscribe(async argvArg => {
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.ok('Allright. We are now in Docker!');
|
|
|
|
plugins.beautylog.log('now trying to run your specified command');
|
|
|
|
let configArg = await ConfigModule.run();
|
2018-09-16 19:08:13 +00:00
|
|
|
const smartshellInstance = new plugins.smartshell.Smartshell({
|
|
|
|
executor: 'bash'
|
2018-10-29 00:07:39 +00:00
|
|
|
});
|
2018-09-16 19:08:13 +00:00
|
|
|
await smartshellInstance.exec(configArg.command).then(response => {
|
2017-04-02 12:48:23 +00:00
|
|
|
if (response.exitCode !== 0) {
|
2018-05-18 11:09:14 +00:00
|
|
|
process.exit(1);
|
2017-04-02 12:48:23 +00:00
|
|
|
}
|
2018-05-18 11:09:14 +00:00
|
|
|
});
|
|
|
|
});
|
2017-04-02 12:48:23 +00:00
|
|
|
|
2018-05-18 11:17:52 +00:00
|
|
|
npmdockerCli.addCommand('clean').subscribe(async argvArg => {
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.ora.start();
|
|
|
|
plugins.beautylog.ora.text('cleaning up docker env...');
|
2017-02-11 22:37:01 +00:00
|
|
|
if (argvArg.all) {
|
2018-09-16 19:08:13 +00:00
|
|
|
const smartshellInstance = new plugins.smartshell.Smartshell({
|
|
|
|
executor: 'bash'
|
2018-10-29 00:07:39 +00:00
|
|
|
});
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.ora.text('killing any running docker containers...');
|
2018-09-16 19:08:13 +00:00
|
|
|
await smartshellInstance.exec(`docker kill $(docker ps -q)`);
|
2017-02-11 22:37:01 +00:00
|
|
|
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.ora.text('removing stopped containers...');
|
2018-09-16 19:08:13 +00:00
|
|
|
await smartshellInstance.exec(`docker rm $(docker ps -a -q)`);
|
2017-02-11 22:37:01 +00:00
|
|
|
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.ora.text('removing images...');
|
2018-10-28 20:40:31 +00:00
|
|
|
await smartshellInstance.exec(`docker rmi -f $(docker images -q -f dangling=true)`);
|
2017-02-11 22:37:01 +00:00
|
|
|
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.ora.text('removing all other images...');
|
2018-09-16 19:08:13 +00:00
|
|
|
await smartshellInstance.exec(`docker rmi $(docker images -a -q)`);
|
2017-02-12 14:17:59 +00:00
|
|
|
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.ora.text('removing all volumes...');
|
2018-09-16 19:08:13 +00:00
|
|
|
await smartshellInstance.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`);
|
2017-02-11 22:37:01 +00:00
|
|
|
}
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.ora.endOk('docker environment now is clean!');
|
|
|
|
});
|
2017-02-11 22:37:01 +00:00
|
|
|
|
2018-05-18 11:17:52 +00:00
|
|
|
npmdockerCli.addCommand('speedtest').subscribe(async argvArg => {
|
2018-09-16 19:08:13 +00:00
|
|
|
const smartshellInstance = new plugins.smartshell.Smartshell({
|
|
|
|
executor: 'bash'
|
2018-10-29 00:07:39 +00:00
|
|
|
});
|
2018-05-18 11:09:14 +00:00
|
|
|
plugins.beautylog.figletSync('npmdocker');
|
|
|
|
plugins.beautylog.ok('Starting speedtest');
|
2018-09-16 19:08:13 +00:00
|
|
|
await smartshellInstance.exec(
|
2018-05-18 11:09:14 +00:00
|
|
|
`docker pull tianon/speedtest && docker run --rm tianon/speedtest`
|
|
|
|
);
|
|
|
|
});
|
2017-02-12 15:04:27 +00:00
|
|
|
|
2018-05-18 11:09:14 +00:00
|
|
|
npmdockerCli.startParse();
|
|
|
|
};
|