|
@@ -3,18 +3,14 @@ pipeline {
|
|
|
label "swarm"
|
|
|
}
|
|
|
environment {
|
|
|
- DOCKER_IMAGE='admin'
|
|
|
+ DOCKER_IMAGE='iru/admin'
|
|
|
SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/stack-deploy.git'
|
|
|
SWARM_GIT_NAME='stack-deploy'
|
|
|
JENKINS_MAIL='jenkins@sdsys.ru'
|
|
|
- CLUSTER_DEV='dev-iru-swarm.infoclinica.lan'
|
|
|
- CLUSTER_PROD='iru-swarm.infoclinica.ru'
|
|
|
PACKAGE_NAME='web-registry-admin'
|
|
|
- DEV_REGISTRY='dev-registry.infoclinica.ru:5000'
|
|
|
- PROD_REGISTRY='registry.infoclinica.ru:5000'
|
|
|
DOCKER_CERT_PATH='/run/secrets/swarm'
|
|
|
- DHOST=''
|
|
|
- DOCKER_REGISTRY=''
|
|
|
+ DHOST='tcp://dev-iru-swarm.infoclinica.lan:2376 DOCKER_TLS_VERIFY=1'
|
|
|
+ DOCKER_REGISTRY='dev-registry.infoclinica.ru:5000'
|
|
|
NEWTAG=''
|
|
|
}
|
|
|
parameters {
|
|
@@ -23,11 +19,6 @@ pipeline {
|
|
|
defaultValue: "prod",
|
|
|
description: "Repository to build and/or deploy from. Values - dev, prod."
|
|
|
)
|
|
|
- string(
|
|
|
- name: "cluster",
|
|
|
- defaultValue: "dev",
|
|
|
- description: "Cluster to deploy. Values - dev, prod."
|
|
|
- )
|
|
|
string(
|
|
|
name: "service_update",
|
|
|
defaultValue: "info_admin",
|
|
@@ -42,35 +33,20 @@ pipeline {
|
|
|
stages {
|
|
|
stage("Build") {
|
|
|
steps {
|
|
|
+ echo "Building ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}."
|
|
|
+ sh "docker build --build-arg repo=${repo} --no-cache -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} ."
|
|
|
script {
|
|
|
- switch (cluster) {
|
|
|
- case 'prod':
|
|
|
- DOCKER_REGISTRY=PROD_REGISTRY
|
|
|
- DHOST="tcp://${CLUSTER_PROD}:2376 DOCKER_TLS_VERIFY=1"
|
|
|
- break
|
|
|
- case 'dev':
|
|
|
- DOCKER_REGISTRY=DEV_REGISTRY
|
|
|
- DHOST="tcp://${CLUSTER_DEV}:2376 DOCKER_TLS_VERIFY=1"
|
|
|
- break
|
|
|
- default:
|
|
|
- currentBuild.result = 'ABORTED'
|
|
|
- error('Unknown cluster')
|
|
|
- }
|
|
|
- }
|
|
|
- echo "Building ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}."
|
|
|
- sh "docker build --build-arg repo=${repo} --no-cache -t ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} ."
|
|
|
- script {
|
|
|
- NEWTAG = sh script: "docker run --rm ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} rpm -q --qf %{VERSION}-%{RELEASE} ${PACKAGE_NAME} 2> /dev/null", returnStdout: true
|
|
|
+ NEWTAG = sh script: "docker run --rm ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} rpm -q --qf %{VERSION}-%{RELEASE} ${PACKAGE_NAME} 2> /dev/null", returnStdout: true
|
|
|
NEWTAG = repo + "-" + NEWTAG + "_" + BUILD_NUMBER
|
|
|
echo "NEWTAG is $NEWTAG"
|
|
|
}
|
|
|
- sh "docker tag ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
+ sh "docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
}
|
|
|
}
|
|
|
stage("Publish") {
|
|
|
steps {
|
|
|
- echo "Publishing ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
- sh "docker push ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
+ echo "Publishing ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
+ sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
}
|
|
|
}
|
|
|
stage("Update") {
|
|
@@ -80,7 +56,7 @@ pipeline {
|
|
|
for (String item : service_update.split()) {
|
|
|
echo "Updating ${item}"
|
|
|
try{
|
|
|
- sh "DOCKER_HOST=${DHOST} docker service update ${item} --image ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
+ sh "DOCKER_HOST=${DHOST} docker service update ${item} --image ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
}
|
|
|
catch(err){
|
|
|
echo "Recovering service $item"
|
|
@@ -94,14 +70,14 @@ pipeline {
|
|
|
stage("Tagging"){
|
|
|
steps{
|
|
|
echo "Setting latest tag"
|
|
|
- sh """ docker tag ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG} ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:latest
|
|
|
- docker push ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:latest """
|
|
|
+ sh """ docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest
|
|
|
+ docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest """
|
|
|
echo "Updating tag info in ${SWARM_GIT_NAME} repository"
|
|
|
withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
|
|
|
sh """GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
|
|
|
git clone ${SWARM_GIT_URL}
|
|
|
cd ${SWARM_GIT_NAME}
|
|
|
- echo -n ${NEWTAG} > tags/${DOCKER_IMAGE}.version
|
|
|
+ echo -n ${NEWTAG} > tags/${DOCKER_IMAGE}.dev-version
|
|
|
git add -A
|
|
|
git config --global user.email "${JENKINS_MAIL}"
|
|
|
git config --global user.name "Jenkins"
|
|
@@ -117,7 +93,7 @@ pipeline {
|
|
|
always {
|
|
|
echo "CleaningUp work diretory"
|
|
|
deleteDir()
|
|
|
- sh "docker image rm -f `docker image ls -q ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}`"
|
|
|
+ sh "docker image rm -f `docker image ls -q ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}`"
|
|
|
}
|
|
|
failure {
|
|
|
mail charset: 'UTF-8',
|
|
@@ -134,4 +110,4 @@ pipeline {
|
|
|
body: "<b>Congradulations!!!</b> <b><br> Jenkins job succefully finished.\n\n <b><br>Project Name:</b> ${env.JOB_NAME} <b><br>\nBuild Number:</b> ${env.BUILD_NUMBER} <b><br>\nURL Build:</b> ${RUN_DISPLAY_URL}"
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|