Jenkins - Docker

This commit is contained in:
Vicente Falco 2017-05-11 12:07:33 +02:00
parent f8cd8ee776
commit 27d086843f
5 changed files with 81 additions and 5 deletions

68
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,68 @@
#!groovy
def image;
def branchName = "${env.BRANCH_NAME}";
def branchNameTest = "preprod";
def branchNameProd = "master";
def prefixDocker = "test";
def dockerNginxName = "nginx";
def dockerAuthName = "auth";
def dockerSalixName = "salix"
def dockerClientName = "client"
def buildNumber = "${env.BUILD_NUMBER}";
String[] dockers = [dockerNginxName, dockerAuthName, dockerSalixName, dockerClientName];
node {
if (branchName == branchNameProd)
prefixDocker = "prod";
stage ('Checkout') {
checkout scm
}
stage ('build Project Salix'){
sh "gulp build"
}
for (int i = 0; i < dockers.size(); i++)
{
def element = dockers[i];
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}";
returnDocker = sh (script: "docker -force rmi ${prefixDocker}-${element}:${buildNumber-1}", returnStdout: true).trim();
echo "${returnDocker}";
}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}"){
image.run ("--name ${prefixDocker}-${element}")
}
/*
stage('docker registry'){
docker.withServer('tcp://harbor.verdnatura.es','docker-registry')
}
*/
}
}
}

View File

@ -7,3 +7,5 @@ WORKDIR /app
RUN npm install RUN npm install
CMD ["npm", "start"] CMD ["npm", "start"]
EXPOSE 3000:3000

View File

@ -7,3 +7,5 @@ WORKDIR /app
RUN npm install RUN npm install
CMD ["npm", "start"] CMD ["npm", "start"]
EXPOSE 3002:3002

View File

@ -4,6 +4,8 @@ RUN rm /etc/nginx/nginx.conf
RUN rm /etc/nginx/conf.d/default.conf RUN rm /etc/nginx/conf.d/default.conf
COPY conf-prod.conf /etc/nginx/nginx.conf COPY conf-prod.conf /etc/nginx/nginx.conf
COPY build /etc/nginx COPY static /usr/share/nginx/html
EXPOSE 80:8080

View File

@ -7,3 +7,5 @@ WORKDIR /app
RUN npm install RUN npm install
CMD ["npm", "start"] CMD ["npm", "start"]
EXPOSE 3001:3001