|
@@ -1,3 +1,13 @@
|
|
|
+def SERIAL
|
|
|
+def PROD = [ dir: 'stack-deploy', url: 'ssh://git@git.sdsys.ru:8022/iru/stack-deploy.git', host: 'tcp://iru-swarm.infoclinica.lan:2376 DOCKER_TLS_VERIFY=1', registry: 'registry.infoclinica.ru:5000' ]
|
|
|
+def VOLGA = [ dir: 'stack-deploy-volga', url: 'ssh://git@git.sdsys.ru:8022/iru/stack-deploy-volga.git', host: 'tcp://iru-volga.infoclinica.lan:2376 DOCKER_TLS_VERIFY=1', registry: 'risz-registry.volganet.ru:5000' ]
|
|
|
+def TULA = [ dir: 'stack-deploy-tula', url: 'ssh://git@git.sdsys.ru:8022/iru/stack-deploy-tula.git', host: 'tcp://iru-tula.infoclinica.lan:2376 DOCKER_TLS_VERIFY=1', registry: 'registry.doctor71.ru:5000' ]
|
|
|
+def GIT_DIR = ''
|
|
|
+def GIT_URL = ''
|
|
|
+def DHOST = ''
|
|
|
+def REGISTRY = ''
|
|
|
+def GIT_DIR_PROD = ''
|
|
|
+def GIT_URL_PROD = ''
|
|
|
pipeline {
|
|
|
agent {
|
|
|
label "swarm"
|
|
@@ -5,15 +15,15 @@ pipeline {
|
|
|
environment {
|
|
|
DOCKER_IMAGE='iru/node'
|
|
|
DOCKER_CERT_PATH='/run/secrets/swarm'
|
|
|
- DHOST='tcp://iru-swarm.infoclinica.lan:2376 DOCKER_TLS_VERIFY=1'
|
|
|
DEV_REGISTRY='dev-registry.infoclinica.ru:5000'
|
|
|
- PROD_REGISTRY='registry.infoclinica.ru:5000'
|
|
|
- SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/stack-deploy.git'
|
|
|
- SWARM_GIT_NAME='stack-deploy'
|
|
|
JENKINS_MAIL='jenkins@sdsys.ru'
|
|
|
NEWTAG=''
|
|
|
}
|
|
|
parameters {
|
|
|
+ choice (
|
|
|
+ choices: 'PROD\nVOLGA\nTULA',
|
|
|
+ description: 'There is run deploy?',
|
|
|
+ name: 'CLUSTER')
|
|
|
string(
|
|
|
name: "service_update",
|
|
|
defaultValue: "info_node info_node-api",
|
|
@@ -26,33 +36,64 @@ pipeline {
|
|
|
)
|
|
|
}
|
|
|
stages {
|
|
|
- stage("Tagging in Git"){
|
|
|
+ stage("Define Variables") {
|
|
|
steps{
|
|
|
- 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}
|
|
|
- cp -f tags/${DOCKER_IMAGE}.dev-version tags/${DOCKER_IMAGE}.version
|
|
|
- git add -A
|
|
|
-
|
|
|
- git config --global user.email "${JENKINS_MAIL}"
|
|
|
- git config --global user.name "Jenkins"
|
|
|
- git commit -m 'Version update'| grep '' # Shield ourself from non-zero exit code from 'git commit' command
|
|
|
- GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
|
|
|
- git push origin master
|
|
|
- ls"""
|
|
|
+ script{
|
|
|
+ switch (CLUSTER) {
|
|
|
+ case 'PROD':
|
|
|
+ GIT_DIR = PROD['dir']
|
|
|
+ GIT_URL = PROD['url']
|
|
|
+ DHOST = PROD['host']
|
|
|
+ REGISTRY = PROD['registry']
|
|
|
+ break
|
|
|
+ case 'VOLGA':
|
|
|
+ GIT_DIR = VOLGA['dir']
|
|
|
+ GIT_URL = VOLGA['url']
|
|
|
+ DHOST = VOLGA['host']
|
|
|
+ REGISTRY = VOLGA['registry']
|
|
|
+ break
|
|
|
+ case 'TULA':
|
|
|
+ GIT_DIR = TULA['dir']
|
|
|
+ GIT_URL = TULA['url']
|
|
|
+ DHOST = TULA['host']
|
|
|
+ REGISTRY = TULA['registry']
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stage("Tagging in Git") {
|
|
|
+ steps {
|
|
|
+ script {
|
|
|
+ GIT_DIR_PROD = PROD['dir']
|
|
|
+ GIT_URL_PROD = PROD['url']
|
|
|
+ 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 ${GIT_URL}
|
|
|
+ [ $CLUSTER != 'PROD' ] && GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
|
|
|
+ git clone ${GIT_URL_PROD}
|
|
|
+ cp -f ${GIT_DIR_PROD}/tags/${DOCKER_IMAGE}.dev-version ${GIT_DIR}/tags/${DOCKER_IMAGE}.version
|
|
|
+ cd ${GIT_DIR}
|
|
|
+ git add -A
|
|
|
+ git config --global user.email "${JENKINS_MAIL}"
|
|
|
+ git config --global user.name "Jenkins"
|
|
|
+ git commit -m 'Version update'| grep '' # Shield ourself from non-zero exit code from 'git commit' command
|
|
|
+ GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
|
|
|
+ git push origin master
|
|
|
+ """
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
stage("Tagging and pushing to prod registry"){
|
|
|
steps{
|
|
|
script {
|
|
|
- NEWTAG=sh (script: "cat ${SWARM_GIT_NAME}/tags/${DOCKER_IMAGE}.version", returnStdout: true).trim()
|
|
|
+ NEWTAG=sh (script: "cat ${GIT_DIR}/tags/${DOCKER_IMAGE}.version", returnStdout: true).trim()
|
|
|
sh """docker pull ${DEV_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}
|
|
|
- docker tag ${DEV_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG} ${PROD_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}
|
|
|
- docker tag ${DEV_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG} ${PROD_REGISTRY}/${DOCKER_IMAGE}:latest
|
|
|
- docker push ${PROD_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}
|
|
|
- docker push ${PROD_REGISTRY}/${DOCKER_IMAGE}:latest
|
|
|
+ docker tag ${DEV_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG} ${REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}
|
|
|
+ docker tag ${DEV_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG} ${REGISTRY}/${DOCKER_IMAGE}:latest
|
|
|
+ docker push ${REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}
|
|
|
+ docker push ${REGISTRY}/${DOCKER_IMAGE}:latest
|
|
|
"""
|
|
|
}
|
|
|
}
|
|
@@ -63,7 +104,7 @@ pipeline {
|
|
|
for (String item : service_update.split()) {
|
|
|
echo "Updating ${item}"
|
|
|
try{
|
|
|
- sh "DOCKER_HOST=${DHOST} docker service update ${item} --image ${PROD_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
+ sh "DOCKER_HOST=${DHOST} docker service update ${item} --image ${REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
}
|
|
|
catch(err){
|
|
|
echo "Recovering service $item"
|