Compare commits
No commits in common. "master" and "v1.2.4" have entirely different histories.
27
.gitignore
vendored
27
.gitignore
vendored
@ -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
|
|
||||||
|
@ -1,40 +1,28 @@
|
|||||||
image: hosttoday/ht-docker-dbase:npmci
|
image: hosttoday/ht-docker-dbase:npmts
|
||||||
services:
|
services:
|
||||||
- docker:dind
|
- docker:dind
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- mirror
|
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- trigger
|
- trigger
|
||||||
- pages
|
|
||||||
|
|
||||||
mirror:
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: mirror
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npm install
|
||||||
- npmci npm install
|
- npm test
|
||||||
- npmci npm test
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- lossless
|
- lossless
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
|
image: hosttoday/ht-docker-node:npmts
|
||||||
stage: release
|
stage: release
|
||||||
environment: npmjs-com_registry
|
environment: npmjs-com_registry
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci publish
|
||||||
- npmci npm publish
|
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
@ -43,6 +31,7 @@ release:
|
|||||||
- priv
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
|
image: hosttoday/ht-docker-node:npmts
|
||||||
stage: trigger
|
stage: trigger
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
@ -52,18 +41,3 @@ trigger:
|
|||||||
- docker
|
- docker
|
||||||
- lossless
|
- lossless
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: pages
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci command tsdoc
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"typescript.tsdk": "node_modules/typescript/lib"
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
FROM hosttoday/ht-docker-node:stable
|
|
||||||
LABEL author="Lossless GmbH <office@lossless.com>"
|
|
||||||
|
|
||||||
RUN yarn global add npmci npmdocker npmts ts-node
|
|
59
README.md
Normal file
59
README.md
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# 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)
|
||||||
|
|
||||||
|
[](https://git.zone)
|
@ -1,6 +1,5 @@
|
|||||||
FROM hosttoday/ht-docker-node:npmci
|
FROM hosttoday/ht-docker-node:npmts
|
||||||
RUN yarn global add @gitzone/tsdocker
|
COPY ./buildContextDir /workspace
|
||||||
COPY ./ /workspace
|
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
ENV CI=true
|
ENV CI=true
|
||||||
CMD ["tsdocker","runinside"];
|
CMD ["npmci","test","stable"];
|
||||||
|
3
cli.js
3
cli.js
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
process.env.CLI_CALL = 'true';
|
|
||||||
require('./dist/index');
|
|
@ -1,4 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
process.env.CLI_CALL = 'true';
|
|
||||||
require('@gitzone/tsrun');
|
|
||||||
require('./ts/index');
|
|
2
dist/cli.js
vendored
Normal file
2
dist/cli.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
var index = require("../dist/index.js");
|
0
dist/index.d.ts
vendored
Normal file
0
dist/index.d.ts
vendored
Normal file
4
dist/index.js
vendored
Normal file
4
dist/index.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
"use strict";
|
||||||
|
const cli = require("./npmdocker.cli");
|
||||||
|
cli.run();
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQ0EsdUNBQXNDO0FBRXRDLEdBQUcsQ0FBQyxHQUFHLEVBQUUsQ0FBQSJ9
|
1
dist/npmdocker.cli.d.ts
vendored
Normal file
1
dist/npmdocker.cli.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export declare let run: () => void;
|
49
dist/npmdocker.cli.js
vendored
Normal file
49
dist/npmdocker.cli.js
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
"use strict";
|
||||||
|
const plugins = require("./npmdocker.plugins");
|
||||||
|
// modules
|
||||||
|
const ConfigModule = require("./npmdocker.config");
|
||||||
|
const DockerModule = require("./npmdocker.docker");
|
||||||
|
let npmdockerCli = new plugins.smartcli.Smartcli();
|
||||||
|
plugins.beautylog.ora.start();
|
||||||
|
exports.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) => {
|
||||||
|
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...');
|
||||||
|
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)`);
|
||||||
|
}
|
||||||
|
plugins.beautylog.ora.endOk('docker environment now is clean!');
|
||||||
|
});
|
||||||
|
npmdockerCli.addCommand('speedtest').then(argvArg => {
|
||||||
|
plugins.beautylog.ora.text('cleaning up docker env...');
|
||||||
|
plugins.shelljs.exec(`docker pull tianon/speedtest && docker run --rm tianon/speedtest`);
|
||||||
|
plugins.beautylog.ora.endOk('docker environment now is clean!');
|
||||||
|
});
|
||||||
|
npmdockerCli.startParse();
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLCtDQUE4QztBQUc5QyxVQUFVO0FBQ1YsbURBQWtEO0FBQ2xELG1EQUFrRDtBQUVsRCxJQUFJLFlBQVksR0FBRyxJQUFJLE9BQU8sQ0FBQyxRQUFRLENBQUMsUUFBUSxFQUFFLENBQUE7QUFFbEQsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsS0FBSyxFQUFFLENBQUE7QUFDbEIsUUFBQSxHQUFHLEdBQUc7SUFDZixZQUFZLENBQUMsWUFBWSxFQUFFLENBQUMsSUFBSSxDQUFDLE9BQU87UUFDdEMsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUM1QixZQUFZLENBQUMsR0FBRyxFQUFFO2FBQ2YsSUFBSSxDQUFDLFlBQVksQ0FBQyxHQUFHLENBQUM7YUFDdEIsSUFBSSxDQUFDLENBQUMsU0FBUztZQUNkLElBQUksQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUE7UUFDekIsQ0FBQyxDQUFDLENBQUE7UUFDSixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUNyQixDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxTQUErQjtRQUN0QyxFQUFFLENBQUMsQ0FBQyxTQUFTLENBQUMsUUFBUSxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7WUFDN0IsT0FBTyxDQUFDLFNBQVMsQ0FBQyxPQUFPLENBQUMsNEJBQTRCLENBQUMsQ0FBQTtRQUN6RCxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDTixPQUFPLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyw2QkFBNkIsQ0FBQyxDQUFBO1lBQ3RELE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDakIsQ0FBQztJQUNILENBQUMsQ0FBQyxDQUFBO0lBRUYsWUFBWSxDQUFDLFVBQVUsQ0FBQyxPQUFPLENBQUMsQ0FBQyxJQUFJLENBQUMsT0FBTztRQUMzQyxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsMkJBQTJCLENBQUMsQ0FBQTtRQUN2RCxFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQztZQUNoQixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsMENBQTBDLENBQUMsQ0FBQTtZQUN0RSxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyw2QkFBNkIsQ0FBQyxDQUFBO1lBRW5ELE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxnQ0FBZ0MsQ0FBQyxDQUFBO1lBQzVELE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLDhCQUE4QixDQUFDLENBQUE7WUFFcEQsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLG9CQUFvQixDQUFDLENBQUE7WUFDaEQsT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsaURBQWlELENBQUMsQ0FBQTtZQUV2RSxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsOEJBQThCLENBQUMsQ0FBQTtZQUMxRCxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxtQ0FBbUMsQ0FBQyxDQUFBO1lBRXpELE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyx5QkFBeUIsQ0FBQyxDQUFBO1lBQ3JELE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLDBEQUEwRCxDQUFDLENBQUE7UUFDbEYsQ0FBQztRQUNELE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLEtBQUssQ0FBQyxrQ0FBa0MsQ0FBQyxDQUFBO0lBQ2pFLENBQUMsQ0FBQyxDQUFBO0lBRUYsWUFBWSxDQUFDLFVBQVUsQ0FBQyxXQUFXLENBQUMsQ0FBQyxJQUFJLENBQUMsT0FBTztRQUMvQyxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsMkJBQTJCLENBQUMsQ0FBQTtRQUN2RCxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxrRUFBa0UsQ0FBQyxDQUFBO1FBQ3hGLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLEtBQUssQ0FBQyxrQ0FBa0MsQ0FBQyxDQUFBO0lBQ2pFLENBQUMsQ0FBQyxDQUFBO0lBRUYsWUFBWSxDQUFDLFVBQVUsRUFBRSxDQUFBO0FBQzNCLENBQUMsQ0FBQSJ9
|
9
dist/npmdocker.config.d.ts
vendored
Normal file
9
dist/npmdocker.config.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { IKeyValueObject } from 'qenv';
|
||||||
|
export interface IConfig {
|
||||||
|
baseImage: string;
|
||||||
|
command: string;
|
||||||
|
dockerSock: boolean;
|
||||||
|
exitCode?: number;
|
||||||
|
keyValueObjectArray: IKeyValueObject[];
|
||||||
|
}
|
||||||
|
export declare let run: () => Promise<{}>;
|
37
dist/npmdocker.config.js
vendored
Normal file
37
dist/npmdocker.config.js
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
"use strict";
|
||||||
|
const plugins = require("./npmdocker.plugins");
|
||||||
|
const paths = require("./npmdocker.paths");
|
||||||
|
;
|
||||||
|
let getQenvKeyValueObject = () => {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
let qenvKeyValueObjectArray;
|
||||||
|
if (plugins.smartfile.fs.fileExistsSync(plugins.path.join(paths.cwd, 'qenv.yml'))) {
|
||||||
|
qenvKeyValueObjectArray = new plugins.qenv.Qenv(paths.cwd, '.nogit/').keyValueObjectArray;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qenvKeyValueObjectArray = [];
|
||||||
|
}
|
||||||
|
;
|
||||||
|
done.resolve(qenvKeyValueObjectArray);
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
let buildConfig = (qenvKeyValueObjectArrayArg) => {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
let npmextra = new plugins.npmextra.Npmextra(paths.cwd);
|
||||||
|
let config = npmextra.dataFor('npmdocker', {
|
||||||
|
baseImage: 'hosttoday/ht-docker-node:npmts',
|
||||||
|
command: 'npm test',
|
||||||
|
dockerSock: false,
|
||||||
|
keyValueObjectArray: qenvKeyValueObjectArrayArg
|
||||||
|
});
|
||||||
|
done.resolve(config);
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
exports.run = () => {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
getQenvKeyValueObject()
|
||||||
|
.then(buildConfig)
|
||||||
|
.then(done.resolve);
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLCtDQUE4QztBQUM5QywyQ0FBMEM7QUFXekMsQ0FBQztBQUVGLElBQUkscUJBQXFCLEdBQUc7SUFDMUIsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUM1QixJQUFJLHVCQUEwQyxDQUFBO0lBQzlDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGNBQWMsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsR0FBRyxFQUFFLFVBQVUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQ2xGLHVCQUF1QixHQUFHLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLEdBQUcsRUFBRSxTQUFTLENBQUMsQ0FBQyxtQkFBbUIsQ0FBQTtJQUMzRixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDTix1QkFBdUIsR0FBRyxFQUFFLENBQUE7SUFDOUIsQ0FBQztJQUFBLENBQUM7SUFDRixJQUFJLENBQUMsT0FBTyxDQUFDLHVCQUF1QixDQUFDLENBQUE7SUFDckMsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDckIsQ0FBQyxDQUFBO0FBRUQsSUFBSSxXQUFXLEdBQUcsQ0FBQywwQkFBMkM7SUFDNUQsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUM1QixJQUFJLFFBQVEsR0FBRyxJQUFJLE9BQU8sQ0FBQyxRQUFRLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQUMsQ0FBQTtJQUN2RCxJQUFJLE1BQU0sR0FBRyxRQUFRLENBQUMsT0FBTyxDQUMzQixXQUFXLEVBQ1g7UUFDRSxTQUFTLEVBQUUsZ0NBQWdDO1FBQzNDLE9BQU8sRUFBRSxVQUFVO1FBQ25CLFVBQVUsRUFBRSxLQUFLO1FBQ2pCLG1CQUFtQixFQUFFLDBCQUEwQjtLQUNoRCxDQUNGLENBQUE7SUFDRCxJQUFJLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO0lBQ3BCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3JCLENBQUMsQ0FBQTtBQUVVLFFBQUEsR0FBRyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUM1QixxQkFBcUIsRUFBRTtTQUNwQixJQUFJLENBQUMsV0FBVyxDQUFDO1NBQ2pCLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDckIsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDckIsQ0FBQyxDQUFBIn0=
|
1
dist/npmdocker.docker.d.ts
vendored
Normal file
1
dist/npmdocker.docker.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export declare let run: (configArg: any) => Promise<{}>;
|
186
dist/npmdocker.docker.js
vendored
Normal file
186
dist/npmdocker.docker.js
vendored
Normal file
File diff suppressed because one or more lines are too long
5
dist/npmdocker.paths.d.ts
vendored
Normal file
5
dist/npmdocker.paths.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export declare let cwd: string;
|
||||||
|
export declare let packageBase: string;
|
||||||
|
export declare let assets: string;
|
||||||
|
export declare let buildContextDir: string;
|
||||||
|
export declare let dockerfile: string;
|
12
dist/npmdocker.paths.js
vendored
Normal file
12
dist/npmdocker.paths.js
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
"use strict";
|
||||||
|
const plugins = require("./npmdocker.plugins");
|
||||||
|
// directories
|
||||||
|
exports.cwd = process.cwd();
|
||||||
|
exports.packageBase = plugins.path.join(__dirname, "../");
|
||||||
|
exports.assets = plugins.path.join(exports.packageBase, "assets/");
|
||||||
|
plugins.smartfile.fs.ensureDirSync(exports.assets);
|
||||||
|
exports.buildContextDir = plugins.path.join(exports.assets, "buildContextDir");
|
||||||
|
plugins.smartfile.fs.ensureDirSync(exports.buildContextDir);
|
||||||
|
// files
|
||||||
|
exports.dockerfile = plugins.path.join(exports.assets, "Dockerfile");
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwrQ0FBK0M7QUFFL0MsY0FBYztBQUNILFFBQUEsR0FBRyxHQUFHLE9BQU8sQ0FBQyxHQUFHLEVBQUUsQ0FBQztBQUNwQixRQUFBLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxTQUFTLEVBQUUsS0FBSyxDQUFDLENBQUM7QUFDbEQsUUFBQSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsbUJBQVcsRUFBRSxTQUFTLENBQUMsQ0FBQztBQUM5RCxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxhQUFhLENBQUMsY0FBTSxDQUFDLENBQUM7QUFFaEMsUUFBQSxlQUFlLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsY0FBTSxFQUFDLGlCQUFpQixDQUFDLENBQUM7QUFDekUsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsYUFBYSxDQUFDLHVCQUFlLENBQUMsQ0FBQztBQUVwRCxRQUFRO0FBQ0csUUFBQSxVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsY0FBTSxFQUFFLFlBQVksQ0FBQyxDQUFDIn0=
|
12
dist/npmdocker.plugins.d.ts
vendored
Normal file
12
dist/npmdocker.plugins.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import 'typings-global';
|
||||||
|
import * as beautylog from 'beautylog';
|
||||||
|
import * as npmextra from 'npmextra';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as projectinfo from 'projectinfo';
|
||||||
|
import * as q from 'smartq';
|
||||||
|
import * as qenv from 'qenv';
|
||||||
|
import * as shelljs from 'shelljs';
|
||||||
|
import * as smartcli from 'smartcli';
|
||||||
|
import * as smartfile from 'smartfile';
|
||||||
|
import * as smartstring from 'smartstring';
|
||||||
|
export { beautylog, npmextra, path, projectinfo, q, qenv, shelljs, smartcli, smartfile, smartstring };
|
23
dist/npmdocker.plugins.js
vendored
Normal file
23
dist/npmdocker.plugins.js
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
const beautylog = require("beautylog");
|
||||||
|
exports.beautylog = beautylog;
|
||||||
|
const npmextra = require("npmextra");
|
||||||
|
exports.npmextra = npmextra;
|
||||||
|
const path = require("path");
|
||||||
|
exports.path = path;
|
||||||
|
const projectinfo = require("projectinfo");
|
||||||
|
exports.projectinfo = projectinfo;
|
||||||
|
const q = require("smartq");
|
||||||
|
exports.q = q;
|
||||||
|
const qenv = require("qenv");
|
||||||
|
exports.qenv = qenv;
|
||||||
|
const shelljs = require("shelljs");
|
||||||
|
exports.shelljs = shelljs;
|
||||||
|
const smartcli = require("smartcli");
|
||||||
|
exports.smartcli = smartcli;
|
||||||
|
const smartfile = require("smartfile");
|
||||||
|
exports.smartfile = smartfile;
|
||||||
|
const smartstring = require("smartstring");
|
||||||
|
exports.smartstring = smartstring;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1kb2NrZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVDQUFzQztBQVlwQyw4QkFBUztBQVhYLHFDQUFvQztBQVlsQyw0QkFBUTtBQVhWLDZCQUE0QjtBQVkxQixvQkFBSTtBQVhOLDJDQUEwQztBQVl4QyxrQ0FBVztBQVhiLDRCQUEyQjtBQVl6QixjQUFDO0FBWEgsNkJBQTRCO0FBWTFCLG9CQUFJO0FBWE4sbUNBQWtDO0FBWWhDLDBCQUFPO0FBWFQscUNBQW9DO0FBWWxDLDRCQUFRO0FBWFYsdUNBQXNDO0FBWXBDLDhCQUFTO0FBWFgsMkNBQTBDO0FBWXhDLGtDQUFXIn0=
|
5
dist/npmdocker.snippets.d.ts
vendored
Normal file
5
dist/npmdocker.snippets.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export interface IDockerfileSnippet {
|
||||||
|
baseImage: string;
|
||||||
|
command: string;
|
||||||
|
}
|
||||||
|
export declare let dockerfileSnippet: (optionsArg: IDockerfileSnippet) => string;
|
21
dist/npmdocker.snippets.js
vendored
Normal file
21
dist/npmdocker.snippets.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
"use strict";
|
||||||
|
const plugins = require("./npmdocker.plugins");
|
||||||
|
exports.dockerfileSnippet = (optionsArg) => {
|
||||||
|
let commandArray = optionsArg.command.split(/\s/);
|
||||||
|
let commandString = "";
|
||||||
|
for (let stringItem of commandArray) {
|
||||||
|
if (!(commandString == "")) {
|
||||||
|
commandString = commandString + ",";
|
||||||
|
}
|
||||||
|
commandString = commandString + '"' + stringItem + '"';
|
||||||
|
}
|
||||||
|
;
|
||||||
|
return plugins.smartstring.indent.normalize(`
|
||||||
|
FROM ${optionsArg.baseImage}
|
||||||
|
COPY ./buildContextDir /workspace
|
||||||
|
WORKDIR /workspace
|
||||||
|
ENV CI=true
|
||||||
|
CMD [${commandString}];
|
||||||
|
`);
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnNuaXBwZXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnNuaXBwZXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwrQ0FBK0M7QUFPcEMsUUFBQSxpQkFBaUIsR0FBRyxDQUFDLFVBQTZCO0lBQ3pELElBQUksWUFBWSxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQ2xELElBQUksYUFBYSxHQUFVLEVBQUUsQ0FBQztJQUM5QixHQUFHLENBQUEsQ0FBQyxJQUFJLFVBQVUsSUFBSSxZQUFZLENBQUMsQ0FBQSxDQUFDO1FBQ2hDLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxhQUFhLElBQUksRUFBRSxDQUFDLENBQUMsQ0FBQSxDQUFDO1lBQ3ZCLGFBQWEsR0FBRyxhQUFhLEdBQUcsR0FBRyxDQUFDO1FBQ3hDLENBQUM7UUFDRCxhQUFhLEdBQUcsYUFBYSxHQUFHLEdBQUcsR0FBRyxVQUFVLEdBQUcsR0FBRyxDQUFDO0lBQzNELENBQUM7SUFBQSxDQUFDO0lBQ0YsTUFBTSxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsTUFBTSxDQUFDLFNBQVMsQ0FBQztlQUNqQyxVQUFVLENBQUMsU0FBUzs7OztlQUlwQixhQUFhO0tBQ3ZCLENBQUMsQ0FBQztBQUNQLENBQUMsQ0FBQSJ9
|
@ -1,20 +1,7 @@
|
|||||||
{
|
{
|
||||||
"npmts":{
|
"npmts":{
|
||||||
"mode":"default",
|
"mode":"default",
|
||||||
"cli": true
|
"cli":true,
|
||||||
},
|
"dockerSock":true
|
||||||
"npmci": {
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
28061
package-lock.json
generated
28061
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
53
package.json
53
package.json
@ -1,20 +1,20 @@
|
|||||||
{
|
{
|
||||||
"name": "@gitzone/tsdocker",
|
"name": "npmdocker",
|
||||||
"version": "1.2.40",
|
"version": "1.2.4",
|
||||||
"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": "dist/cli.js"
|
||||||
|
},
|
||||||
|
"directories": {
|
||||||
|
"test": "test"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npm run clean && npm run setupCheck && npm run testStandard && npm run testSpeed)",
|
"test": "(npm run clean && npm run compile && npm run setupCheck && npm run testStandard && npm run testSpeed && npm run testClean)",
|
||||||
"build": "(tsbuild)",
|
"testStandard": "(cd test/ && node ../dist/index.js)",
|
||||||
"testStandard": "(cd test/ && node ../cli.ts.js)",
|
"testSpeed": "(cd test/ && node ../dist/index.js speedtest)",
|
||||||
"testSpeed": "(cd test/ && node ../cli.ts.js speedtest)",
|
"testClean": "(cd test/ && node ../dist/index.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 +33,19 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/gitzone/npmdocker#README",
|
"homepage": "https://gitlab.com/gitzone/npmdocker#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.27",
|
"npmts-g": "^6.0.0"
|
||||||
"@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": {
|
"dependencies": {
|
||||||
"@pushrocks/npmextra": "^3.0.9",
|
"@types/shelljs": "0.x.x",
|
||||||
"@pushrocks/projectinfo": "^4.0.5",
|
"beautylog": "^6.1.1",
|
||||||
"@pushrocks/qenv": "^4.0.10",
|
"npmextra": "^2.0.3",
|
||||||
"@pushrocks/smartanalytics": "^2.0.15",
|
"projectinfo": "^3.0.1",
|
||||||
"@pushrocks/smartcli": "^3.0.14",
|
"qenv": "^1.1.3",
|
||||||
"@pushrocks/smartfile": "^8.0.10",
|
"shelljs": "^0.7.6",
|
||||||
"@pushrocks/smartlog": "^2.0.44",
|
"smartcli": "^2.0.1",
|
||||||
"@pushrocks/smartlog-destination-local": "^8.0.8",
|
"smartfile": "^4.1.5",
|
||||||
"@pushrocks/smartlog-source-ora": "^1.0.9",
|
"smartq": "^1.1.0",
|
||||||
"@pushrocks/smartopen": "^1.0.22",
|
"smartstring": "^2.0.22",
|
||||||
"@pushrocks/smartpromise": "^3.1.6",
|
"typings-global": "^1.0.14"
|
||||||
"@pushrocks/smartshell": "^2.0.28",
|
|
||||||
"@pushrocks/smartstring": "^3.0.24",
|
|
||||||
"@types/shelljs": "^0.8.9"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './tsdocker.plugins';
|
import * as plugins from './npmdocker.plugins'
|
||||||
import * as cli from './tsdocker.cli';
|
import * as cli from './npmdocker.cli'
|
||||||
|
|
||||||
cli.run();
|
cli.run()
|
||||||
|
57
ts/npmdocker.cli.ts
Normal file
57
ts/npmdocker.cli.ts
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
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...')
|
||||||
|
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)`)
|
||||||
|
}
|
||||||
|
plugins.beautylog.ora.endOk('docker environment now is clean!')
|
||||||
|
})
|
||||||
|
|
||||||
|
npmdockerCli.addCommand('speedtest').then(argvArg => {
|
||||||
|
plugins.beautylog.ora.text('cleaning up docker env...')
|
||||||
|
plugins.shelljs.exec(`docker pull tianon/speedtest && docker run --rm tianon/speedtest`)
|
||||||
|
plugins.beautylog.ora.endOk('docker environment now is clean!')
|
||||||
|
})
|
||||||
|
|
||||||
|
npmdockerCli.startParse()
|
||||||
|
}
|
49
ts/npmdocker.config.ts
Normal file
49
ts/npmdocker.config.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import * as plugins from './npmdocker.plugins'
|
||||||
|
import * as paths from "./npmdocker.paths"
|
||||||
|
|
||||||
|
// interfaces
|
||||||
|
import { IKeyValueObject } from 'qenv'
|
||||||
|
|
||||||
|
export interface IConfig {
|
||||||
|
baseImage: string
|
||||||
|
command: string
|
||||||
|
dockerSock: boolean
|
||||||
|
exitCode?: number
|
||||||
|
keyValueObjectArray: IKeyValueObject[]
|
||||||
|
};
|
||||||
|
|
||||||
|
let getQenvKeyValueObject = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
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 = []
|
||||||
|
};
|
||||||
|
done.resolve(qenvKeyValueObjectArray)
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
let buildConfig = (qenvKeyValueObjectArrayArg: IKeyValueObject) => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
let npmextra = new plugins.npmextra.Npmextra(paths.cwd)
|
||||||
|
let config = npmextra.dataFor<IConfig>(
|
||||||
|
'npmdocker',
|
||||||
|
{
|
||||||
|
baseImage: 'hosttoday/ht-docker-node:npmts',
|
||||||
|
command: 'npm test',
|
||||||
|
dockerSock: false,
|
||||||
|
keyValueObjectArray: qenvKeyValueObjectArrayArg
|
||||||
|
}
|
||||||
|
)
|
||||||
|
done.resolve(config)
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
export let run = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
getQenvKeyValueObject()
|
||||||
|
.then(buildConfig)
|
||||||
|
.then(done.resolve)
|
||||||
|
return done.promise
|
||||||
|
}
|
208
ts/npmdocker.docker.ts
Normal file
208
ts/npmdocker.docker.ts
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
import * as plugins from './npmdocker.plugins';
|
||||||
|
import * as paths from './npmdocker.paths';
|
||||||
|
import * as snippets from './npmdocker.snippets'
|
||||||
|
|
||||||
|
// interfaces
|
||||||
|
import { IConfig } from './npmdocker.config'
|
||||||
|
|
||||||
|
let config: IConfig
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the docker data used to build the internal testing container
|
||||||
|
*/
|
||||||
|
let dockerData = {
|
||||||
|
imageTag: 'npmdocker-temp-image:latest',
|
||||||
|
containerName: 'npmdocker-temp-container',
|
||||||
|
dockerProjectMountString: '',
|
||||||
|
dockerSockString: '',
|
||||||
|
dockerEnvString: ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if docker is available
|
||||||
|
*/
|
||||||
|
let checkDocker = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
plugins.beautylog.ora.text('checking docker...')
|
||||||
|
if (plugins.shelljs.which('docker')) {
|
||||||
|
plugins.beautylog.ok('Docker found!')
|
||||||
|
done.resolve()
|
||||||
|
} else {
|
||||||
|
done.reject(new Error('docker not found on this machine'))
|
||||||
|
}
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* builds the Dockerfile according to the config in the project
|
||||||
|
*/
|
||||||
|
let buildDockerFile = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
plugins.beautylog.ora.text('building Dockerfile...')
|
||||||
|
let 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}`)
|
||||||
|
plugins.smartfile.memory.toFsSync(dockerfile, paths.dockerfile)
|
||||||
|
plugins.beautylog.ok('Dockerfile created!')
|
||||||
|
done.resolve()
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* builds the Dockerimage from the built Dockerfile
|
||||||
|
*/
|
||||||
|
let buildDockerImage = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
plugins.beautylog.ora.text('pulling latest base image from registry...')
|
||||||
|
plugins.shelljs.exec(
|
||||||
|
`docker pull ${config.baseImage}`,
|
||||||
|
{
|
||||||
|
silent: true
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
plugins.beautylog.ora.text('building Dockerimage...')
|
||||||
|
// are we creating a build context form project ?
|
||||||
|
if (process.env.CI === 'true') {
|
||||||
|
plugins.beautylog.ora.text('creating build context...')
|
||||||
|
plugins.smartfile.fs.copySync(paths.cwd, paths.buildContextDir)
|
||||||
|
}
|
||||||
|
plugins.shelljs.exec(
|
||||||
|
`docker build -f ${paths.dockerfile} -t ${dockerData.imageTag} ${paths.assets}`,
|
||||||
|
{
|
||||||
|
silent: true
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
plugins.beautylog.ok('Dockerimage built!')
|
||||||
|
done.resolve()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) // first pull latest version of baseImage
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
let buildDockerProjectMountString = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
if (process.env.CI !== 'true') {
|
||||||
|
dockerData.dockerProjectMountString = `-v ${paths.cwd}:/workspace`
|
||||||
|
};
|
||||||
|
done.resolve()
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* builds an environment string that docker cli understands
|
||||||
|
*/
|
||||||
|
let buildDockerEnvString = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
for (let keyValueObjectArg of config.keyValueObjectArray) {
|
||||||
|
let envString = dockerData.dockerEnvString = dockerData.dockerEnvString + `-e ${keyValueObjectArg.key}=${keyValueObjectArg.value} `
|
||||||
|
};
|
||||||
|
done.resolve()
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates string to mount the docker.sock inside the testcontainer
|
||||||
|
*/
|
||||||
|
let buildDockerSockString = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
if (config.dockerSock) {
|
||||||
|
dockerData.dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`
|
||||||
|
};
|
||||||
|
done.resolve()
|
||||||
|
return done
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a container by running the built Dockerimage
|
||||||
|
*/
|
||||||
|
let runDockerImage = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
plugins.beautylog.ora.text('starting Container...')
|
||||||
|
plugins.beautylog.ora.end()
|
||||||
|
plugins.beautylog.log('now running Dockerimage')
|
||||||
|
config.exitCode = plugins.shelljs.exec(`docker run ${dockerData.dockerProjectMountString} ${dockerData.dockerSockString} ${dockerData.dockerEnvString} --name ${dockerData.containerName} ${dockerData.imageTag}`).code
|
||||||
|
done.resolve()
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cleans up: deletes the test container
|
||||||
|
*/
|
||||||
|
let deleteDockerContainer = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
plugins.shelljs.exec(`docker rm -f ${dockerData.containerName}`, {
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
|
done.resolve()
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cleans up deletes the test image
|
||||||
|
*/
|
||||||
|
let deleteDockerImage = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`, {
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
|
done.resolve()
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cleans up, deletes the build context
|
||||||
|
*/
|
||||||
|
let deleteBuildContext = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
plugins.smartfile.fs.remove(paths.buildContextDir)
|
||||||
|
.then(() => {
|
||||||
|
done.resolve()
|
||||||
|
})
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
let preClean = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
deleteDockerImage()
|
||||||
|
.then(deleteDockerContainer)
|
||||||
|
.then(() => {
|
||||||
|
plugins.beautylog.ok('ensured clean Docker environment!')
|
||||||
|
done.resolve()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let postClean = () => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
deleteDockerContainer()
|
||||||
|
.then(deleteDockerImage)
|
||||||
|
.then(deleteBuildContext)
|
||||||
|
.then(() => {
|
||||||
|
plugins.beautylog.ok('cleaned up!')
|
||||||
|
done.resolve()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export let run = (configArg) => {
|
||||||
|
let done = plugins.q.defer()
|
||||||
|
config = configArg
|
||||||
|
checkDocker()
|
||||||
|
.then(preClean)
|
||||||
|
.then(buildDockerFile)
|
||||||
|
.then(buildDockerImage)
|
||||||
|
.then(buildDockerProjectMountString)
|
||||||
|
.then(buildDockerEnvString)
|
||||||
|
.then(buildDockerSockString)
|
||||||
|
.then(runDockerImage)
|
||||||
|
.then(postClean)
|
||||||
|
.then(() => {
|
||||||
|
done.resolve(config);
|
||||||
|
}).catch(err => { console.log(err) })
|
||||||
|
return done.promise
|
||||||
|
}
|
13
ts/npmdocker.paths.ts
Normal file
13
ts/npmdocker.paths.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import * as plugins from "./npmdocker.plugins";
|
||||||
|
|
||||||
|
// directories
|
||||||
|
export let cwd = process.cwd();
|
||||||
|
export let packageBase = plugins.path.join(__dirname, "../");
|
||||||
|
export let assets = plugins.path.join(packageBase, "assets/");
|
||||||
|
plugins.smartfile.fs.ensureDirSync(assets);
|
||||||
|
|
||||||
|
export let buildContextDir = plugins.path.join(assets,"buildContextDir");
|
||||||
|
plugins.smartfile.fs.ensureDirSync(buildContextDir);
|
||||||
|
|
||||||
|
// files
|
||||||
|
export let dockerfile = plugins.path.join(assets, "Dockerfile");
|
24
ts/npmdocker.plugins.ts
Normal file
24
ts/npmdocker.plugins.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import 'typings-global'
|
||||||
|
import * as beautylog from 'beautylog'
|
||||||
|
import * as npmextra from 'npmextra'
|
||||||
|
import * as path from 'path'
|
||||||
|
import * as projectinfo from 'projectinfo'
|
||||||
|
import * as q from 'smartq'
|
||||||
|
import * as qenv from 'qenv'
|
||||||
|
import * as shelljs from 'shelljs'
|
||||||
|
import * as smartcli from 'smartcli'
|
||||||
|
import * as smartfile from 'smartfile'
|
||||||
|
import * as smartstring from 'smartstring'
|
||||||
|
|
||||||
|
export {
|
||||||
|
beautylog,
|
||||||
|
npmextra,
|
||||||
|
path,
|
||||||
|
projectinfo,
|
||||||
|
q,
|
||||||
|
qenv,
|
||||||
|
shelljs,
|
||||||
|
smartcli,
|
||||||
|
smartfile,
|
||||||
|
smartstring
|
||||||
|
}
|
24
ts/npmdocker.snippets.ts
Normal file
24
ts/npmdocker.snippets.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import * as plugins from "./npmdocker.plugins";
|
||||||
|
|
||||||
|
export interface IDockerfileSnippet {
|
||||||
|
baseImage:string;
|
||||||
|
command:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export let dockerfileSnippet = (optionsArg:IDockerfileSnippet):string => {
|
||||||
|
let commandArray = optionsArg.command.split(/\s/);
|
||||||
|
let commandString:string = "";
|
||||||
|
for(let stringItem of commandArray){
|
||||||
|
if(!(commandString == "")){
|
||||||
|
commandString = commandString + ",";
|
||||||
|
}
|
||||||
|
commandString = commandString + '"' + stringItem + '"';
|
||||||
|
};
|
||||||
|
return plugins.smartstring.indent.normalize(`
|
||||||
|
FROM ${optionsArg.baseImage}
|
||||||
|
COPY ./buildContextDir /workspace
|
||||||
|
WORKDIR /workspace
|
||||||
|
ENV CI=true
|
||||||
|
CMD [${commandString}];
|
||||||
|
`);
|
||||||
|
}
|
@ -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();
|
|
||||||
};
|
|
@ -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;
|
|
||||||
};
|
|
@ -1,169 +0,0 @@
|
|||||||
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 './tsdocker.config';
|
|
||||||
|
|
||||||
let config: IConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the docker data used to build the internal testing container
|
|
||||||
*/
|
|
||||||
const dockerData = {
|
|
||||||
imageTag: 'npmdocker-temp-image:latest',
|
|
||||||
containerName: 'npmdocker-temp-container',
|
|
||||||
dockerProjectMountString: '',
|
|
||||||
dockerSockString: '',
|
|
||||||
dockerEnvString: ''
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* check if docker is available
|
|
||||||
*/
|
|
||||||
const checkDocker = () => {
|
|
||||||
const done = plugins.smartpromise.defer();
|
|
||||||
ora.text('checking docker...');
|
|
||||||
|
|
||||||
if (smartshellInstance.exec('which docker')) {
|
|
||||||
logger.log('ok', 'Docker found!');
|
|
||||||
done.resolve();
|
|
||||||
} else {
|
|
||||||
done.reject(new Error('docker not found on this machine'));
|
|
||||||
}
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* builds the Dockerfile according to the config in the project
|
|
||||||
*/
|
|
||||||
const buildDockerFile = () => {
|
|
||||||
const done = plugins.smartpromise.defer();
|
|
||||||
ora.text('building Dockerfile...');
|
|
||||||
const dockerfile: string = snippets.dockerfileSnippet({
|
|
||||||
baseImage: config.baseImage,
|
|
||||||
command: 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'));
|
|
||||||
logger.log('ok', 'Dockerfile created!');
|
|
||||||
ora.stop();
|
|
||||||
done.resolve();
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* builds the Dockerimage from the built Dockerfile
|
|
||||||
*/
|
|
||||||
const buildDockerImage = async () => {
|
|
||||||
logger.log('info', 'pulling latest base image from registry...');
|
|
||||||
await smartshellInstance.exec(`docker pull ${config.baseImage}`);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
logger.log('ok', 'Dockerimage built!');
|
|
||||||
};
|
|
||||||
|
|
||||||
const buildDockerProjectMountString = async () => {
|
|
||||||
if (process.env.CI !== 'true') {
|
|
||||||
dockerData.dockerProjectMountString = `-v ${paths.cwd}:/workspace`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* builds an environment string that docker cli understands
|
|
||||||
*/
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
const buildDockerSockString = async () => {
|
|
||||||
if (config.dockerSock) {
|
|
||||||
dockerData.dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* creates a container by running the built 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
|
|
||||||
} --name ${dockerData.containerName} ${dockerData.imageTag}`
|
|
||||||
)).exitCode;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cleans up: deletes the test container
|
|
||||||
*/
|
|
||||||
const deleteDockerContainer = async () => {
|
|
||||||
await smartshellInstance.execSilent(`docker rm -f ${dockerData.containerName}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cleans up deletes the test image
|
|
||||||
*/
|
|
||||||
const deleteDockerImage = async () => {
|
|
||||||
await smartshellInstance.execSilent(`docker rmi ${dockerData.imageTag}`).then(async response => {
|
|
||||||
if (response.exitCode !== 0) {
|
|
||||||
console.log(response.stdout);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const preClean = async () => {
|
|
||||||
await deleteDockerImage()
|
|
||||||
.then(deleteDockerContainer)
|
|
||||||
.then(async () => {
|
|
||||||
logger.log('ok', 'ensured clean Docker environment!');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const postClean = async () => {
|
|
||||||
await deleteDockerContainer()
|
|
||||||
.then(deleteDockerImage)
|
|
||||||
.then(async () => {
|
|
||||||
logger.log('ok', 'cleaned up!');
|
|
||||||
});
|
|
||||||
plugins.smartfile.fs.removeSync(paths.npmdockerFile);
|
|
||||||
};
|
|
||||||
|
|
||||||
export let run = async (configArg: IConfig): Promise<IConfig> => {
|
|
||||||
config = configArg;
|
|
||||||
const resultConfig = await checkDocker()
|
|
||||||
.then(preClean)
|
|
||||||
.then(buildDockerFile)
|
|
||||||
.then(buildDockerImage)
|
|
||||||
.then(buildDockerProjectMountString)
|
|
||||||
.then(buildDockerEnvString)
|
|
||||||
.then(buildDockerSockString)
|
|
||||||
.then(runDockerImage)
|
|
||||||
.then(postClean)
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
return config;
|
|
||||||
};
|
|
@ -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();
|
|
@ -1,8 +0,0 @@
|
|||||||
import * as plugins from './tsdocker.plugins';
|
|
||||||
|
|
||||||
// directories
|
|
||||||
export let cwd = process.cwd();
|
|
||||||
export let packageBase = plugins.path.join(__dirname, '../');
|
|
||||||
export let assets = plugins.path.join(packageBase, 'assets/');
|
|
||||||
plugins.smartfile.fs.ensureDirSync(assets);
|
|
||||||
export let npmdockerFile = plugins.path.join(cwd, 'npmdocker');
|
|
@ -1,30 +0,0 @@
|
|||||||
// pushrocks scope
|
|
||||||
import * as npmextra from '@pushrocks/npmextra';
|
|
||||||
import * as path from 'path';
|
|
||||||
import * as projectinfo from '@pushrocks/projectinfo';
|
|
||||||
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 {
|
|
||||||
npmextra,
|
|
||||||
path,
|
|
||||||
projectinfo,
|
|
||||||
smartpromise,
|
|
||||||
qenv,
|
|
||||||
smartcli,
|
|
||||||
smartfile,
|
|
||||||
smartlog,
|
|
||||||
smartlogDestinationLocal,
|
|
||||||
smartlogSouceOra,
|
|
||||||
smartopen,
|
|
||||||
smartshell,
|
|
||||||
smartstring
|
|
||||||
};
|
|
@ -1,37 +0,0 @@
|
|||||||
import * as plugins from './tsdocker.plugins';
|
|
||||||
|
|
||||||
export interface IDockerfileSnippet {
|
|
||||||
baseImage: string;
|
|
||||||
command: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
let getMountSolutionString = (optionsArg: IDockerfileSnippet) => {
|
|
||||||
if (process.env.CI) {
|
|
||||||
return 'COPY ./ /workspace';
|
|
||||||
} else {
|
|
||||||
return '# not copying workspcae since not in CI';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let getGlobalPreparationString = (optionsArg: IDockerfileSnippet) => {
|
|
||||||
if (optionsArg.baseImage !== 'hosttoday/ht-docker-node:npmdocker') {
|
|
||||||
return 'RUN npm install -g npmdocker';
|
|
||||||
} else {
|
|
||||||
return '# not installing npmdocker since it is included in the base image';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export let dockerfileSnippet = (optionsArg: IDockerfileSnippet): string => {
|
|
||||||
return plugins.smartstring.indent.normalize(
|
|
||||||
`
|
|
||||||
FROM ${optionsArg.baseImage}
|
|
||||||
# For info about what npmdocker does read the docs at https://gitzone.github.io/npmdocker
|
|
||||||
${getGlobalPreparationString(optionsArg)}
|
|
||||||
${getMountSolutionString(optionsArg)}
|
|
||||||
WORKDIR /workspace
|
|
||||||
ENV CI=true
|
|
||||||
ENTRYPOINT ["npmdocker"]
|
|
||||||
CMD ["runinside"]
|
|
||||||
`
|
|
||||||
);
|
|
||||||
};
|
|
16
tslint.json
16
tslint.json
@ -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"
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user