2017-02-11 22:37:01 +00:00
|
|
|
import * as plugins from './npmdocker.plugins'
|
|
|
|
import * as paths from './npmdocker.paths'
|
|
|
|
|
|
|
|
// modules
|
|
|
|
import * as ConfigModule from './npmdocker.config'
|
|
|
|
import * as DockerModule from './npmdocker.docker'
|
|
|
|
|
|
|
|
let npmdockerCli = new plugins.smartcli.Smartcli()
|
|
|
|
|
|
|
|
plugins.beautylog.ora.start()
|
|
|
|
export let run = () => {
|
|
|
|
npmdockerCli.standardTask().then(argvArg => {
|
|
|
|
let done = plugins.q.defer()
|
|
|
|
ConfigModule.run()
|
|
|
|
.then(DockerModule.run)
|
|
|
|
.then((configArg) => {
|
|
|
|
done.resolve(configArg)
|
|
|
|
})
|
|
|
|
return done.promise
|
|
|
|
}).then((configArg: ConfigModule.IConfig) => {
|
|
|
|
if (configArg.exitCode === 0) {
|
|
|
|
plugins.beautylog.success('container ended all right!')
|
|
|
|
} else {
|
|
|
|
plugins.beautylog.error('container ended with error!')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
npmdockerCli.addCommand('clean').then(argvArg => {
|
|
|
|
plugins.beautylog.ora.text('cleaning up docker env...')
|
|
|
|
if (argvArg.all) {
|
|
|
|
plugins.beautylog.ora.text('killing any running docker containers...')
|
|
|
|
plugins.shelljs.exec(`docker kill $(docker ps -q)`)
|
|
|
|
|
|
|
|
plugins.beautylog.ora.text('removing stopped containers...')
|
|
|
|
plugins.shelljs.exec(`docker rm $(docker ps -a -q)`)
|
|
|
|
|
|
|
|
plugins.beautylog.ora.text('removing images...')
|
|
|
|
plugins.shelljs.exec(`docker rmi $(docker images -q -f dangling=true)`)
|
|
|
|
|
|
|
|
plugins.beautylog.ora.text('removing all other images...')
|
2017-02-12 14:17:59 +00:00
|
|
|
plugins.shelljs.exec(`docker rmi $(docker images -a -q)`)
|
|
|
|
|
|
|
|
plugins.beautylog.ora.text('removing all volumes...')
|
|
|
|
plugins.shelljs.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`)
|
2017-02-11 22:37:01 +00:00
|
|
|
}
|
|
|
|
plugins.beautylog.ora.endOk('docker environment now is clean!')
|
|
|
|
})
|
|
|
|
|
|
|
|
npmdockerCli.startParse()
|
|
|
|
}
|