now supports qenv

This commit is contained in:
Philipp Kunz 2016-08-04 22:25:15 +02:00
parent 30b88d36ae
commit 8778324e5b
10 changed files with 188 additions and 82 deletions

View File

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

View File

@ -1,9 +1,11 @@
/// <reference types="q" /> /// <reference types="q" />
import * as plugins from "./npmdocker.plugins"; import * as plugins from "./npmdocker.plugins";
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[];
} }
export declare let run: () => plugins.q.Promise<{}>; export declare let run: () => plugins.q.Promise<{}>;

View File

@ -1,16 +1,39 @@
"use strict"; "use strict";
const plugins = require("./npmdocker.plugins"); const plugins = require("./npmdocker.plugins");
let config = plugins.npmextra.dataFor({ const paths = require("./npmdocker.paths");
toolName: "npmdocker", ;
defaultSettings: { let getQenvKeyValueObject = () => {
baseImage: "hosttoday/ht-docker-node:npmts",
command: "npm test",
dockerSock: false
}
});
exports.run = () => {
let done = plugins.q.defer(); 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 config = plugins.npmextra.dataFor({
toolName: "npmdocker",
defaultSettings: {
baseImage: "hosttoday/ht-docker-node:npmts",
command: "npm run npmdocker",
dockerSock: false,
keyValueObjectArray: qenvKeyValueObjectArrayArg
}
});
done.resolve(config); done.resolve(config);
return done.promise; return done.promise;
}; };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHFCQUFxQixDQUFDLENBQUE7QUFVL0MsSUFBSSxNQUFNLEdBQVcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxPQUFPLENBQUM7SUFDMUMsUUFBUSxFQUFDLFdBQVc7SUFDcEIsZUFBZSxFQUFFO1FBQ2IsU0FBUyxFQUFDLGdDQUFnQztRQUMxQyxPQUFPLEVBQUMsVUFBVTtRQUNsQixVQUFVLEVBQUUsS0FBSztLQUNwQjtDQUNKLENBQUMsQ0FBQztBQUVRLFdBQUcsR0FBRztJQUNiLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IsSUFBSSxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUNyQixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztBQUN4QixDQUFDLENBQUEifQ== exports.run = () => {
let done = plugins.q.defer();
getQenvKeyValueObject()
.then(buildConfig)
.then(done.resolve);
return done.promise;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHFCQUFxQixDQUFDLENBQUE7QUFDL0MsTUFBWSxLQUFLLFdBQU0sbUJBQW1CLENBQUMsQ0FBQ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BMEI7U0FDbEQ7S0FDSixDQUFDLENBQUM7SUFDSCxJQUFJLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBQ3JCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3ZCLENBQUMsQ0FBQztBQUVTLFdBQUcsR0FBRztJQUNiLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IscUJBQXFCLEVBQUU7U0FDbEIsSUFBSSxDQUFDLFdBQVcsQ0FBQztTQUNqQixJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQ3hCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQSJ9

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,9 @@ import "typings-global";
export import beautylog = require("beautylog"); export import beautylog = require("beautylog");
export import npmextra = require("npmextra"); export import npmextra = require("npmextra");
export import path = require("path"); export import path = require("path");
export import projectinfo = require("projectinfo");
export import q = require("q"); export import q = require("q");
export import qenv = require("qenv");
export import shelljs = require("shelljs"); export import shelljs = require("shelljs");
export import smartfile = require("smartfile"); export import smartfile = require("smartfile");
export import smartstring = require("smartstring"); export import smartstring = require("smartstring");

View File

@ -3,8 +3,10 @@ require("typings-global");
exports.beautylog = require("beautylog"); exports.beautylog = require("beautylog");
exports.npmextra = require("npmextra"); exports.npmextra = require("npmextra");
exports.path = require("path"); exports.path = require("path");
exports.projectinfo = require("projectinfo");
exports.q = require("q"); exports.q = require("q");
exports.qenv = require("qenv");
exports.shelljs = require("shelljs"); exports.shelljs = require("shelljs");
exports.smartfile = require("smartfile"); exports.smartfile = require("smartfile");
exports.smartstring = require("smartstring"); exports.smartstring = require("smartstring");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBsdWdpbnMuanMi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 -31,20 +31,22 @@
}, },
"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.8",
"should": "^10.0.0", "should": "^10.0.0",
"typings-test": "^1.0.1" "typings-test": "^1.0.1"
}, },
"dependencies": { "dependencies": {
"@types/q": "^0.0.27", "@types/q": "0.x.x",
"@types/shelljs": "^0.3.27", "@types/shelljs": "0.x.x",
"beautylog": "^5.0.14", "beautylog": "^5.0.20",
"npmextra": "^1.0.8", "npmextra": "^1.0.8",
"projectinfo": "^1.0.3",
"q": "^1.4.1", "q": "^1.4.1",
"qenv": "^1.1.1",
"rxjs": "^5.0.0-beta.10", "rxjs": "^5.0.0-beta.10",
"shelljs": "^0.7.0", "shelljs": "^0.7.3",
"smartfile": "^4.0.11", "smartfile": "^4.0.13",
"smartstring": "^2.0.15", "smartstring": "^2.0.17",
"typings-global": "^1.0.6" "typings-global": "^1.0.6"
} }
} }

View File

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

View File

@ -2,12 +2,18 @@ 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"; import { npmdockerOra } from "./npmdocker.promisechain";
let config; // interfaces
import { IConfig } from "./npmdocker.config";
let config: IConfig;
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: ""
}; };
/** /**
@ -16,7 +22,7 @@ let dockerData = {
let checkDocker = () => { let checkDocker = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
npmdockerOra.text("checking docker..."); npmdockerOra.text("checking docker...");
if(plugins.shelljs.which("docker")){ if (plugins.shelljs.which("docker")) {
plugins.beautylog.ok("Docker found!") plugins.beautylog.ok("Docker found!")
done.resolve(); done.resolve();
} else { } else {
@ -31,13 +37,13 @@ let checkDocker = () => {
let buildDockerFile = () => { let buildDockerFile = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
npmdockerOra.text("building Dockerfile..."); npmdockerOra.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
@ -49,18 +55,18 @@ let buildDockerFile = () => {
let buildDockerImage = () => { let buildDockerImage = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
npmdockerOra.text("pulling latest base image from registry..."); npmdockerOra.text("pulling latest base image from registry...");
plugins.shelljs.exec(`docker pull ${config.baseImage}`,{ plugins.shelljs.exec(`docker pull ${config.baseImage}`, {
silent:true silent: true
},() => { }, () => {
npmdockerOra.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") {
npmdockerOra.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);
} }
plugins.shelljs.exec(`docker build -f ${paths.dockerfile} -t ${dockerData.imageTag} ${paths.assets}`,{ plugins.shelljs.exec(`docker build -f ${paths.dockerfile} -t ${dockerData.imageTag} ${paths.assets}`, {
silent:true silent: true
},() => { }, () => {
plugins.beautylog.ok("Dockerimage built!") plugins.beautylog.ok("Dockerimage built!")
done.resolve(); done.resolve();
}); });
@ -68,6 +74,34 @@ let buildDockerImage = () => {
return done.promise 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;
}
let buildDockerEnvString = () => {
let done = plugins.q.defer();
console.log(config.keyValueObjectArray);
for (let keyValueObjectArg of config.keyValueObjectArray) {
let envString = dockerData.dockerEnvString = dockerData.dockerEnvString + `-e ${keyValueObjectArg.key}=${keyValueObjectArg.value} `
};
done.resolve();
return done.promise;
}
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 * creates a container by running the built Dockerimage
*/ */
@ -75,26 +109,16 @@ let runDockerImage = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
npmdockerOra.text("starting Container..."); npmdockerOra.text("starting Container...");
npmdockerOra.end(); 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"); plugins.beautylog.log("now running Dockerimage");
config.exitCode = plugins.shelljs.exec(`docker run ${dockerProjectMountString} ${dockerSockString} --name ${dockerData.containerName} ${dockerData.imageTag}`).code; config.exitCode = plugins.shelljs.exec(`docker run ${dockerData.dockerProjectMountString} ${dockerData.dockerSockString} ${dockerData.dockerEnvString} --name ${dockerData.containerName} ${dockerData.imageTag}`).code;
done.resolve(); done.resolve();
return done.promise; return done.promise;
}; };
let deleteDockerContainer = () => { let deleteDockerContainer = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
plugins.shelljs.exec(`docker rm -f ${dockerData.containerName}`,{ plugins.shelljs.exec(`docker rm -f ${dockerData.containerName}`, {
silent:true silent: true
}); });
done.resolve(); done.resolve();
return done.promise return done.promise
@ -102,8 +126,8 @@ let deleteDockerContainer = () => {
let deleteDockerImage = () => { let deleteDockerImage = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`,{ plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`, {
silent:true silent: true
}); });
done.resolve(); done.resolve();
return done.promise return done.promise
@ -146,10 +170,13 @@ export let run = (configArg) => {
.then(preClean) .then(preClean)
.then(buildDockerFile) .then(buildDockerFile)
.then(buildDockerImage) .then(buildDockerImage)
.then(buildDockerProjectMountString)
.then(buildDockerEnvString)
.then(buildDockerSockString)
.then(runDockerImage) .then(runDockerImage)
.then(postClean) .then(postClean)
.then(() => { .then(() => {
done.resolve(config); done.resolve(config);
}) }).catch(err => {console.log(err)});
return done.promise; return done.promise;
} }

View File

@ -2,7 +2,9 @@ import "typings-global";
export import beautylog = require("beautylog"); export import beautylog = require("beautylog");
export import npmextra = require("npmextra"); export import npmextra = require("npmextra");
export import path = require("path"); export import path = require("path");
export import projectinfo = require("projectinfo");
export import q = require("q"); export import q = require("q");
export import qenv = require("qenv");
export import shelljs = require("shelljs"); export import shelljs = require("shelljs");
export import smartfile = require("smartfile"); export import smartfile = require("smartfile");
export import smartstring = require("smartstring"); export import smartstring = require("smartstring");