Compare commits

...

35 Commits

Author SHA1 Message Date
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
b9618a86a6 1.1.4 2016-07-29 03:17:09 +02:00
f1d232a333 add right images to gitlab ci 2016-07-29 03:16:59 +02:00
aa66a3bb86 1.1.3 2016-07-29 03:16:09 +02:00
fbaeb63e4d fix gitlab ci 2016-07-29 03:16:04 +02:00
d60e6a4aa6 1.1.2 2016-07-29 03:09:51 +02:00
90e3e24803 fix gitlab.yml 2016-07-29 03:09:25 +02:00
2372ad7681 fix gitlab ci 2016-07-29 03:05:01 +02:00
02490ef011 fix gitlab ci 2016-07-29 03:03:07 +02:00
2388da50a1 fix gitlab ci 2016-07-29 00:55:11 +02:00
141358595e fix gitlab ci 2016-07-29 00:54:25 +02:00
fc54362312 1.1.1 2016-07-29 00:52:38 +02:00
f9f0119121 now has better support for docker in docker 2016-07-29 00:52:30 +02:00
46e4ed1c8b 1.1.0 2016-07-28 18:01:07 +02:00
25b3cc1045 added dockerSock option 2016-07-28 18:01:02 +02:00
ce996f43a0 Update .gitlab-ci.yml 2016-07-20 15:44:06 +00:00
4e5af75559 1.0.5 2016-07-20 00:45:39 +02:00
62396c52e9 1.0.4 2016-07-20 00:42:29 +02:00
e86773c151 add environment tag 2016-07-20 00:42:22 +02:00
00e915dc4d 1.0.3 2016-07-20 00:40:44 +02:00
687417c03d now fully working 2016-07-20 00:40:37 +02:00
0157ca94e4 wire up cli use 2016-07-19 19:53:09 +02:00
c07fa65341 1.0.2 2016-07-19 19:22:17 +02:00
778afb04cb added test folder to gitignore 2016-07-19 19:22:12 +02:00
617aec88cc removed test 2016-07-19 19:21:52 +02:00
ca0ecd4e93 now working 2016-07-19 19:21:06 +02:00
2d5054be0b update docker handling 2016-07-19 02:10:36 +02:00
ddfd314a18 improve path management 2016-07-19 02:03:54 +02:00
8c5cf3485a improve confighandling 2016-07-19 00:59:57 +02:00
e222456431 start Docker configuration 2016-07-19 00:37:13 +02:00
c5413ca11d start docker integration 2016-07-18 20:48:34 +02:00
030c3ec00d update 2016-07-17 19:00:53 +02:00
26 changed files with 588 additions and 23 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
node_modules/ node_modules/
coverage/ coverage/
docs/ docs/
test/
assets/
.nogit/ .nogit/

View File

@ -1,35 +1,43 @@
image: hosttoday/ht-docker-node:npmts image: hosttoday/ht-docker-dbase:npmts
services:
- docker:dind
stages: stages:
- test - test
- release - release
- trigger
testLEGACY: test:
stage: test stage: test
script: script:
- npmci test legacy - npm install
tags: - npm test
- docker
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags: tags:
- docker - docker
- lossless
- priv
release: release:
image: hosttoday/ht-docker-node:npmts
stage: release stage: release
environment: npmjs-com_registry
script: script:
- npmci publish - npmci publish
only: only:
- tags - tags
tags: tags:
- docker - docker
- lossless
- priv
trigger:
image: hosttoday/ht-docker-node:npmts
stage: trigger
script:
- npmci trigger
only:
- tags
tags:
- docker
- lossless
- priv

5
assets/Dockerfile Normal file
View File

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

2
dist/cli.js vendored Normal file
View File

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

15
dist/index.js vendored
View File

@ -1 +1,14 @@
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0= "use strict";
const plugins = require("./npmdocker.plugins");
const promisechain = require("./npmdocker.promisechain");
promisechain.run()
.then((configArg) => {
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=

9
dist/npmdocker.config.d.ts vendored Normal file
View File

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

16
dist/npmdocker.config.js vendored Normal file
View File

@ -0,0 +1,16 @@
"use strict";
const plugins = require("./npmdocker.plugins");
let config = plugins.npmextra.dataFor({
toolName: "npmdocker",
defaultSettings: {
baseImage: "hosttoday/ht-docker-node:npmts",
command: "npm test",
dockerSock: false
}
});
exports.run = () => {
let done = plugins.q.defer();
done.resolve(config);
return done.promise;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHFCQUFxQixDQUFDLENBQUE7QUFVL0MsSUFBSSxNQUFNLEdBQVcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxPQUFPLENBQUM7SUFDMUMsUUFBUSxFQUFDLFdBQVc7SUFDcEIsZUFBZSxFQUFFO1FBQ2IsU0FBUyxFQUFDLGdDQUFnQztRQUMxQyxPQUFPLEVBQUMsVUFBVTtRQUNsQixVQUFVLEVBQUUsS0FBSztLQUNwQjtDQUNKLENBQUMsQ0FBQztBQUVRLFdBQUcsR0FBRztJQUNiLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IsSUFBSSxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUNyQixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztBQUN4QixDQUFDLENBQUEifQ==

3
dist/npmdocker.docker.d.ts vendored Normal file
View File

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

146
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
View 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
View 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFBcUIsQ0FBQyxDQUFBO0FBRS9DLGNBQWM7QUFDSCxXQUFHLEdBQUcsT0FBTyxDQUFDLEdBQUcsRUFBRSxDQUFDO0FBQ3BCLG1CQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFFLEtBQUssQ0FBQyxDQUFDO0FBQ2xELGNBQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxtQkFBVyxFQUFFLFNBQVMsQ0FBQyxDQUFDO0FBQzlELE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyxjQUFNLENBQUMsQ0FBQztBQUVoQyx1QkFBZSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLGNBQU0sRUFBQyxpQkFBaUIsQ0FBQyxDQUFDO0FBQ3pFLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyx1QkFBZSxDQUFDLENBQUM7QUFFcEQsUUFBUTtBQUNHLGtCQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsY0FBTSxFQUFFLFlBQVksQ0FBQyxDQUFDIn0=

8
dist/npmdocker.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
import "typings-global";
export import beautylog = require("beautylog");
export import npmextra = require("npmextra");
export import path = require("path");
export import q = require("q");
export import shelljs = require("shelljs");
export import smartfile = require("smartfile");
export import smartstring = require("smartstring");

10
dist/npmdocker.plugins.js vendored Normal file
View File

@ -0,0 +1,10 @@
"use strict";
require("typings-global");
exports.beautylog = require("beautylog");
exports.npmextra = require("npmextra");
exports.path = require("path");
exports.q = require("q");
exports.shelljs = require("shelljs");
exports.smartfile = require("smartfile");
exports.smartstring = require("smartstring");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1kb2NrZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNqQyxnQkFBUSxXQUFXLFVBQVUsQ0FBQyxDQUFDO0FBQy9CLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDakIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9

5
dist/npmdocker.promisechain.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
/// <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<{}>;

18
dist/npmdocker.promisechain.js vendored Normal file
View File

@ -0,0 +1,18 @@
"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=

5
dist/npmdocker.snippets.d.ts vendored Normal file
View 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
View 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnNuaXBwZXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnNuaXBwZXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFBcUIsQ0FBQyxDQUFBO0FBT3BDLHlCQUFpQixHQUFHLENBQUMsVUFBNkI7SUFDekQsSUFBSSxZQUFZLEdBQUcsVUFBVSxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDbEQsSUFBSSxhQUFhLEdBQVUsRUFBRSxDQUFDO0lBQzlCLEdBQUcsQ0FBQSxDQUFDLElBQUksVUFBVSxJQUFJLFlBQVksQ0FBQyxDQUFBLENBQUM7UUFDaEMsRUFBRSxDQUFBLENBQUMsQ0FBQyxDQUFDLGFBQWEsSUFBSSxFQUFFLENBQUMsQ0FBQyxDQUFBLENBQUM7WUFDdkIsYUFBYSxHQUFHLGFBQWEsR0FBRyxHQUFHLENBQUM7UUFDeEMsQ0FBQztRQUNELGFBQWEsR0FBRyxhQUFhLEdBQUcsR0FBRyxHQUFHLFVBQVUsR0FBRyxHQUFHLENBQUM7SUFDM0QsQ0FBQztJQUFBLENBQUM7SUFDRixNQUFNLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDO2VBQ2pDLFVBQVUsQ0FBQyxTQUFTOzs7O2VBSXBCLGFBQWE7S0FDdkIsQ0FBQyxDQUFDO0FBQ1AsQ0FBQyxDQUFBIn0=

7
npmextra.json Normal file
View File

@ -0,0 +1,7 @@
{
"npmts":{
"mode":"default",
"cli":true,
"dockerSock":true
}
}

View File

@ -1,13 +1,21 @@
{ {
"name": "npmdocker", "name": "npmdocker",
"version": "1.0.1", "version": "1.1.6",
"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",
"bin": {
"npmdocker": "dist/cli.js"
},
"directories": { "directories": {
"test": "test" "test": "test"
}, },
"scripts": { "scripts": {
"test": "(npmts)" "test": "(npm run clean && npm run compile && npm run setupCheck && npm run check)",
"clean": "(rm -rf test/)",
"compile": "(npmts --notest)",
"setupCheck": "(git clone https://gitlab.com/sandboxzone/sandbox-npmts.git test/)",
"check": "(cd test/ && node ../dist/index.js)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -24,14 +32,19 @@
"homepage": "https://gitlab.com/pushrocks/npmdocker#README", "homepage": "https://gitlab.com/pushrocks/npmdocker#README",
"devDependencies": { "devDependencies": {
"npmts-g": "^5.2.6", "npmts-g": "^5.2.6",
"should": "^9.0.2", "should": "^10.0.0",
"typings-test": "^1.0.1" "typings-test": "^1.0.1"
}, },
"dependencies": { "dependencies": {
"beautylog": "^5.0.13", "@types/q": "^0.0.27",
"@types/shelljs": "^0.3.27",
"beautylog": "^5.0.14",
"npmextra": "^1.0.8",
"q": "^1.4.1", "q": "^1.4.1",
"rxjs": "^5.0.0-beta.10", "rxjs": "^5.0.0-beta.10",
"smartfile": "^4.0.10", "shelljs": "^0.7.0",
"smartfile": "^4.0.11",
"smartstring": "^2.0.15",
"typings-global": "^1.0.6" "typings-global": "^1.0.6"
} }
} }

View File

@ -0,0 +1,15 @@
import * as plugins from "./npmdocker.plugins";
import * as promisechain from "./npmdocker.promisechain";
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);
}
});

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

@ -0,0 +1,24 @@
import * as plugins from "./npmdocker.plugins";
import * as paths from "./npmdocker.paths";
export interface IConfig {
baseImage:string;
command:string;
dockerSock:boolean;
exitCode?:number
}
let config:IConfig = plugins.npmextra.dataFor({
toolName:"npmdocker",
defaultSettings: {
baseImage:"hosttoday/ht-docker-node:npmts",
command:"npm test",
dockerSock: false
}
});
export let run = () => {
let done = plugins.q.defer();
done.resolve(config);
return done.promise;
}

155
ts/npmdocker.docker.ts Normal file
View File

@ -0,0 +1,155 @@
import * as plugins from "./npmdocker.plugins";
import * as paths from "./npmdocker.paths";
import * as snippets from "./npmdocker.snippets";
import {npmdockerOra} from "./npmdocker.promisechain";
let config;
let dockerData = {
imageTag: "npmdocker-temp-image:latest",
containerName: "npmdocker-temp-container"
};
/**
* check if docker is available
*/
let checkDocker = () => {
let done = plugins.q.defer();
npmdockerOra.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();
npmdockerOra.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();
npmdockerOra.text("pulling latest base image from registry...");
plugins.shelljs.exec(`docker pull ${config.baseImage}`,{
silent:true
},() => {
npmdockerOra.text("building Dockerimage...");
// are we creating a build context form project ?
if(process.env.CI == "true"){
npmdockerOra.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
};
/**
* creates a container by running the built Dockerimage
*/
let runDockerImage = () => {
let done = plugins.q.defer();
npmdockerOra.text("starting Container...");
npmdockerOra.end();
// Are we mounting the project directory?
let dockerProjectMountString:string = "";
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`
};
plugins.beautylog.log("now running Dockerimage");
config.exitCode = plugins.shelljs.exec(`docker run ${dockerProjectMountString} ${dockerSockString} --name ${dockerData.containerName} ${dockerData.imageTag}`).code;
done.resolve();
return done.promise;
};
let deleteDockerContainer = () => {
let done = plugins.q.defer();
plugins.shelljs.exec(`docker rm -f ${dockerData.containerName}`,{
silent:true
});
done.resolve();
return done.promise
};
let deleteDockerImage = () => {
let done = plugins.q.defer();
plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`,{
silent:true
});
done.resolve();
return done.promise
};
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(runDockerImage)
.then(postClean)
.then(() => {
done.resolve(config);
})
return done.promise;
}

13
ts/npmdocker.paths.ts Normal file
View 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");

8
ts/npmdocker.plugins.ts Normal file
View File

@ -0,0 +1,8 @@
import "typings-global";
export import beautylog = require("beautylog");
export import npmextra = require("npmextra");
export import path = require("path");
export import q = require("q");
export import shelljs = require("shelljs");
export import smartfile = require("smartfile");
export import smartstring = require("smartstring");

View File

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

24
ts/npmdocker.snippets.ts Normal file
View 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}];
`);
}