Compare commits

...

17 Commits

Author SHA1 Message Date
da1c2167d3 1.2.5 2017-03-29 01:01:42 +02:00
d55f7ef7f2 now running async and a lot faster 2017-03-29 01:01:37 +02:00
82f4fcceac 1.2.4 2017-02-12 16:04:30 +01:00
aa3b85314d added speedtest 2017-02-12 16:04:27 +01:00
b5145294bd add removing volumes 2017-02-12 15:17:59 +01:00
d25decd15d 1.2.3 2017-02-11 23:37:06 +01:00
abf5cd1e24 added clean --all 2017-02-11 23:37:01 +01:00
9b8636b472 1.2.2 2017-02-11 20:23:13 +01:00
eab75f03da update dependencies and README 2017-02-11 20:23:10 +01:00
74374e99d7 1.2.1 2016-08-04 22:36:05 +02:00
52294de14f remove unnecessary dependencies 2016-08-04 22:36:00 +02:00
4f395850bc 1.2.0 2016-08-04 22:25:21 +02:00
8778324e5b now supports qenv 2016-08-04 22:25:15 +02:00
30b88d36ae 1.1.6 2016-07-29 22:19:58 +02:00
2c49978674 now also removes old running containers 2016-07-29 22:19:53 +02:00
4dffa31f7d 1.1.5 2016-07-29 22:00:27 +02:00
6904088af8 now removes any previous containers to avoid name space conflicts after errors 2016-07-29 22:00:22 +02:00
26 changed files with 1971 additions and 352 deletions

4
.gitignore vendored
View File

@ -1,6 +1,8 @@
node_modules/ node_modules/
coverage/ coverage/
docs/ pages/
public/
test/ test/
assets/ assets/
.nogit/ .nogit/

View File

@ -1,5 +1,59 @@
# npmdocker # npmdocker
develop npm modules cross platform with docker 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 ## Usage
npmdocker looks for a npmextra.json at the root of your directory and looks at the npmdocker portion of it. 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)
[![npm](https://gitzone.gitlab.io/assets/repo-footer.svg)](https://git.zone)

View File

@ -1,5 +1,5 @@
FROM hosttoday/ht-docker-node:npmts FROM hosttoday/ht-docker-node:npmci
COPY ./buildContextDir /workspace COPY ./buildContextDir /workspace
WORKDIR /workspace WORKDIR /workspace
ENV CI=true ENV CI=true
CMD ["npm","test"]; CMD ["npmci","test","stable"];

2
dist/cli.js vendored
View File

@ -1,2 +1,2 @@
#!/usr/bin/env node #!/usr/bin/env node
var index = require("./index.js"); var index = require("../dist/index.js");

17
dist/index.js vendored
View File

@ -1,14 +1,5 @@
"use strict"; "use strict";
const plugins = require("./npmdocker.plugins"); Object.defineProperty(exports, "__esModule", { value: true });
const promisechain = require("./npmdocker.promisechain"); const cli = require("./npmdocker.cli");
promisechain.run() cli.run();
.then((configArg) => { //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLHVDQUFzQztBQUV0QyxHQUFHLENBQUMsR0FBRyxFQUFFLENBQUEifQ==
if (configArg.exitCode == 0) {
plugins.beautylog.success("container ended all right!");
}
else {
plugins.beautylog.error("container ended with error!");
process.exit(1);
}
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0scUJBQXFCLENBQUMsQ0FBQTtBQUMvQyxNQUFZLFlBQVksV0FBTSwwQkFBMEIsQ0FBQyxDQUFBO0FBSXpELFlBQVksQ0FBQyxHQUFHLEVBQUU7S0FDYixJQUFJLENBQUMsQ0FBQyxTQUE4QjtJQUNqQyxFQUFFLENBQUEsQ0FBQyxTQUFTLENBQUMsUUFBUSxJQUFJLENBQUMsQ0FBQyxDQUFBLENBQUM7UUFDeEIsT0FBTyxDQUFDLFNBQVMsQ0FBQyxPQUFPLENBQUMsNEJBQTRCLENBQUMsQ0FBQztJQUM1RCxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyw2QkFBNkIsQ0FBQyxDQUFDO1FBQ3ZELE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDcEIsQ0FBQztBQUNMLENBQUMsQ0FBQyxDQUFDIn0=

1
dist/npmdocker.cli.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare let run: () => void;

51
dist/npmdocker.cli.js vendored Normal file
View File

@ -0,0 +1,51 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./npmdocker.plugins");
// modules
const ConfigModule = require("./npmdocker.config");
const DockerModule = require("./npmdocker.docker");
let npmdockerCli = new plugins.smartcli.Smartcli();
exports.run = () => {
npmdockerCli.standardTask().then((argvArg) => __awaiter(this, void 0, void 0, function* () {
let configArg = yield ConfigModule.run()
.then(DockerModule.run);
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) => __awaiter(this, void 0, void 0, function* () {
plugins.beautylog.ora.start();
plugins.beautylog.ora.text('cleaning up docker env...');
if (argvArg.all) {
plugins.beautylog.ora.text('killing any running docker containers...');
yield plugins.smartshell.exec(`docker kill $(docker ps -q)`);
plugins.beautylog.ora.text('removing stopped containers...');
yield plugins.smartshell.exec(`docker rm $(docker ps -a -q)`);
plugins.beautylog.ora.text('removing images...');
yield plugins.smartshell.exec(`docker rmi $(docker images -q -f dangling=true)`);
plugins.beautylog.ora.text('removing all other images...');
yield plugins.smartshell.exec(`docker rmi $(docker images -a -q)`);
plugins.beautylog.ora.text('removing all volumes...');
yield plugins.smartshell.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) => __awaiter(this, void 0, void 0, function* () {
plugins.beautylog.ok('Starting speedtest');
yield plugins.smartshell.exec(`docker pull tianon/speedtest && docker run --rm tianon/speedtest`);
}));
npmdockerCli.startParse();
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLCtDQUE4QztBQUc5QyxVQUFVO0FBQ1YsbURBQWtEO0FBQ2xELG1EQUFrRDtBQUVsRCxJQUFJLFlBQVksR0FBRyxJQUFJLE9BQU8sQ0FBQyxRQUFRLENBQUMsUUFBUSxFQUFFLENBQUE7QUFFdkMsUUFBQSxHQUFHLEdBQUc7SUFDZixZQUFZLENBQUMsWUFBWSxFQUFFLENBQUMsSUFBSSxDQUFDLENBQU8sT0FBTztRQUM3QyxJQUFJLFNBQVMsR0FBRyxNQUFNLFlBQVksQ0FBQyxHQUFHLEVBQUU7YUFDckMsSUFBSSxDQUFDLFlBQVksQ0FBQyxHQUFHLENBQUMsQ0FBQTtRQUN6QixFQUFFLENBQUMsQ0FBQyxTQUFTLENBQUMsUUFBUSxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7WUFDN0IsT0FBTyxDQUFDLFNBQVMsQ0FBQyxPQUFPLENBQUMsNEJBQTRCLENBQUMsQ0FBQTtRQUN6RCxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDTixPQUFPLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyw2QkFBNkIsQ0FBQyxDQUFBO1lBQ3RELE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDakIsQ0FBQztJQUNILENBQUMsQ0FBQSxDQUFDLENBQUE7SUFFRixZQUFZLENBQUMsVUFBVSxDQUFDLE9BQU8sQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFPLE9BQU87UUFDbEQsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsS0FBSyxFQUFFLENBQUE7UUFDN0IsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLDJCQUEyQixDQUFDLENBQUE7UUFDdkQsRUFBRSxDQUFDLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUM7WUFDaEIsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLDBDQUEwQyxDQUFDLENBQUE7WUFDdEUsTUFBTSxPQUFPLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQyw2QkFBNkIsQ0FBQyxDQUFBO1lBRTVELE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxnQ0FBZ0MsQ0FBQyxDQUFBO1lBQzVELE1BQU0sT0FBTyxDQUFDLFVBQVUsQ0FBQyxJQUFJLENBQUMsOEJBQThCLENBQUMsQ0FBQTtZQUU3RCxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsb0JBQW9CLENBQUMsQ0FBQTtZQUNoRCxNQUFNLE9BQU8sQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLGlEQUFpRCxDQUFDLENBQUE7WUFFaEYsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLDhCQUE4QixDQUFDLENBQUE7WUFDMUQsTUFBTSxPQUFPLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQyxtQ0FBbUMsQ0FBQyxDQUFBO1lBRWxFLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyx5QkFBeUIsQ0FBQyxDQUFBO1lBQ3JELE1BQU0sT0FBTyxDQUFDLFVBQVUsQ0FBQyxJQUFJLENBQUMsMERBQTBELENBQUMsQ0FBQTtRQUMzRixDQUFDO1FBQ0QsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsS0FBSyxDQUFDLGtDQUFrQyxDQUFDLENBQUE7SUFDakUsQ0FBQyxDQUFBLENBQUMsQ0FBQTtJQUVGLFlBQVksQ0FBQyxVQUFVLENBQUMsV0FBVyxDQUFDLENBQUMsSUFBSSxDQUFDLENBQU8sT0FBTztRQUN0RCxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxvQkFBb0IsQ0FBQyxDQUFBO1FBQzFDLE1BQU0sT0FBTyxDQUFDLFVBQVUsQ0FBQyxJQUFJLENBQUMsa0VBQWtFLENBQUMsQ0FBQTtJQUNuRyxDQUFDLENBQUEsQ0FBQyxDQUFBO0lBRUYsWUFBWSxDQUFDLFVBQVUsRUFBRSxDQUFBO0FBQzNCLENBQUMsQ0FBQSJ9

View File

@ -1,9 +1,9 @@
/// <reference types="q" /> import { IKeyValueObject } from 'qenv';
import * as plugins from "./npmdocker.plugins";
export interface IConfig { export interface IConfig {
baseImage: string; baseImage: string;
command: string; command: string;
dockerSock: boolean; dockerSock: boolean;
exitCode?: number; exitCode?: number;
keyValueObjectArray: IKeyValueObject[];
} }
export declare let run: () => plugins.q.Promise<{}>; export declare let run: () => Promise<IConfig>;

View File

@ -1,16 +1,39 @@
"use strict"; "use strict";
const plugins = require("./npmdocker.plugins"); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
let config = plugins.npmextra.dataFor({ return new (P || (P = Promise))(function (resolve, reject) {
toolName: "npmdocker", function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
defaultSettings: { function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
baseImage: "hosttoday/ht-docker-node:npmts", function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
command: "npm test", step((generator = generator.apply(thisArg, _arguments || [])).next());
dockerSock: false });
}
});
exports.run = () => {
let done = plugins.q.defer();
done.resolve(config);
return done.promise;
}; };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHFCQUFxQixDQUFDLENBQUE7QUFVL0MsSUFBSSxNQUFNLEdBQVcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxPQUFPLENBQUM7SUFDMUMsUUFBUSxFQUFDLFdBQVc7SUFDcEIsZUFBZSxFQUFFO1FBQ2IsU0FBUyxFQUFDLGdDQUFnQztRQUMxQyxPQUFPLEVBQUMsVUFBVTtRQUNsQixVQUFVLEVBQUUsS0FBSztLQUNwQjtDQUNKLENBQUMsQ0FBQztBQUVRLFdBQUcsR0FBRztJQUNiLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IsSUFBSSxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUNyQixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztBQUN4QixDQUFDLENBQUEifQ== Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./npmdocker.plugins");
const paths = require("./npmdocker.paths");
;
let getQenvKeyValueObject = () => __awaiter(this, void 0, void 0, function* () {
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 = [];
}
;
return qenvKeyValueObjectArray;
});
let buildConfig = (qenvKeyValueObjectArrayArg) => __awaiter(this, void 0, void 0, function* () {
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
});
return config;
});
exports.run = () => __awaiter(this, void 0, void 0, function* () {
let config = yield getQenvKeyValueObject().then(buildConfig);
return config;
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLCtDQUE4QztBQUM5QywyQ0FBMEM7QUFXekMsQ0FBQztBQUVGLElBQUkscUJBQXFCLEdBQUc7SUFDMUIsSUFBSSx1QkFBMEMsQ0FBQTtJQUM5QyxFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxjQUFjLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLEdBQUcsRUFBRSxVQUFVLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUNsRix1QkFBdUIsR0FBRyxJQUFJLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxHQUFHLEVBQUUsU0FBUyxDQUFDLENBQUMsbUJBQW1CLENBQUE7SUFDM0YsQ0FBQztJQUFDLElBQUksQ0FBQyxDQUFDO1FBQ04sdUJBQXVCLEdBQUcsRUFBRSxDQUFBO0lBQzlCLENBQUM7SUFBQSxDQUFDO0lBQ0YsTUFBTSxDQUFDLHVCQUF1QixDQUFBO0FBQ2hDLENBQUMsQ0FBQSxDQUFBO0FBRUQsSUFBSSxXQUFXLEdBQUcsQ0FBTywwQkFBNkM7SUFDcEUsSUFBSSxRQUFRLEdBQUcsSUFBSSxPQUFPLENBQUMsUUFBUSxDQUFDLFFBQVEsQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUE7SUFDdkQsSUFBSSxNQUFNLEdBQUcsUUFBUSxDQUFDLE9BQU8sQ0FDM0IsV0FBVyxFQUNYO1FBQ0UsU0FBUyxFQUFFLGdDQUFnQztRQUMzQyxPQUFPLEVBQUUsVUFBVTtRQUNuQixVQUFVLEVBQUUsS0FBSztRQUNqQixtQkFBbUIsRUFBRSwwQkFBMEI7S0FDaEQsQ0FDRixDQUFBO0lBQ0QsTUFBTSxDQUFDLE1BQU0sQ0FBQTtBQUNmLENBQUMsQ0FBQSxDQUFBO0FBRVUsUUFBQSxHQUFHLEdBQUc7SUFDZixJQUFJLE1BQU0sR0FBRyxNQUFNLHFCQUFxQixFQUFFLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFBO0lBQzVELE1BQU0sQ0FBQyxNQUFNLENBQUE7QUFDZixDQUFDLENBQUEsQ0FBQSJ9

View File

@ -1,3 +1,2 @@
/// <reference types="q" /> import { IConfig } from './npmdocker.config';
import * as plugins from "./npmdocker.plugins"; export declare let run: (configArg: IConfig) => Promise<IConfig>;
export declare let run: (configArg: any) => plugins.q.Promise<{}>;

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./npmdocker.plugins"); const plugins = require("./npmdocker.plugins");
// directories // directories
exports.cwd = process.cwd(); exports.cwd = process.cwd();
@ -9,4 +10,4 @@ exports.buildContextDir = plugins.path.join(exports.assets, "buildContextDir");
plugins.smartfile.fs.ensureDirSync(exports.buildContextDir); plugins.smartfile.fs.ensureDirSync(exports.buildContextDir);
// files // files
exports.dockerfile = plugins.path.join(exports.assets, "Dockerfile"); exports.dockerfile = plugins.path.join(exports.assets, "Dockerfile");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFBcUIsQ0FBQyxDQUFBO0FBRS9DLGNBQWM7QUFDSCxXQUFHLEdBQUcsT0FBTyxDQUFDLEdBQUcsRUFBRSxDQUFDO0FBQ3BCLG1CQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFFLEtBQUssQ0FBQyxDQUFDO0FBQ2xELGNBQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxtQkFBVyxFQUFFLFNBQVMsQ0FBQyxDQUFDO0FBQzlELE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyxjQUFNLENBQUMsQ0FBQztBQUVoQyx1QkFBZSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLGNBQU0sRUFBQyxpQkFBaUIsQ0FBQyxDQUFDO0FBQ3pFLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyx1QkFBZSxDQUFDLENBQUM7QUFFcEQsUUFBUTtBQUNHLGtCQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsY0FBTSxFQUFFLFlBQVksQ0FBQyxDQUFDIn0= //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQStDO0FBRS9DLGNBQWM7QUFDSCxRQUFBLEdBQUcsR0FBRyxPQUFPLENBQUMsR0FBRyxFQUFFLENBQUM7QUFDcEIsUUFBQSxXQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFFLEtBQUssQ0FBQyxDQUFDO0FBQ2xELFFBQUEsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLG1CQUFXLEVBQUUsU0FBUyxDQUFDLENBQUM7QUFDOUQsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsYUFBYSxDQUFDLGNBQU0sQ0FBQyxDQUFDO0FBRWhDLFFBQUEsZUFBZSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLGNBQU0sRUFBQyxpQkFBaUIsQ0FBQyxDQUFDO0FBQ3pFLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyx1QkFBZSxDQUFDLENBQUM7QUFFcEQsUUFBUTtBQUNHLFFBQUEsVUFBVSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLGNBQU0sRUFBRSxZQUFZLENBQUMsQ0FBQyJ9

View File

@ -1,8 +1,12 @@
import "typings-global"; import 'typings-global';
export import beautylog = require("beautylog"); import * as beautylog from 'beautylog';
export import npmextra = require("npmextra"); import * as npmextra from 'npmextra';
export import path = require("path"); import * as path from 'path';
export import q = require("q"); import * as projectinfo from 'projectinfo';
export import shelljs = require("shelljs"); import * as q from 'smartq';
export import smartfile = require("smartfile"); import * as qenv from 'qenv';
export import smartstring = require("smartstring"); import * as smartcli from 'smartcli';
import * as smartfile from 'smartfile';
import * as smartshell from 'smartshell';
import * as smartstring from 'smartstring';
export { beautylog, npmextra, path, projectinfo, q, qenv, smartcli, smartfile, smartshell, smartstring };

View File

@ -1,10 +1,24 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global"); require("typings-global");
exports.beautylog = require("beautylog"); const beautylog = require("beautylog");
exports.npmextra = require("npmextra"); exports.beautylog = beautylog;
exports.path = require("path"); const npmextra = require("npmextra");
exports.q = require("q"); exports.npmextra = npmextra;
exports.shelljs = require("shelljs"); const path = require("path");
exports.smartfile = require("smartfile"); exports.path = path;
exports.smartstring = require("smartstring"); const projectinfo = require("projectinfo");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1kb2NrZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNqQyxnQkFBUSxXQUFXLFVBQVUsQ0FBQyxDQUFDO0FBQy9CLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDakIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9 exports.projectinfo = projectinfo;
const q = require("smartq");
exports.q = q;
const qenv = require("qenv");
exports.qenv = qenv;
const smartcli = require("smartcli");
exports.smartcli = smartcli;
const smartfile = require("smartfile");
exports.smartfile = smartfile;
const smartshell = require("smartshell");
exports.smartshell = smartshell;
const smartstring = require("smartstring");
exports.smartstring = smartstring;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1kb2NrZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qix1Q0FBc0M7QUFZcEMsOEJBQVM7QUFYWCxxQ0FBb0M7QUFZbEMsNEJBQVE7QUFYViw2QkFBNEI7QUFZMUIsb0JBQUk7QUFYTiwyQ0FBMEM7QUFZeEMsa0NBQVc7QUFYYiw0QkFBMkI7QUFZekIsY0FBQztBQVhILDZCQUE0QjtBQVkxQixvQkFBSTtBQVhOLHFDQUFvQztBQVlsQyw0QkFBUTtBQVhWLHVDQUFzQztBQVlwQyw4QkFBUztBQVhYLHlDQUF3QztBQVl0QyxnQ0FBVTtBQVhaLDJDQUEwQztBQVl4QyxrQ0FBVyJ9

View File

@ -1,5 +0,0 @@
/// <reference types="q" />
import * as plugins from "./npmdocker.plugins";
import { Ora } from "beautylog";
export declare let npmdockerOra: Ora;
export declare let run: () => plugins.q.Promise<{}>;

View File

@ -1,18 +0,0 @@
"use strict";
const plugins = require("./npmdocker.plugins");
const beautylog_1 = require("beautylog");
//modules
const ConfigModule = require("./npmdocker.config");
const DockerModule = require("./npmdocker.docker");
exports.npmdockerOra = new beautylog_1.Ora("npmdocker", "blue");
exports.npmdockerOra.start();
exports.run = () => {
let done = plugins.q.defer();
ConfigModule.run()
.then(DockerModule.run)
.then((configArg) => {
done.resolve(configArg);
});
return done.promise;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnByb21pc2VjaGFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5wcm9taXNlY2hhaW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHFCQUFxQixDQUFDLENBQUE7QUFFL0MsNEJBQWtCLFdBQVcsQ0FBQyxDQUFBO0FBQzlCLFNBQVM7QUFDVCxNQUFZLFlBQVksV0FBTSxvQkFBb0IsQ0FBQyxDQUFBO0FBQ25ELE1BQVksWUFBWSxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFFeEMsb0JBQVksR0FBRyxJQUFJLGVBQUcsQ0FBQyxXQUFXLEVBQUMsTUFBTSxDQUFDLENBQUM7QUFDdEQsb0JBQVksQ0FBQyxLQUFLLEVBQUUsQ0FBQztBQUNWLFdBQUcsR0FBRztJQUNiLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IsWUFBWSxDQUFDLEdBQUcsRUFBRTtTQUNiLElBQUksQ0FBQyxZQUFZLENBQUMsR0FBRyxDQUFDO1NBQ3RCLElBQUksQ0FBQyxDQUFDLFNBQVM7UUFDWixJQUFJLENBQUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0lBQzVCLENBQUMsQ0FBQyxDQUFBO0lBQ04sTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDeEIsQ0FBQyxDQUFBIn0=

View File

@ -1,4 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./npmdocker.plugins"); const plugins = require("./npmdocker.plugins");
exports.dockerfileSnippet = (optionsArg) => { exports.dockerfileSnippet = (optionsArg) => {
let commandArray = optionsArg.command.split(/\s/); let commandArray = optionsArg.command.split(/\s/);
@ -18,4 +19,4 @@ exports.dockerfileSnippet = (optionsArg) => {
CMD [${commandString}]; CMD [${commandString}];
`); `);
}; };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnNuaXBwZXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnNuaXBwZXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFBcUIsQ0FBQyxDQUFBO0FBT3BDLHlCQUFpQixHQUFHLENBQUMsVUFBNkI7SUFDekQsSUFBSSxZQUFZLEdBQUcsVUFBVSxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDbEQsSUFBSSxhQUFhLEdBQVUsRUFBRSxDQUFDO0lBQzlCLEdBQUcsQ0FBQSxDQUFDLElBQUksVUFBVSxJQUFJLFlBQVksQ0FBQyxDQUFBLENBQUM7UUFDaEMsRUFBRSxDQUFBLENBQUMsQ0FBQyxDQUFDLGFBQWEsSUFBSSxFQUFFLENBQUMsQ0FBQyxDQUFBLENBQUM7WUFDdkIsYUFBYSxHQUFHLGFBQWEsR0FBRyxHQUFHLENBQUM7UUFDeEMsQ0FBQztRQUNELGFBQWEsR0FBRyxhQUFhLEdBQUcsR0FBRyxHQUFHLFVBQVUsR0FBRyxHQUFHLENBQUM7SUFDM0QsQ0FBQztJQUFBLENBQUM7SUFDRixNQUFNLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDO2VBQ2pDLFVBQVUsQ0FBQyxTQUFTOzs7O2VBSXBCLGFBQWE7S0FDdkIsQ0FBQyxDQUFDO0FBQ1AsQ0FBQyxDQUFBIn0= //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnNuaXBwZXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnNuaXBwZXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQStDO0FBT3BDLFFBQUEsaUJBQWlCLEdBQUcsQ0FBQyxVQUE2QjtJQUN6RCxJQUFJLFlBQVksR0FBRyxVQUFVLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsQ0FBQztJQUNsRCxJQUFJLGFBQWEsR0FBVSxFQUFFLENBQUM7SUFDOUIsR0FBRyxDQUFBLENBQUMsSUFBSSxVQUFVLElBQUksWUFBWSxDQUFDLENBQUEsQ0FBQztRQUNoQyxFQUFFLENBQUEsQ0FBQyxDQUFDLENBQUMsYUFBYSxJQUFJLEVBQUUsQ0FBQyxDQUFDLENBQUEsQ0FBQztZQUN2QixhQUFhLEdBQUcsYUFBYSxHQUFHLEdBQUcsQ0FBQztRQUN4QyxDQUFDO1FBQ0QsYUFBYSxHQUFHLGFBQWEsR0FBRyxHQUFHLEdBQUcsVUFBVSxHQUFHLEdBQUcsQ0FBQztJQUMzRCxDQUFDO0lBQUEsQ0FBQztJQUNGLE1BQU0sQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLE1BQU0sQ0FBQyxTQUFTLENBQUM7ZUFDakMsVUFBVSxDQUFDLFNBQVM7Ozs7ZUFJcEIsYUFBYTtLQUN2QixDQUFDLENBQUM7QUFDUCxDQUFDLENBQUEifQ==

View File

@ -1,6 +1,6 @@
{ {
"name": "npmdocker", "name": "npmdocker",
"version": "1.1.4", "version": "1.2.5",
"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",
@ -11,15 +11,17 @@
"test": "test" "test": "test"
}, },
"scripts": { "scripts": {
"test": "(npm run clean && npm run compile && npm run setupCheck && npm run check)", "test": "(npm run clean && npm run compile && npm run setupCheck && npm run testStandard && npm run testSpeed && npm run testClean)",
"testStandard": "(cd test/ && node ../dist/index.js)",
"testSpeed": "(cd test/ && node ../dist/index.js speedtest)",
"testClean": "(cd test/ && node ../dist/index.js clean --all)",
"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/)"
"check": "(cd test/ && node ../dist/index.js)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+ssh://git@gitlab.com/pushrocks/npmdocker.git" "url": "git+ssh://git@gitlab.com/gitzone/npmdocker.git"
}, },
"keywords": [ "keywords": [
"docker" "docker"
@ -27,24 +29,21 @@
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://gitlab.com/pushrocks/npmdocker/issues" "url": "https://gitlab.com/gitzone/npmdocker/issues"
},
"homepage": "https://gitlab.com/pushrocks/npmdocker#README",
"devDependencies": {
"npmts-g": "^5.2.6",
"should": "^10.0.0",
"typings-test": "^1.0.1"
}, },
"homepage": "https://gitlab.com/gitzone/npmdocker#README",
"devDependencies": {},
"dependencies": { "dependencies": {
"@types/q": "^0.0.27", "@types/shelljs": "0.x.x",
"@types/shelljs": "^0.3.27", "beautylog": "^6.1.5",
"beautylog": "^5.0.14", "npmextra": "^2.0.5",
"npmextra": "^1.0.8", "projectinfo": "^3.0.2",
"q": "^1.4.1", "qenv": "^1.1.3",
"rxjs": "^5.0.0-beta.10", "smartcli": "^2.0.1",
"shelljs": "^0.7.0", "smartfile": "^4.1.9",
"smartfile": "^4.0.11", "smartq": "^1.1.1",
"smartstring": "^2.0.15", "smartshell": "^1.0.6",
"typings-global": "^1.0.6" "smartstring": "^2.0.24",
"typings-global": "^1.0.14"
} }
} }

View File

@ -1,15 +1,4 @@
import * as plugins from "./npmdocker.plugins"; import * as plugins from './npmdocker.plugins'
import * as promisechain from "./npmdocker.promisechain"; import * as cli from './npmdocker.cli'
import * as ConfigModule from "./npmdocker.config";
promisechain.run()
.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);
}
});
cli.run()

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

@ -0,0 +1,50 @@
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().then(async (argvArg) => {
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!')
process.exit(1)
}
})
npmdockerCli.addCommand('clean').then(async (argvArg) => {
plugins.beautylog.ora.start()
plugins.beautylog.ora.text('cleaning up docker env...')
if (argvArg.all) {
plugins.beautylog.ora.text('killing any running docker containers...')
await plugins.smartshell.exec(`docker kill $(docker ps -q)`)
plugins.beautylog.ora.text('removing stopped containers...')
await plugins.smartshell.exec(`docker rm $(docker ps -a -q)`)
plugins.beautylog.ora.text('removing images...')
await plugins.smartshell.exec(`docker rmi $(docker images -q -f dangling=true)`)
plugins.beautylog.ora.text('removing all other images...')
await plugins.smartshell.exec(`docker rmi $(docker images -a -q)`)
plugins.beautylog.ora.text('removing all volumes...')
await plugins.smartshell.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`)
}
plugins.beautylog.ora.endOk('docker environment now is clean!')
})
npmdockerCli.addCommand('speedtest').then(async (argvArg) => {
plugins.beautylog.ok('Starting speedtest')
await plugins.smartshell.exec(`docker pull tianon/speedtest && docker run --rm tianon/speedtest`)
})
npmdockerCli.startParse()
}

View File

@ -1,24 +1,42 @@
import * as plugins from "./npmdocker.plugins"; import * as plugins from './npmdocker.plugins'
import * as paths from "./npmdocker.paths"; import * as paths from "./npmdocker.paths"
// interfaces
import { IKeyValueObject } from 'qenv'
export interface IConfig { export interface IConfig {
baseImage:string; baseImage: string
command:string; command: string
dockerSock:boolean; dockerSock: boolean
exitCode?:number 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 config:IConfig = plugins.npmextra.dataFor({ let buildConfig = async (qenvKeyValueObjectArrayArg: IKeyValueObject[]) => {
toolName:"npmdocker", let npmextra = new plugins.npmextra.Npmextra(paths.cwd)
defaultSettings: { let config = npmextra.dataFor<IConfig>(
baseImage:"hosttoday/ht-docker-node:npmts", 'npmdocker',
command:"npm test", {
dockerSock: false baseImage: 'hosttoday/ht-docker-node:npmts',
command: 'npm test',
dockerSock: false,
keyValueObjectArray: qenvKeyValueObjectArrayArg
} }
}); )
return config
}
export let run = () => { export let run = async (): Promise<IConfig> => {
let done = plugins.q.defer(); let config = await getQenvKeyValueObject().then(buildConfig)
done.resolve(config); return config
return done.promise; }
}

View File

@ -1,137 +1,165 @@
import * as plugins from "./npmdocker.plugins"; import * as plugins from './npmdocker.plugins';
import * as paths from "./npmdocker.paths"; import * as paths from './npmdocker.paths';
import * as snippets from "./npmdocker.snippets"; import * as snippets from './npmdocker.snippets'
import {npmdockerOra} from "./npmdocker.promisechain"; // interfaces
import { IConfig } from './npmdocker.config'
let config; let config: IConfig
/**
* the docker data used to build the internal testing container
*/
let dockerData = { let dockerData = {
imageTag: "npmdocker-temp-image:latest", imageTag: 'npmdocker-temp-image:latest',
containerName: "npmdocker-temp-container" containerName: 'npmdocker-temp-container',
}; dockerProjectMountString: '',
dockerSockString: '',
dockerEnvString: ''
}
/** /**
* check if docker is available * check if docker is available
*/ */
let checkDocker = () => { let checkDocker = () => {
let done = plugins.q.defer(); let done = plugins.q.defer()
npmdockerOra.text("checking docker..."); plugins.beautylog.ora.text('checking docker...')
if(plugins.shelljs.which("docker")){ if (plugins.smartshell.which('docker')) {
plugins.beautylog.ok("Docker found!") plugins.beautylog.ok('Docker found!')
done.resolve(); done.resolve()
} else { } else {
done.reject(new Error("docker not found on this machine")); done.reject(new Error('docker not found on this machine'))
} }
return done.promise; return done.promise
}; }
/** /**
* builds the Dockerfile according to the config in the project * builds the Dockerfile according to the config in the project
*/ */
let buildDockerFile = () => { let buildDockerFile = () => {
let done = plugins.q.defer(); let done = plugins.q.defer()
npmdockerOra.text("building Dockerfile..."); plugins.beautylog.ora.text('building Dockerfile...')
let dockerfile:string = snippets.dockerfileSnippet({ let dockerfile: string = snippets.dockerfileSnippet({
baseImage:config.baseImage, baseImage: config.baseImage,
command:config.command command: config.command
}); })
plugins.beautylog.info(`Base image is: ${config.baseImage}`); plugins.beautylog.info(`Base image is: ${config.baseImage}`)
plugins.beautylog.info(`Command is: ${config.command}`); plugins.beautylog.info(`Command is: ${config.command}`)
plugins.smartfile.memory.toFsSync(dockerfile,paths.dockerfile); plugins.smartfile.memory.toFsSync(dockerfile, paths.dockerfile)
plugins.beautylog.ok("Dockerfile created!"); plugins.beautylog.ok('Dockerfile created!')
done.resolve(); done.resolve()
return done.promise return done.promise
}; }
/** /**
* builds the Dockerimage from the built Dockerfile * builds the Dockerimage from the built Dockerfile
*/ */
let buildDockerImage = () => { let buildDockerImage = async () => {
let done = plugins.q.defer(); plugins.beautylog.ora.text('pulling latest base image from registry...')
npmdockerOra.text("pulling latest base image from registry..."); await plugins.smartshell.execSilent(
plugins.shelljs.exec(`docker pull ${config.baseImage}`,{ `docker pull ${config.baseImage}`
silent:true ).then(async () => {
},() => { plugins.beautylog.ora.text('building Dockerimage...')
npmdockerOra.text("building Dockerimage..."); // are we creating a build context form project ?
// are we creating a build context form project ? if (process.env.CI === 'true') {
if(process.env.CI == "true"){ plugins.beautylog.ora.text('creating build context...')
npmdockerOra.text("creating build context..."); plugins.smartfile.fs.copySync(paths.cwd, paths.buildContextDir)
plugins.smartfile.fs.copySync(paths.cwd,paths.buildContextDir); }
} await plugins.smartshell.execSilent(
plugins.shelljs.exec(`docker build -f ${paths.dockerfile} -t ${dockerData.imageTag} ${paths.assets}`,{ `docker build -f ${paths.dockerfile} -t ${dockerData.imageTag} ${paths.assets}`
silent:true ).then(async () => {
},() => { plugins.beautylog.ok('Dockerimage built!')
plugins.beautylog.ok("Dockerimage built!") })
done.resolve(); })
}); }
}); // first pull latest version of baseImage
return done.promise let buildDockerProjectMountString = async () => {
}; if (process.env.CI !== 'true') {
dockerData.dockerProjectMountString = `-v ${paths.cwd}:/workspace`
};
}
/**
* 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} `
};
}
/**
* creates string to mount the docker.sock inside the testcontainer
*/
let buildDockerSockString = async () => {
if (config.dockerSock) {
dockerData.dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`
};
}
/** /**
* creates a container by running the built Dockerimage * creates a container by running the built Dockerimage
*/ */
let runDockerImage = () => { let runDockerImage = async () => {
let done = plugins.q.defer(); let done = plugins.q.defer()
npmdockerOra.text("starting Container..."); plugins.beautylog.ora.text('starting Container...')
npmdockerOra.end(); plugins.beautylog.ora.end()
// Are we mounting the project directory? plugins.beautylog.log('now running Dockerimage')
let dockerProjectMountString:string = ""; config.exitCode = (await plugins.smartshell.exec(`docker run ${dockerData.dockerProjectMountString} ${dockerData.dockerSockString} ${dockerData.dockerEnvString} --name ${dockerData.containerName} ${dockerData.imageTag}`)).exitCode
if(process.env.CI != "true"){ }
dockerProjectMountString = `-v ${paths.cwd}:/workspace`
};
// Are we mounting docker.sock?
let dockerSockString:string = "";
if(config.dockerSock){
dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`
};
config.exitCode = plugins.shelljs.exec(`docker run ${dockerProjectMountString} ${dockerSockString} --name ${dockerData.containerName} ${dockerData.imageTag}`).code;
done.resolve();
return done.promise;
};
let deleteDockerContainter = () => { /**
let done = plugins.q.defer(); * cleans up: deletes the test container
plugins.shelljs.exec(`docker rm ${dockerData.containerName}`,{ */
silent:true let deleteDockerContainer = async () => {
}); await plugins.smartshell.execSilent(`docker rm -f ${dockerData.containerName}`)
done.resolve(); }
plugins.beautylog.ok("removed test container!");
return done.promise
};
let deleteDockerImage = () => { /**
let done = plugins.q.defer(); * cleans up deletes the test image
plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`,{ */
silent:true let deleteDockerImage = async () => {
}); await plugins.smartshell.exec(`docker rmi ${dockerData.imageTag}`)
plugins.beautylog.ok("removed test image!"); }
plugins.beautylog.ok("Cleaned up!");
done.resolve();
return done.promise
};
let deleteBuildContext = () => { /**
let done = plugins.q.defer(); * cleans up, deletes the build context
plugins.smartfile.fs.removeSync(paths.buildContextDir); */
done.resolve(); let deleteBuildContext = async () => {
return done.promise; await plugins.smartfile.fs.remove(paths.buildContextDir)
}
let preClean = async () => {
await deleteDockerImage()
.then(deleteDockerContainer)
.then(async () => {
plugins.beautylog.ok('ensured clean Docker environment!')
})
}
let postClean = async () => {
await deleteDockerContainer()
.then(deleteDockerImage)
.then(deleteBuildContext)
.then(async () => {
plugins.beautylog.ok('cleaned up!')
})
} }
export let run = (configArg) => { export let run = async (configArg: IConfig): Promise<IConfig> => {
let done = plugins.q.defer(); plugins.beautylog.ora.start()
config = configArg; config = configArg
checkDocker() let resultConfig = await checkDocker()
.then(buildDockerFile) .then(preClean)
.then(buildDockerImage) .then(buildDockerFile)
.then(runDockerImage) .then(buildDockerImage)
.then(deleteDockerContainter) .then(buildDockerProjectMountString)
.then(deleteDockerImage) .then(buildDockerEnvString)
.then(deleteBuildContext) .then(buildDockerSockString)
.then(() => { .then(runDockerImage)
done.resolve(config); .then(postClean)
}) .catch(err => { console.log(err) })
return done.promise; return config
} }

View File

@ -1,8 +1,24 @@
import "typings-global"; import 'typings-global'
export import beautylog = require("beautylog"); import * as beautylog from 'beautylog'
export import npmextra = require("npmextra"); import * as npmextra from 'npmextra'
export import path = require("path"); import * as path from 'path'
export import q = require("q"); import * as projectinfo from 'projectinfo'
export import shelljs = require("shelljs"); import * as q from 'smartq'
export import smartfile = require("smartfile"); import * as qenv from 'qenv'
export import smartstring = require("smartstring"); import * as smartcli from 'smartcli'
import * as smartfile from 'smartfile'
import * as smartshell from 'smartshell'
import * as smartstring from 'smartstring'
export {
beautylog,
npmextra,
path,
projectinfo,
q,
qenv,
smartcli,
smartfile,
smartshell,
smartstring
}

View File

@ -1,18 +0,0 @@
import * as plugins from "./npmdocker.plugins";
import * as paths from "./npmdocker.paths";
import {Ora} from "beautylog";
//modules
import * as ConfigModule from "./npmdocker.config";
import * as DockerModule from "./npmdocker.docker";
export let npmdockerOra = new Ora("npmdocker","blue");
npmdockerOra.start();
export let run = () => {
let done = plugins.q.defer();
ConfigModule.run()
.then(DockerModule.run)
.then((configArg) => {
done.resolve(configArg);
})
return done.promise;
}

3
tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}

1390
yarn.lock Normal file

File diff suppressed because it is too large Load Diff