now has better support for docker in docker
This commit is contained in:
parent
46e4ed1c8b
commit
f9f0119121
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,5 @@ node_modules/
|
|||||||
coverage/
|
coverage/
|
||||||
docs/
|
docs/
|
||||||
test/
|
test/
|
||||||
|
assets/
|
||||||
.nogit/
|
.nogit/
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
image: hosttoday/ht-docker-dbase:npmts
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
FROM hosttoday/ht-docker-node:npmts
|
FROM hosttoday/ht-docker-node:npmts
|
||||||
RUN mkdir /workspace
|
COPY ./buildContextDir /workspace
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
ENV CI=true
|
ENV CI=true
|
||||||
CMD ["npm","test"];
|
CMD ["npm","test"];
|
||||||
|
25
dist/npmdocker.docker.js
vendored
25
dist/npmdocker.docker.js
vendored
File diff suppressed because one or more lines are too long
1
dist/npmdocker.paths.d.ts
vendored
1
dist/npmdocker.paths.d.ts
vendored
@ -1,4 +1,5 @@
|
|||||||
export declare let cwd: string;
|
export declare let cwd: string;
|
||||||
export declare let packageBase: string;
|
export declare let packageBase: string;
|
||||||
export declare let assets: string;
|
export declare let assets: string;
|
||||||
|
export declare let buildContextDir: string;
|
||||||
export declare let dockerfile: string;
|
export declare let dockerfile: string;
|
||||||
|
5
dist/npmdocker.paths.js
vendored
5
dist/npmdocker.paths.js
vendored
@ -5,5 +5,8 @@ exports.cwd = process.cwd();
|
|||||||
exports.packageBase = plugins.path.join(__dirname, "../");
|
exports.packageBase = plugins.path.join(__dirname, "../");
|
||||||
exports.assets = plugins.path.join(exports.packageBase, "assets/");
|
exports.assets = plugins.path.join(exports.packageBase, "assets/");
|
||||||
plugins.smartfile.fs.ensureDirSync(exports.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");
|
exports.dockerfile = plugins.path.join(exports.assets, "Dockerfile");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFBcUIsQ0FBQyxDQUFBO0FBRS9DLGNBQWM7QUFDSCxXQUFHLEdBQUcsT0FBTyxDQUFDLEdBQUcsRUFBRSxDQUFDO0FBQ3BCLG1CQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFDO0FBQ2pELGNBQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxtQkFBVyxFQUFDLFNBQVMsQ0FBQyxDQUFDO0FBQzdELE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyxjQUFNLENBQUMsQ0FBQztBQUNoQyxrQkFBVSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLGNBQU0sRUFBQyxZQUFZLENBQUMsQ0FBQyJ9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFBcUIsQ0FBQyxDQUFBO0FBRS9DLGNBQWM7QUFDSCxXQUFHLEdBQUcsT0FBTyxDQUFDLEdBQUcsRUFBRSxDQUFDO0FBQ3BCLG1CQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFFLEtBQUssQ0FBQyxDQUFDO0FBQ2xELGNBQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxtQkFBVyxFQUFFLFNBQVMsQ0FBQyxDQUFDO0FBQzlELE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyxjQUFNLENBQUMsQ0FBQztBQUVoQyx1QkFBZSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLGNBQU0sRUFBQyxpQkFBaUIsQ0FBQyxDQUFDO0FBQ3pFLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyx1QkFBZSxDQUFDLENBQUM7QUFFcEQsUUFBUTtBQUNHLGtCQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsY0FBTSxFQUFFLFlBQVksQ0FBQyxDQUFDIn0=
|
2
dist/npmdocker.snippets.js
vendored
2
dist/npmdocker.snippets.js
vendored
@ -12,7 +12,7 @@ exports.dockerfileSnippet = (optionsArg) => {
|
|||||||
;
|
;
|
||||||
return plugins.smartstring.indent.normalize(`
|
return plugins.smartstring.indent.normalize(`
|
||||||
FROM ${optionsArg.baseImage}
|
FROM ${optionsArg.baseImage}
|
||||||
RUN mkdir /workspace
|
COPY ./buildContextDir /workspace
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
ENV CI=true
|
ENV CI=true
|
||||||
CMD [${commandString}];
|
CMD [${commandString}];
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"npmts":{
|
"npmts":{
|
||||||
"mode":"default",
|
"mode":"default",
|
||||||
"cli":true
|
"cli":true,
|
||||||
|
"dockerSock":true
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -53,6 +53,11 @@ let buildDockerImage = () => {
|
|||||||
silent:true
|
silent:true
|
||||||
},() => {
|
},() => {
|
||||||
npmdockerOra.text("building Dockerimage...");
|
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}`,{
|
plugins.shelljs.exec(`docker build -f ${paths.dockerfile} -t ${dockerData.imageTag} ${paths.assets}`,{
|
||||||
silent:true
|
silent:true
|
||||||
},() => {
|
},() => {
|
||||||
@ -70,11 +75,17 @@ 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 = "";
|
let dockerSockString:string = "";
|
||||||
if(config.dockerSock){
|
if(config.dockerSock){
|
||||||
dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`
|
dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`
|
||||||
};
|
};
|
||||||
config.exitCode = plugins.shelljs.exec(`docker run -v ${paths.cwd}:/workspace ${dockerSockString} --name ${dockerData.containerName} ${dockerData.imageTag}`).code;
|
config.exitCode = plugins.shelljs.exec(`docker run ${dockerProjectMountString} ${dockerSockString} --name ${dockerData.containerName} ${dockerData.imageTag}`).code;
|
||||||
done.resolve();
|
done.resolve();
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
@ -94,12 +105,19 @@ let deleteDockerImage = () => {
|
|||||||
plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`,{
|
plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`,{
|
||||||
silent:true
|
silent:true
|
||||||
});
|
});
|
||||||
done.resolve();
|
|
||||||
plugins.beautylog.ok("removed test image!");
|
plugins.beautylog.ok("removed test image!");
|
||||||
plugins.beautylog.ok("Cleaned up!");
|
plugins.beautylog.ok("Cleaned up!");
|
||||||
|
done.resolve();
|
||||||
return done.promise
|
return done.promise
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let deleteBuildContext = () => {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
plugins.smartfile.fs.removeSync(paths.buildContextDir);
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export let run = (configArg) => {
|
export let run = (configArg) => {
|
||||||
@ -111,6 +129,7 @@ export let run = (configArg) => {
|
|||||||
.then(runDockerImage)
|
.then(runDockerImage)
|
||||||
.then(deleteDockerContainter)
|
.then(deleteDockerContainter)
|
||||||
.then(deleteDockerImage)
|
.then(deleteDockerImage)
|
||||||
|
.then(deleteBuildContext)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
done.resolve(config);
|
done.resolve(config);
|
||||||
})
|
})
|
||||||
|
@ -2,7 +2,12 @@ import * as plugins from "./npmdocker.plugins";
|
|||||||
|
|
||||||
// directories
|
// directories
|
||||||
export let cwd = process.cwd();
|
export let cwd = process.cwd();
|
||||||
export let packageBase = plugins.path.join(__dirname,"../");
|
export let packageBase = plugins.path.join(__dirname, "../");
|
||||||
export let assets = plugins.path.join(packageBase,"assets/");
|
export let assets = plugins.path.join(packageBase, "assets/");
|
||||||
plugins.smartfile.fs.ensureDirSync(assets);
|
plugins.smartfile.fs.ensureDirSync(assets);
|
||||||
export let dockerfile = plugins.path.join(assets,"Dockerfile");
|
|
||||||
|
export let buildContextDir = plugins.path.join(assets,"buildContextDir");
|
||||||
|
plugins.smartfile.fs.ensureDirSync(buildContextDir);
|
||||||
|
|
||||||
|
// files
|
||||||
|
export let dockerfile = plugins.path.join(assets, "Dockerfile");
|
||||||
|
@ -16,7 +16,7 @@ export let dockerfileSnippet = (optionsArg:IDockerfileSnippet):string => {
|
|||||||
};
|
};
|
||||||
return plugins.smartstring.indent.normalize(`
|
return plugins.smartstring.indent.normalize(`
|
||||||
FROM ${optionsArg.baseImage}
|
FROM ${optionsArg.baseImage}
|
||||||
RUN mkdir /workspace
|
COPY ./buildContextDir /workspace
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
ENV CI=true
|
ENV CI=true
|
||||||
CMD [${commandString}];
|
CMD [${commandString}];
|
||||||
|
Loading…
Reference in New Issue
Block a user