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
WORKDIR /workspace
ENV CI=true
CMD ["npm","test"];
CMD ["npm","run","npmdocker"];

View File

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

View File

@ -1,16 +1,39 @@
"use strict";
const plugins = require("./npmdocker.plugins");
let config = plugins.npmextra.dataFor({
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 config = plugins.npmextra.dataFor({
toolName: "npmdocker",
defaultSettings: {
baseImage: "hosttoday/ht-docker-node:npmts",
command: "npm test",
dockerSock: false
command: "npm run npmdocker",
dockerSock: false,
keyValueObjectArray: qenvKeyValueObjectArrayArg
}
});
exports.run = () => {
let done = plugins.q.defer();
});
done.resolve(config);
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHFCQUFxQixDQUFDLENBQUE7QUFDL0MsTUFBWSxLQUFLLFdBQU0sbUJBQW1CLENBQUMsQ0FBQTtBQVcxQyxDQUFDO0FBRUYsSUFBSSxxQkFBcUIsR0FBRztJQUN4QixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO0lBQzdCLElBQUksdUJBQXlDLENBQUM7SUFDOUMsRUFBRSxDQUFBLENBQUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMs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FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IscUJBQXFCLEVBQUU7U0FDbEIsSUFBSSxDQUFDLFdBQVcsQ0FBQztTQUNqQixJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQ3hCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQSJ9

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 npmextra = require("npmextra");
export import path = require("path");
export import projectinfo = require("projectinfo");
export import q = require("q");
export import qenv = require("qenv");
export import shelljs = require("shelljs");
export import smartfile = require("smartfile");
export import smartstring = require("smartstring");

View File

@ -3,8 +3,10 @@ require("typings-global");
exports.beautylog = require("beautylog");
exports.npmextra = require("npmextra");
exports.path = require("path");
exports.projectinfo = require("projectinfo");
exports.q = require("q");
exports.qenv = require("qenv");
exports.shelljs = require("shelljs");
exports.smartfile = require("smartfile");
exports.smartstring = require("smartstring");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1kb2NrZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNqQyxnQkFBUSxXQUFXLFVBQVUsQ0FBQyxDQUFDO0FBQy9CLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDakIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1kb2NrZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNqQyxnQkFBUSxXQUFXLFVBQVUsQ0FBQyxDQUFDO0FBQy9CLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixtQkFBVyxXQUFXLGFBQWEsQ0FBQyxDQUFDO0FBQ3JDLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNqQixZQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDdkIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9

View File

@ -31,20 +31,22 @@
},
"homepage": "https://gitlab.com/pushrocks/npmdocker#README",
"devDependencies": {
"npmts-g": "^5.2.6",
"npmts-g": "^5.2.8",
"should": "^10.0.0",
"typings-test": "^1.0.1"
},
"dependencies": {
"@types/q": "^0.0.27",
"@types/shelljs": "^0.3.27",
"beautylog": "^5.0.14",
"@types/q": "0.x.x",
"@types/shelljs": "0.x.x",
"beautylog": "^5.0.20",
"npmextra": "^1.0.8",
"projectinfo": "^1.0.3",
"q": "^1.4.1",
"qenv": "^1.1.1",
"rxjs": "^5.0.0-beta.10",
"shelljs": "^0.7.0",
"smartfile": "^4.0.11",
"smartstring": "^2.0.15",
"shelljs": "^0.7.3",
"smartfile": "^4.0.13",
"smartstring": "^2.0.17",
"typings-global": "^1.0.6"
}
}

View File

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

View File

@ -2,12 +2,18 @@ import * as plugins from "./npmdocker.plugins";
import * as paths from "./npmdocker.paths";
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 = {
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 done = plugins.q.defer();
npmdockerOra.text("checking docker...");
if(plugins.shelljs.which("docker")){
if (plugins.shelljs.which("docker")) {
plugins.beautylog.ok("Docker found!")
done.resolve();
} else {
@ -31,13 +37,13 @@ let checkDocker = () => {
let buildDockerFile = () => {
let done = plugins.q.defer();
npmdockerOra.text("building Dockerfile...");
let dockerfile:string = snippets.dockerfileSnippet({
baseImage:config.baseImage,
command:config.command
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.smartfile.memory.toFsSync(dockerfile, paths.dockerfile);
plugins.beautylog.ok("Dockerfile created!");
done.resolve();
return done.promise
@ -49,18 +55,18 @@ let buildDockerFile = () => {
let buildDockerImage = () => {
let done = plugins.q.defer();
npmdockerOra.text("pulling latest base image from registry...");
plugins.shelljs.exec(`docker pull ${config.baseImage}`,{
silent:true
},() => {
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"){
if (process.env.CI == "true") {
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}`,{
silent:true
},() => {
plugins.shelljs.exec(`docker build -f ${paths.dockerfile} -t ${dockerData.imageTag} ${paths.assets}`, {
silent: true
}, () => {
plugins.beautylog.ok("Dockerimage built!")
done.resolve();
});
@ -68,6 +74,34 @@ let buildDockerImage = () => {
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
*/
@ -75,26 +109,16 @@ 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;
config.exitCode = plugins.shelljs.exec(`docker run ${dockerData.dockerProjectMountString} ${dockerData.dockerSockString} ${dockerData.dockerEnvString} --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
plugins.shelljs.exec(`docker rm -f ${dockerData.containerName}`, {
silent: true
});
done.resolve();
return done.promise
@ -102,8 +126,8 @@ let deleteDockerContainer = () => {
let deleteDockerImage = () => {
let done = plugins.q.defer();
plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`,{
silent:true
plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`, {
silent: true
});
done.resolve();
return done.promise
@ -146,10 +170,13 @@ export let run = (configArg) => {
.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;
}

View File

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