Compare commits

..

No commits in common. "master" and "v1.2.23" have entirely different histories.

21 changed files with 1395 additions and 27540 deletions

27
.gitignore vendored
View File

@ -1,23 +1,8 @@
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/ node_modules/
coverage/
pages/
public/
# caches test/
.yarn/ assets/
.cache/ .nogit/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom
test

View File

@ -57,8 +57,8 @@ pages:
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-node:npmci
stage: pages stage: pages
script: script:
- npmci command npm install -g @gitzone/tsdoc - npmci command yarn global add npmpage
- npmci command tsdoc - npmci command npmpage
only: only:
- tags - tags
tags: tags:

View File

@ -1,3 +0,0 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}

67
README.md Normal file
View File

@ -0,0 +1,67 @@
# npmdocker
develop npm modules cross platform with docker
## Availabililty
[![npm](https://gitzone.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/npmdocker)
[![git](https://gitzone.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/gitzone/npmdocker)
[![git](https://gitzone.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/gitzone/npmdocker)
[![docs](https://gitzone.gitlab.io/assets/repo-button-docs.svg)](https://gitzone.gitlab.io/npmdocker/)
## Status for master
[![build status](https://GitLab.com/gitzone/npmdocker/badges/master/build.svg)](https://GitLab.com/gitzone/npmdocker/commits/master)
[![coverage report](https://GitLab.com/gitzone/npmdocker/badges/master/coverage.svg)](https://GitLab.com/gitzone/npmdocker/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/npmdocker.svg)](https://www.npmjs.com/package/npmdocker)
[![Dependency Status](https://david-dm.org/gitzonetools/npmdocker.svg)](https://david-dm.org/gitzonetools/npmdocker)
[![bitHound Dependencies](https://www.bithound.io/github/gitzonetools/npmdocker/badges/dependencies.svg)](https://www.bithound.io/github/gitzonetools/npmdocker/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/gitzonetools/npmdocker/badges/code.svg)](https://www.bithound.io/github/gitzonetools/npmdocker)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
Use TypeScript for best in class instellisense.
### Why does this package exist?
Sometimes you want a clean and fresh linux environment everytime you test your package.
Usually this is the default i CI, but locally behaviour tends to defer.
### Where does it work
The npmdocker package works in everywhere where the docker cli is available. e.g.:
* docker toolbox
* native docker application
* docker in docker
* mounted docker.sock
### How do I use it?
create a npmextra.json in the project's root directory
```json
{
"npmdocker": {
"baseImage": "hosttoday/ht-docker-node:npmts",
"command": "npmci test stable",
"dockerSock": false
}
}
```
| option | description |
| ----------- | ------------------------------------------------------------------------------------- |
| baseImage | the base image that is the context for your project |
| command | the cli command to run within the the project's directory inside the docker container |
| dockersSock | wether or not the testcontainer will have access to the docker.sock of the host |
For further information read the linked docs at the top of this README.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://gitzone.gitlab.io/assets/repo-footer.svg)](https://git.zone)

View File

@ -1,6 +1,6 @@
FROM hosttoday/ht-docker-node:npmci FROM hosttoday/ht-docker-node:npmci
RUN yarn global add @gitzone/tsdocker RUN yarn global add npmdocker
COPY ./ /workspace COPY ./ /workspace
WORKDIR /workspace WORKDIR /workspace
ENV CI=true ENV CI=true
CMD ["tsdocker","runinside"]; CMD ["npmdocker","runinside"];

1
docs/index.md Normal file
View File

@ -0,0 +1 @@
Docs for npmpage coming soon.

View File

@ -4,17 +4,10 @@
"cli": true "cli": true
}, },
"npmci": { "npmci": {
"npmGlobalTools": [], "npmGlobalTools": [
"@gitzone/npmts",
"ts-node"
],
"npmAccessLevel": "public" "npmAccessLevel": "public"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "gitzone",
"gitrepo": "npmdocker",
"shortDescription": "develop npm modules cross platform with docker",
"npmPackagename": "@gitzone/npmdocker",
"license": "MIT"
}
} }
} }

28439
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +1,18 @@
{ {
"name": "@gitzone/tsdocker", "name": "@gitzone/npmdocker",
"version": "1.2.40", "version": "1.2.23",
"private": false,
"description": "develop npm modules cross platform with docker", "description": "develop npm modules cross platform with docker",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"bin": { "bin": {
"tsdocker": "cli.js" "npmdocker": "cli.js"
}, },
"scripts": { "scripts": {
"test": "(npm run clean && npm run setupCheck && npm run testStandard && npm run testSpeed)", "test": "(npm run clean && npm run setupCheck && npm run testStandard && npm run testSpeed)",
"build": "(tsbuild)", "build": "tsbuild",
"testStandard": "(cd test/ && node ../cli.ts.js)", "testStandard": "(cd test/ && node ../cli.ts.js)",
"testSpeed": "(cd test/ && node ../cli.ts.js speedtest)", "testSpeed": "(cd test/ && node ../cli.ts.js speedtest)",
"testClean": "(cd test/ && node ../cli.ts.js clean --all)", "testClean": "(cd test/ && node ../cli.ts.js clean --all)",
"testVscode": "(cd test/ && node ../cli.ts.js vscode)",
"clean": "(rm -rf test/)", "clean": "(rm -rf test/)",
"compile": "(npmts --notest)", "compile": "(npmts --notest)",
"setupCheck": "(git clone https://gitlab.com/sandboxzone/sandbox-npmts.git test/)" "setupCheck": "(git clone https://gitlab.com/sandboxzone/sandbox-npmts.git test/)"
@ -33,28 +31,24 @@
}, },
"homepage": "https://gitlab.com/gitzone/npmdocker#README", "homepage": "https://gitlab.com/gitzone/npmdocker#README",
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.27", "@gitzone/tsbuild": "^2.0.22",
"@gitzone/tsrun": "^1.2.17", "@gitzone/tsrun": "^1.1.12",
"@gitzone/tstest": "^1.0.57", "@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.2.14", "@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^16.10.1", "@types/node": "^10.9.4"
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/npmextra": "^3.0.9", "@pushrocks/npmextra": "^3.0.1",
"@pushrocks/projectinfo": "^4.0.5", "@pushrocks/projectinfo": "^4.0.2",
"@pushrocks/qenv": "^4.0.10", "@pushrocks/qenv": "^2.0.2",
"@pushrocks/smartanalytics": "^2.0.15", "@pushrocks/smartcli": "^3.0.4",
"@pushrocks/smartcli": "^3.0.14", "@pushrocks/smartfile": "^6.0.8",
"@pushrocks/smartfile": "^8.0.10", "@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartlog": "^2.0.44", "@pushrocks/smartshell": "^2.0.6",
"@pushrocks/smartlog-destination-local": "^8.0.8", "@pushrocks/smartstring": "^3.0.4",
"@pushrocks/smartlog-source-ora": "^1.0.9", "@types/shelljs": "^0.8.0",
"@pushrocks/smartopen": "^1.0.22", "beautylog": "^6.1.10",
"@pushrocks/smartpromise": "^3.1.6", "smartanalytics": "^2.0.9"
"@pushrocks/smartshell": "^2.0.28", },
"@pushrocks/smartstring": "^3.0.24", "private": true
"@types/shelljs": "^0.8.9"
}
} }

20
ts/analytics.ts Normal file
View File

@ -0,0 +1,20 @@
/**
* smartanalytics:
* We count executions of this tool to keep track which of our tools are really used.
* This insight is used to plan spending our limited resources for improving them.
* Any submitted analytics data is fully anonymized (no Ips or any other personal information is tracked).
* Feel free to dig into the smartanalytics package, if you are interested in how it works.
* Our privacy policy can be found here: https://lossless.gmbh/privacy.html
* The privacy policy is also linked in the readme, so we hope this behaviour does not come as a surprise to you.
* Have a nice day and regards
* Your Open Source team at Lossless GmbH :)
*/
import * as smartanalytics from 'smartanalytics';
let npmdockerAnalytics = new smartanalytics.Analytics({
apiEndPoint: 'https://pubapi.lossless.one',
appName: 'npmdocker',
projectId: 'gitzone'
});
npmdockerAnalytics.recordEvent('npmtoolexecution', {
somedata: 'somedata'
});

View File

@ -1,4 +1,5 @@
import * as plugins from './tsdocker.plugins'; import './analytics';
import * as cli from './tsdocker.cli'; import * as plugins from './npmdocker.plugins';
import * as cli from './npmdocker.cli';
cli.run(); cli.run();

76
ts/npmdocker.cli.ts Normal file
View File

@ -0,0 +1,76 @@
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();
export let run = () => {
npmdockerCli.standardTask().subscribe(async argvArg => {
plugins.beautylog.figletSync('npmdocker');
let configArg = await ConfigModule.run().then(DockerModule.run);
if (configArg.exitCode === 0) {
plugins.beautylog.success('container ended all right!');
} else {
plugins.beautylog.error(`container ended with error! Exit Code is ${configArg.exitCode}`);
process.exit(1);
}
});
/**
* this command is executed inside docker and meant for use from outside docker
*/
npmdockerCli.addCommand('runinside').subscribe(async argvArg => {
plugins.beautylog.ok('Allright. We are now in Docker!');
plugins.beautylog.log('now trying to run your specified command');
let configArg = await ConfigModule.run();
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
})
await smartshellInstance.exec(configArg.command).then(response => {
if (response.exitCode !== 0) {
process.exit(1);
}
});
});
npmdockerCli.addCommand('clean').subscribe(async argvArg => {
plugins.beautylog.ora.start();
plugins.beautylog.ora.text('cleaning up docker env...');
if (argvArg.all) {
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
})
plugins.beautylog.ora.text('killing any running docker containers...');
await smartshellInstance.exec(`docker kill $(docker ps -q)`);
plugins.beautylog.ora.text('removing stopped containers...');
await smartshellInstance.exec(`docker rm $(docker ps -a -q)`);
plugins.beautylog.ora.text('removing images...');
await smartshellInstance.exec(`docker rmi $(docker images -q -f dangling=true)`);
plugins.beautylog.ora.text('removing all other images...');
await smartshellInstance.exec(`docker rmi $(docker images -a -q)`);
plugins.beautylog.ora.text('removing all volumes...');
await smartshellInstance.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`);
}
plugins.beautylog.ora.endOk('docker environment now is clean!');
});
npmdockerCli.addCommand('speedtest').subscribe(async argvArg => {
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
})
plugins.beautylog.figletSync('npmdocker');
plugins.beautylog.ok('Starting speedtest');
await smartshellInstance.exec(
`docker pull tianon/speedtest && docker run --rm tianon/speedtest`
);
});
npmdockerCli.startParse();
};

40
ts/npmdocker.config.ts Normal file
View File

@ -0,0 +1,40 @@
import * as plugins from './npmdocker.plugins';
import * as paths from './npmdocker.paths';
// interfaces
import { IKeyValueObject } from '@pushrocks/qenv';
export interface IConfig {
baseImage: string;
command: string;
dockerSock: boolean;
exitCode?: number;
keyValueObjectArray: IKeyValueObject[];
}
let getQenvKeyValueObject = async () => {
let qenvKeyValueObjectArray: IKeyValueObject[];
if (plugins.smartfile.fs.fileExistsSync(plugins.path.join(paths.cwd, 'qenv.yml'))) {
qenvKeyValueObjectArray = new plugins.qenv.Qenv(paths.cwd, '.nogit/').keyValueObjectArray;
} else {
qenvKeyValueObjectArray = [];
}
return qenvKeyValueObjectArray;
};
let buildConfig = async (qenvKeyValueObjectArrayArg: IKeyValueObject[]) => {
let npmextra = new plugins.npmextra.Npmextra(paths.cwd);
let config = npmextra.dataFor<IConfig>('npmdocker', {
baseImage: 'hosttoday/ht-docker-node:npmdocker',
init: 'rm -rf node_nodules/ && yarn install',
command: 'npmci npm test',
dockerSock: false,
keyValueObjectArray: qenvKeyValueObjectArrayArg
});
return config;
};
export let run = async (): Promise<IConfig> => {
let config = await getQenvKeyValueObject().then(buildConfig);
return config;
};

View File

@ -1,22 +1,20 @@
import * as plugins from './tsdocker.plugins'; import * as plugins from './npmdocker.plugins';
import * as paths from './tsdocker.paths'; import * as paths from './npmdocker.paths';
import * as snippets from './tsdocker.snippets'; import * as snippets from './npmdocker.snippets';
import { logger, ora } from './tsdocker.logging';
const smartshellInstance = new plugins.smartshell.Smartshell({ const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash' executor: 'bash'
}); })
// interfaces // interfaces
import { IConfig } from './tsdocker.config'; import { IConfig } from './npmdocker.config';
let config: IConfig; let config: IConfig;
/** /**
* the docker data used to build the internal testing container * the docker data used to build the internal testing container
*/ */
const dockerData = { let dockerData = {
imageTag: 'npmdocker-temp-image:latest', imageTag: 'npmdocker-temp-image:latest',
containerName: 'npmdocker-temp-container', containerName: 'npmdocker-temp-container',
dockerProjectMountString: '', dockerProjectMountString: '',
@ -27,12 +25,12 @@ const dockerData = {
/** /**
* check if docker is available * check if docker is available
*/ */
const checkDocker = () => { let checkDocker = () => {
const done = plugins.smartpromise.defer(); let done = plugins.smartpromise.defer();
ora.text('checking docker...'); plugins.beautylog.ora.text('checking docker...');
if (smartshellInstance.exec('which docker')) { if (smartshellInstance.exec('which docker')) {
logger.log('ok', 'Docker found!'); plugins.beautylog.ok('Docker found!');
done.resolve(); done.resolve();
} else { } else {
done.reject(new Error('docker not found on this machine')); done.reject(new Error('docker not found on this machine'));
@ -43,18 +41,18 @@ const checkDocker = () => {
/** /**
* builds the Dockerfile according to the config in the project * builds the Dockerfile according to the config in the project
*/ */
const buildDockerFile = () => { let buildDockerFile = () => {
const done = plugins.smartpromise.defer(); let done = plugins.smartpromise.defer();
ora.text('building Dockerfile...'); plugins.beautylog.ora.text('building Dockerfile...');
const dockerfile: string = snippets.dockerfileSnippet({ let dockerfile: string = snippets.dockerfileSnippet({
baseImage: config.baseImage, baseImage: config.baseImage,
command: config.command command: config.command
}); });
logger.log('info', `Base image is: ${config.baseImage}`); plugins.beautylog.info(`Base image is: ${config.baseImage}`);
logger.log('info', `Command is: ${config.command}`); plugins.beautylog.info(`Command is: ${config.command}`);
plugins.smartfile.memory.toFsSync(dockerfile, plugins.path.join(paths.cwd, 'npmdocker')); plugins.smartfile.memory.toFsSync(dockerfile, plugins.path.join(paths.cwd, 'npmdocker'));
logger.log('ok', 'Dockerfile created!'); plugins.beautylog.ok('Dockerfile created!');
ora.stop(); plugins.beautylog.ora.stop();
done.resolve(); done.resolve();
return done.promise; return done.promise;
}; };
@ -62,21 +60,21 @@ const buildDockerFile = () => {
/** /**
* builds the Dockerimage from the built Dockerfile * builds the Dockerimage from the built Dockerfile
*/ */
const buildDockerImage = async () => { let buildDockerImage = async () => {
logger.log('info', 'pulling latest base image from registry...'); plugins.beautylog.info('pulling latest base image from registry...');
await smartshellInstance.exec(`docker pull ${config.baseImage}`); await smartshellInstance.exec(`docker pull ${config.baseImage}`);
ora.text('building Dockerimage...'); plugins.beautylog.ora.text('building Dockerimage...');
const execResult = await smartshellInstance.execSilent( let execResult = await smartshellInstance.execSilent(
`docker build -f npmdocker -t ${dockerData.imageTag} ${paths.cwd}` `docker build -f npmdocker -t ${dockerData.imageTag} ${paths.cwd}`
); );
if (execResult.exitCode !== 0) { if (execResult.exitCode !== 0) {
console.log(execResult.stdout); console.log(execResult.stdout);
process.exit(1); process.exit(1);
} }
logger.log('ok', 'Dockerimage built!'); plugins.beautylog.ok('Dockerimage built!');
}; };
const buildDockerProjectMountString = async () => { let buildDockerProjectMountString = async () => {
if (process.env.CI !== 'true') { if (process.env.CI !== 'true') {
dockerData.dockerProjectMountString = `-v ${paths.cwd}:/workspace`; dockerData.dockerProjectMountString = `-v ${paths.cwd}:/workspace`;
} }
@ -85,17 +83,17 @@ const buildDockerProjectMountString = async () => {
/** /**
* builds an environment string that docker cli understands * builds an environment string that docker cli understands
*/ */
const buildDockerEnvString = async () => { let buildDockerEnvString = async () => {
for (const key of Object.keys(config.keyValueObject)) { for (let keyValueObjectArg of config.keyValueObjectArray) {
const envString = (dockerData.dockerEnvString = let envString = (dockerData.dockerEnvString =
dockerData.dockerEnvString + `-e ${key}=${config.keyValueObject[key]} `); dockerData.dockerEnvString + `-e ${keyValueObjectArg.key}=${keyValueObjectArg.value} `);
} }
}; };
/** /**
* creates string to mount the docker.sock inside the testcontainer * creates string to mount the docker.sock inside the testcontainer
*/ */
const buildDockerSockString = async () => { let buildDockerSockString = async () => {
if (config.dockerSock) { if (config.dockerSock) {
dockerData.dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`; dockerData.dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`;
} }
@ -104,11 +102,11 @@ const buildDockerSockString = async () => {
/** /**
* creates a container by running the built Dockerimage * creates a container by running the built Dockerimage
*/ */
const runDockerImage = async () => { let runDockerImage = async () => {
const done = plugins.smartpromise.defer(); let done = plugins.smartpromise.defer();
ora.text('starting Container...'); plugins.beautylog.ora.text('starting Container...');
ora.stop(); plugins.beautylog.ora.end();
logger.log('info', 'now running Dockerimage'); plugins.beautylog.log('now running Dockerimage');
config.exitCode = (await smartshellInstance.exec( config.exitCode = (await smartshellInstance.exec(
`docker run ${dockerData.dockerProjectMountString} ${dockerData.dockerSockString} ${ `docker run ${dockerData.dockerProjectMountString} ${dockerData.dockerSockString} ${
dockerData.dockerEnvString dockerData.dockerEnvString
@ -119,14 +117,14 @@ const runDockerImage = async () => {
/** /**
* cleans up: deletes the test container * cleans up: deletes the test container
*/ */
const deleteDockerContainer = async () => { let deleteDockerContainer = async () => {
await smartshellInstance.execSilent(`docker rm -f ${dockerData.containerName}`); await smartshellInstance.execSilent(`docker rm -f ${dockerData.containerName}`);
}; };
/** /**
* cleans up deletes the test image * cleans up deletes the test image
*/ */
const deleteDockerImage = async () => { let deleteDockerImage = async () => {
await smartshellInstance.execSilent(`docker rmi ${dockerData.imageTag}`).then(async response => { await smartshellInstance.execSilent(`docker rmi ${dockerData.imageTag}`).then(async response => {
if (response.exitCode !== 0) { if (response.exitCode !== 0) {
console.log(response.stdout); console.log(response.stdout);
@ -134,26 +132,27 @@ const deleteDockerImage = async () => {
}); });
}; };
const preClean = async () => { let preClean = async () => {
await deleteDockerImage() await deleteDockerImage()
.then(deleteDockerContainer) .then(deleteDockerContainer)
.then(async () => { .then(async () => {
logger.log('ok', 'ensured clean Docker environment!'); plugins.beautylog.ok('ensured clean Docker environment!');
}); });
}; };
const postClean = async () => { let postClean = async () => {
await deleteDockerContainer() await deleteDockerContainer()
.then(deleteDockerImage) .then(deleteDockerImage)
.then(async () => { .then(async () => {
logger.log('ok', 'cleaned up!'); plugins.beautylog.ok('cleaned up!');
}); });
plugins.smartfile.fs.removeSync(paths.npmdockerFile); plugins.smartfile.fs.removeSync(paths.npmdockerFile);
}; };
export let run = async (configArg: IConfig): Promise<IConfig> => { export let run = async (configArg: IConfig): Promise<IConfig> => {
plugins.beautylog.ora.start();
config = configArg; config = configArg;
const resultConfig = await checkDocker() let resultConfig = await checkDocker()
.then(preClean) .then(preClean)
.then(buildDockerFile) .then(buildDockerFile)
.then(buildDockerImage) .then(buildDockerImage)

View File

@ -1,4 +1,4 @@
import * as plugins from './tsdocker.plugins'; import * as plugins from './npmdocker.plugins';
// directories // directories
export let cwd = process.cwd(); export let cwd = process.cwd();

View File

@ -1,4 +1,4 @@
// pushrocks scope import * as beautylog from 'beautylog';
import * as npmextra from '@pushrocks/npmextra'; import * as npmextra from '@pushrocks/npmextra';
import * as path from 'path'; import * as path from 'path';
import * as projectinfo from '@pushrocks/projectinfo'; import * as projectinfo from '@pushrocks/projectinfo';
@ -6,14 +6,11 @@ import * as smartpromise from '@pushrocks/smartpromise';
import * as qenv from '@pushrocks/qenv'; import * as qenv from '@pushrocks/qenv';
import * as smartcli from '@pushrocks/smartcli'; import * as smartcli from '@pushrocks/smartcli';
import * as smartfile from '@pushrocks/smartfile'; import * as smartfile from '@pushrocks/smartfile';
import * as smartlog from '@pushrocks/smartlog';
import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
import * as smartlogSouceOra from '@pushrocks/smartlog-source-ora';
import * as smartopen from '@pushrocks/smartopen';
import * as smartshell from '@pushrocks/smartshell'; import * as smartshell from '@pushrocks/smartshell';
import * as smartstring from '@pushrocks/smartstring'; import * as smartstring from '@pushrocks/smartstring';
export { export {
beautylog,
npmextra, npmextra,
path, path,
projectinfo, projectinfo,
@ -21,10 +18,6 @@ export {
qenv, qenv,
smartcli, smartcli,
smartfile, smartfile,
smartlog,
smartlogDestinationLocal,
smartlogSouceOra,
smartopen,
smartshell, smartshell,
smartstring smartstring
}; };

View File

@ -1,4 +1,4 @@
import * as plugins from './tsdocker.plugins'; import * as plugins from './npmdocker.plugins';
export interface IDockerfileSnippet { export interface IDockerfileSnippet {
baseImage: string; baseImage: string;

View File

@ -1,90 +0,0 @@
import * as plugins from './tsdocker.plugins';
import * as paths from './tsdocker.paths';
// modules
import * as ConfigModule from './tsdocker.config';
import * as DockerModule from './tsdocker.docker';
import { logger, ora } from './tsdocker.logging';
const tsdockerCli = new plugins.smartcli.Smartcli();
export let run = () => {
tsdockerCli.standardTask().subscribe(async argvArg => {
const configArg = await ConfigModule.run().then(DockerModule.run);
if (configArg.exitCode === 0) {
logger.log('success', 'container ended all right!');
} else {
logger.log('error', `container ended with error! Exit Code is ${configArg.exitCode}`);
process.exit(1);
}
});
/**
* this command is executed inside docker and meant for use from outside docker
*/
tsdockerCli.addCommand('runinside').subscribe(async argvArg => {
logger.log('ok', 'Allright. We are now in Docker!');
ora.text('now trying to run your specified command');
const configArg = await ConfigModule.run();
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
ora.stop();
await smartshellInstance.exec(configArg.command).then(response => {
if (response.exitCode !== 0) {
process.exit(1);
}
});
});
tsdockerCli.addCommand('clean').subscribe(async argvArg => {
ora.text('cleaning up docker env...');
if (argvArg.all) {
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
ora.text('killing any running docker containers...');
await smartshellInstance.exec(`docker kill $(docker ps -q)`);
ora.text('removing stopped containers...');
await smartshellInstance.exec(`docker rm $(docker ps -a -q)`);
ora.text('removing images...');
await smartshellInstance.exec(`docker rmi -f $(docker images -q -f dangling=true)`);
ora.text('removing all other images...');
await smartshellInstance.exec(`docker rmi $(docker images -a -q)`);
ora.text('removing all volumes...');
await smartshellInstance.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`);
}
ora.finishSuccess('docker environment now is clean!');
});
tsdockerCli.addCommand('speedtest').subscribe(async argvArg => {
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
logger.log('ok', 'Starting speedtest');
await smartshellInstance.exec(
`docker pull tianon/speedtest && docker run --rm tianon/speedtest --accept-license --accept-gdpr`
);
});
tsdockerCli.addCommand('vscode').subscribe(async argvArg => {
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
logger.log('ok', `Starting vscode in cwd ${paths.cwd}`);
await smartshellInstance.execAndWaitForLine(
`docker run -p 127.0.0.1:8443:8443 -v "${
paths.cwd
}:/home/coder/project" registry.gitlab.com/hosttoday/ht-docker-vscode --allow-http --no-auth`,
/Connected to shared process/
);
await plugins.smartopen.openUrl('testing-vscode.git.zone:8443');
});
tsdockerCli.startParse();
};

View File

@ -1,37 +0,0 @@
import * as plugins from './tsdocker.plugins';
import * as paths from './tsdocker.paths';
export interface IConfig {
baseImage: string;
command: string;
dockerSock: boolean;
exitCode?: number;
keyValueObject: {[key: string]: any};
}
const getQenvKeyValueObject = async () => {
let qenvKeyValueObjectArray: { [key: string]: string | number };
if (plugins.smartfile.fs.fileExistsSync(plugins.path.join(paths.cwd, 'qenv.yml'))) {
qenvKeyValueObjectArray = new plugins.qenv.Qenv(paths.cwd, '.nogit/').keyValueObject;
} else {
qenvKeyValueObjectArray = {};
}
return qenvKeyValueObjectArray;
};
const buildConfig = async (qenvKeyValueObjectArg: { [key: string]: string | number }) => {
const npmextra = new plugins.npmextra.Npmextra(paths.cwd);
const config = npmextra.dataFor<IConfig>('npmdocker', {
baseImage: 'hosttoday/ht-docker-node:npmdocker',
init: 'rm -rf node_nodules/ && yarn install',
command: 'npmci npm test',
dockerSock: false,
keyValueObject: qenvKeyValueObjectArg
});
return config;
};
export let run = async (): Promise<IConfig> => {
const config = await getQenvKeyValueObject().then(buildConfig);
return config;
};

View File

@ -1,17 +0,0 @@
import * as plugins from './tsdocker.plugins';
export const logger = new plugins.smartlog.Smartlog({
logContext: {
company: 'Some Company',
companyunit: 'Some CompanyUnit',
containerName: 'Some Containername',
environment: 'local',
runtime: 'node',
zone: 'gitzone'
},
minimumLogLevel: 'silly'
});
logger.addLogDestination(new plugins.smartlogDestinationLocal.DestinationLocal());
export const ora = new plugins.smartlogSouceOra.SmartlogSourceOra();

View File

@ -1,17 +1,3 @@
{ {
"extends": ["tslint:latest", "tslint-config-prettier"], "extends": "tslint-config-standard"
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
} }