now removes any previous containers to avoid name space conflicts after errors

This commit is contained in:
Philipp Kunz 2016-07-29 22:00:22 +02:00
parent b9618a86a6
commit 6904088af8
2 changed files with 53 additions and 19 deletions

File diff suppressed because one or more lines are too long

View File

@ -85,18 +85,18 @@ let runDockerImage = () => {
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`
}; };
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 ${dockerProjectMountString} ${dockerSockString} --name ${dockerData.containerName} ${dockerData.imageTag}`).code;
done.resolve(); done.resolve();
return done.promise; return done.promise;
}; };
let deleteDockerContainter = () => { let deleteDockerContainer = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
plugins.shelljs.exec(`docker rm ${dockerData.containerName}`,{ plugins.shelljs.exec(`docker rm ${dockerData.containerName}`,{
silent:true silent:true
}); });
done.resolve(); done.resolve();
plugins.beautylog.ok("removed test container!");
return done.promise return done.promise
}; };
@ -105,17 +105,36 @@ let deleteDockerImage = () => {
plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`,{ plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`,{
silent:true silent:true
}); });
plugins.beautylog.ok("removed test image!");
plugins.beautylog.ok("Cleaned up!");
done.resolve(); done.resolve();
return done.promise return done.promise
}; };
let deleteBuildContext = () => { let deleteBuildContext = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
plugins.smartfile.fs.removeSync(paths.buildContextDir); plugins.smartfile.fs.remove(paths.buildContextDir)
done.resolve(); .then(done.resolve);
return done.promise; 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();
});
} }
@ -124,12 +143,11 @@ export let run = (configArg) => {
let done = plugins.q.defer(); let done = plugins.q.defer();
config = configArg; config = configArg;
checkDocker() checkDocker()
.then(preClean)
.then(buildDockerFile) .then(buildDockerFile)
.then(buildDockerImage) .then(buildDockerImage)
.then(runDockerImage) .then(runDockerImage)
.then(deleteDockerContainter) .then(postClean)
.then(deleteDockerImage)
.then(deleteBuildContext)
.then(() => { .then(() => {
done.resolve(config); done.resolve(config);
}) })