Compare commits

...

31 Commits

Author SHA1 Message Date
ac386f01e0 1.2.40 2021-09-30 11:14:44 +02:00
08ead4258f fix(core): update 2021-09-30 11:14:43 +02:00
f930f3a6a7 1.2.39 2019-05-28 11:31:40 +02:00
b6d4a76c70 fix(core): update 2019-05-28 11:31:39 +02:00
9a7ecd27e5 1.2.38 2019-05-27 15:50:38 +02:00
11b70b0ddf fix(core): update 2019-05-27 15:50:38 +02:00
79f8cb5e0e 1.2.37 2019-05-27 13:14:12 +02:00
3e1286b9ac fix(core): update 2019-05-27 13:14:12 +02:00
a8ae886959 1.2.36 2019-05-21 17:43:38 +02:00
da1c977a62 fix(core): update 2019-05-21 17:43:37 +02:00
b99b55a05b 1.2.35 2019-05-21 17:41:25 +02:00
133bf0abe5 fix(core): update 2019-05-21 17:41:25 +02:00
df260bbab9 1.2.34 2019-05-21 17:35:37 +02:00
080bd2bc48 fix(core): update 2019-05-21 17:35:36 +02:00
a0032b8168 1.2.33 2019-05-12 18:52:23 +02:00
a09efd1125 fix(core): update 2019-05-12 18:52:23 +02:00
4ce28c7979 1.2.32 2019-05-12 18:30:33 +02:00
415eaea56e fix(bin name): change from npmdocker to tsdocker 2019-05-12 18:30:32 +02:00
bde4597dd9 1.2.31 2019-05-10 17:09:51 +02:00
80946d4f0c fix(core): update 2019-05-10 17:09:50 +02:00
2155e886ef 1.2.30 2019-05-10 11:46:38 +02:00
8b61a90b5f fix(core): update 2019-05-10 11:46:37 +02:00
f48eadc814 1.2.29 2019-05-10 11:46:00 +02:00
9bdaaa0c30 fix(core): update 2019-05-10 11:45:59 +02:00
5f681ff237 fix(core): update 2019-05-10 11:45:20 +02:00
889a3fdc5a 1.2.28 2019-05-09 10:06:59 +02:00
565c002127 fix(core): update 2019-05-09 10:06:59 +02:00
6fec1a00ea 1.2.27 2018-10-29 01:09:46 +01:00
e1f2c28718 fix(ci): remove npmts from build process 2018-10-29 01:09:45 +01:00
9efab07424 1.2.26 2018-10-29 01:07:40 +01:00
18d16feaa9 fix(core): update 2018-10-29 01:07:39 +01:00
21 changed files with 27915 additions and 1716 deletions

29
.gitignore vendored
View File

@ -1,8 +1,23 @@
node_modules/
coverage/
pages/
public/
test/
assets/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.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
stage: pages
script:
- npmci command yarn global add npmpage
- npmci command npmpage
- npmci command npm install -g @gitzone/tsdoc
- npmci command tsdoc
only:
- tags
tags:

3
.vscode/settings.json vendored Normal file
View File

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

View File

@ -1,67 +0,0 @@
# 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
RUN yarn global add npmdocker
RUN yarn global add @gitzone/tsdocker
COPY ./ /workspace
WORKDIR /workspace
ENV CI=true
CMD ["npmdocker","runinside"];
CMD ["tsdocker","runinside"];

View File

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

View File

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

29059
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,20 +0,0 @@
/**
* 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,5 +1,4 @@
import './analytics';
import * as plugins from './npmdocker.plugins';
import * as cli from './npmdocker.cli';
import * as plugins from './tsdocker.plugins';
import * as cli from './tsdocker.cli';
cli.run();

View File

@ -1,76 +0,0 @@
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 -f $(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();
};

View File

@ -1,40 +0,0 @@
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;
};

90
ts/tsdocker.cli.ts Normal file
View File

@ -0,0 +1,90 @@
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();
};

37
ts/tsdocker.config.ts Normal file
View File

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

17
ts/tsdocker.logging.ts Normal file
View File

@ -0,0 +1,17 @@
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,4 +1,4 @@
import * as plugins from './npmdocker.plugins';
import * as plugins from './tsdocker.plugins';
// directories
export let cwd = process.cwd();

View File

@ -1,4 +1,4 @@
import * as beautylog from 'beautylog';
// pushrocks scope
import * as npmextra from '@pushrocks/npmextra';
import * as path from 'path';
import * as projectinfo from '@pushrocks/projectinfo';
@ -6,11 +6,14 @@ import * as smartpromise from '@pushrocks/smartpromise';
import * as qenv from '@pushrocks/qenv';
import * as smartcli from '@pushrocks/smartcli';
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 smartstring from '@pushrocks/smartstring';
export {
beautylog,
npmextra,
path,
projectinfo,
@ -18,6 +21,10 @@ export {
qenv,
smartcli,
smartfile,
smartlog,
smartlogDestinationLocal,
smartlogSouceOra,
smartopen,
smartshell,
smartstring
};

View File

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

View File

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