Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
ac386f01e0 | |||
08ead4258f | |||
f930f3a6a7 | |||
b6d4a76c70 | |||
9a7ecd27e5 | |||
11b70b0ddf | |||
79f8cb5e0e | |||
3e1286b9ac | |||
a8ae886959 | |||
da1c977a62 | |||
b99b55a05b | |||
133bf0abe5 | |||
df260bbab9 | |||
080bd2bc48 | |||
a0032b8168 | |||
a09efd1125 | |||
4ce28c7979 | |||
415eaea56e | |||
bde4597dd9 | |||
80946d4f0c | |||
2155e886ef | |||
8b61a90b5f | |||
f48eadc814 | |||
9bdaaa0c30 | |||
5f681ff237 | |||
889a3fdc5a | |||
565c002127 | |||
6fec1a00ea | |||
e1f2c28718 |
29
.gitignore
vendored
29
.gitignore
vendored
@ -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
|
||||
|
@ -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
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
}
|
67
README.md
67
README.md
@ -1,67 +0,0 @@
|
||||
# npmdocker
|
||||
|
||||
develop npm modules cross platform with docker
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/npmdocker)
|
||||
[](https://GitLab.com/gitzone/npmdocker)
|
||||
[](https://github.com/gitzone/npmdocker)
|
||||
[](https://gitzone.gitlab.io/npmdocker/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/gitzone/npmdocker/commits/master)
|
||||
[](https://GitLab.com/gitzone/npmdocker/commits/master)
|
||||
[](https://www.npmjs.com/package/npmdocker)
|
||||
[](https://david-dm.org/gitzonetools/npmdocker)
|
||||
[](https://www.bithound.io/github/gitzonetools/npmdocker/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/gitzonetools/npmdocker)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](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)
|
||||
|
||||
[](https://git.zone)
|
@ -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"];
|
||||
|
@ -1 +0,0 @@
|
||||
Docs for npmpage coming soon.
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
29005
package-lock.json
generated
29005
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
46
package.json
46
package.json
@ -1,19 +1,20 @@
|
||||
{
|
||||
"name": "@gitzone/npmdocker",
|
||||
"version": "1.2.26",
|
||||
"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,25 +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",
|
||||
"tslint": "^5.11.0",
|
||||
"tslint-config-prettier": "^1.15.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/npmextra": "^3.0.9",
|
||||
"@pushrocks/projectinfo": "^4.0.5",
|
||||
"@pushrocks/qenv": "^4.0.10",
|
||||
"@pushrocks/smartanalytics": "^2.0.15",
|
||||
"@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"
|
||||
"@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"
|
||||
}
|
||||
}
|
||||
|
@ -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 '@pushrocks/smartanalytics';
|
||||
let npmdockerAnalytics = new smartanalytics.Analytics({
|
||||
apiEndPoint: 'https://pubapi.lossless.one',
|
||||
appName: 'npmdocker',
|
||||
projectId: 'gitzone'
|
||||
});
|
||||
npmdockerAnalytics.recordEvent('npmtoolexecution', {
|
||||
somedata: 'somedata'
|
||||
});
|
@ -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();
|
||||
|
@ -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();
|
||||
};
|
@ -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
90
ts/tsdocker.cli.ts
Normal 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
37
ts/tsdocker.config.ts
Normal 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;
|
||||
};
|
@ -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,18 +62,18 @@ 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!');
|
||||
};
|
||||
|
||||
const buildDockerProjectMountString = async () => {
|
||||
@ -84,9 +86,9 @@ const buildDockerProjectMountString = async () => {
|
||||
* builds an environment string that docker cli understands
|
||||
*/
|
||||
const buildDockerEnvString = async () => {
|
||||
for (let keyValueObjectArg of config.keyValueObjectArray) {
|
||||
let envString = (dockerData.dockerEnvString =
|
||||
dockerData.dockerEnvString + `-e ${keyValueObjectArg.key}=${keyValueObjectArg.value} `);
|
||||
for (const key of Object.keys(config.keyValueObject)) {
|
||||
const envString = (dockerData.dockerEnvString =
|
||||
dockerData.dockerEnvString + `-e ${key}=${config.keyValueObject[key]} `);
|
||||
}
|
||||
};
|
||||
|
||||
@ -102,11 +104,11 @@ const 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
17
ts/tsdocker.logging.ts
Normal 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();
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
import * as plugins from './tsdocker.plugins';
|
||||
|
||||
// directories
|
||||
export let cwd = process.cwd();
|
@ -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
|
||||
};
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
import * as plugins from './tsdocker.plugins';
|
||||
|
||||
export interface IDockerfileSnippet {
|
||||
baseImage: string;
|
@ -4,7 +4,14 @@
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user