2017-05-12 10:41:35 +00:00
|
|
|
#!/usr/bin/env groovy
|
|
|
|
|
|
|
|
import groovy.json.*;
|
2017-05-11 10:07:33 +00:00
|
|
|
|
|
|
|
def image;
|
|
|
|
def branchName = "${env.BRANCH_NAME}";
|
|
|
|
def branchNameTest = "preprod";
|
|
|
|
def branchNameProd = "master";
|
|
|
|
def prefixDocker = "test";
|
2017-06-07 06:43:25 +00:00
|
|
|
def dockerNginxName = ["nginx", "-p 80:80 --privileged --link test-auth:auth --link test-salix:salix --link test-client:client --link test-mailer:mailer"]
|
2017-05-12 10:41:35 +00:00
|
|
|
def dockerAuthName = ["auth", "-p 3000:3000"]
|
|
|
|
def dockerSalixName = ["salix", "-p 3001:3001"]
|
|
|
|
def dockerClientName = ["client", "-p 3002:3002"]
|
2017-06-07 06:43:25 +00:00
|
|
|
def dockerMailerName = ["mailer", "-p 3003:3003"]
|
2017-06-30 09:38:55 +00:00
|
|
|
def dockerProductionName = ["production", "-p 3004:3004"]
|
2017-05-12 10:41:35 +00:00
|
|
|
|
2017-05-11 10:07:33 +00:00
|
|
|
def buildNumber = "${env.BUILD_NUMBER}";
|
2017-05-12 10:41:35 +00:00
|
|
|
|
2017-06-30 09:38:55 +00:00
|
|
|
def dockers = [dockerAuthName, dockerSalixName, dockerClientName, dockerMailerName, dockerNginxName, dockerProductionName]
|
2017-05-11 10:07:33 +00:00
|
|
|
|
|
|
|
node {
|
|
|
|
|
|
|
|
if (branchName == branchNameProd)
|
|
|
|
prefixDocker = "prod";
|
|
|
|
|
|
|
|
stage ('Checkout') {
|
|
|
|
checkout scm
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:47:15 +00:00
|
|
|
stage ('install modules'){
|
|
|
|
sh "npm install"
|
|
|
|
}
|
|
|
|
|
2017-05-11 10:07:33 +00:00
|
|
|
stage ('build Project Salix'){
|
|
|
|
sh "gulp build"
|
|
|
|
}
|
|
|
|
|
2017-05-12 10:41:35 +00:00
|
|
|
for (int i = 0; i < dockers.size(); i++)
|
2017-05-11 10:07:33 +00:00
|
|
|
{
|
2017-05-12 10:41:35 +00:00
|
|
|
def element = dockers[i][0]
|
|
|
|
def ports = dockers[i][1]
|
|
|
|
|
2017-05-11 10:07:33 +00:00
|
|
|
stage ("docker ${element}")
|
|
|
|
{
|
|
|
|
stage ("Stopping ${prefixDocker}-${element} actual")
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
def returnDocker = sh (script: "docker stop ${prefixDocker}-${element}", returnStdout: true).trim();
|
|
|
|
echo "${returnDocker}";
|
|
|
|
returnDocker = sh (script: "docker rm ${prefixDocker}-${element}", returnStdout: true).trim();
|
|
|
|
echo "${returnDocker}";
|
2017-05-12 10:41:35 +00:00
|
|
|
//returnDocker = sh (script: "docker rmi ${prefixDocker}-${element}:${buildNumber-3}", returnStdout: true).trim();
|
|
|
|
echo "borran ${prefixDocker}-${element}:${buildNumber-3}";
|
|
|
|
//echo "${returnDocker}";
|
2017-05-11 10:07:33 +00:00
|
|
|
}catch(Exception _){
|
|
|
|
echo "Error Stage Stopping"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage ("Create Docker Image ${element}") {
|
|
|
|
dir("./services/${element}"){
|
|
|
|
stage ("Install modules service ${element}"){
|
|
|
|
if (fileExists('./package.json'))
|
|
|
|
sh "npm i"
|
|
|
|
}
|
|
|
|
stage("Build image ${element}"){
|
|
|
|
image = docker.build("${prefixDocker}-${element}:${buildNumber}", ".")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage ("Run Docker ${element}"){
|
2017-05-12 10:41:35 +00:00
|
|
|
image.run ("${ports} --name ${prefixDocker}-${element}")
|
2017-05-11 10:07:33 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
stage('docker registry'){
|
|
|
|
docker.withServer('tcp://harbor.verdnatura.es','docker-registry')
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|