k8-prod-hh.jenkinsfile 3.88 KB
Newer Older
carlosribas's avatar
carlosribas committed
1 2 3 4 5 6 7 8 9
pipeline {
    agent any
    environment {
        SLACK = credentials('slack-notification')
    }
    parameters {
        choice(
            name: 'EBI_SEARCH_ENDPOINT',
            choices: ['PRO', 'DEV'],
carlosribas's avatar
carlosribas committed
10
            description: 'Which EBI search index to use?'
carlosribas's avatar
carlosribas committed
11 12 13 14 15 16 17 18 19 20 21
        )
        choice(
            name: 'DATABASE',
            choices: ['HH', 'PRO', 'DEV', 'TEST', 'FB'],
            description: 'Which database instance to use?'
        )
        gitParameter(
            branchFilter: 'origin/(.*)',
            defaultValue: 'master',
            name: 'BRANCH',
            type: 'PT_BRANCH',
carlosribas's avatar
carlosribas committed
22
            selectedValue: 'DEFAULT',
carlosribas's avatar
carlosribas committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
            description: 'Name of the branch to test and deploy'
        )
    }
    stages {
        stage("deploy") {
            steps {
                script {
                    // set DB with the corresponding Secret file (from K8)
                    switch(params.DATABASE) {
                        case 'PRO':
                            env.DB = 'db-pro'
                            break
                        case 'DEV':
                            env.DB = 'db-dev'
                            break
                        case 'TEST':
                            env.DB = 'db-test'
                            break
                        case 'FB':
                            env.DB = 'db-fb'
                            break
                        case 'HH':
                            env.DB = 'db-hh'
                            break
                    }

                    // set SEARCH_INDEX
                    switch(params.EBI_SEARCH_ENDPOINT) {
                        case 'PRO':
                            env.SEARCH_INDEX = 'search-index-prod'
                            break
                        case 'DEV':
                            env.SEARCH_INDEX = 'search-index-dev'
                            break
                    }

                    withCredentials([file(credentialsId: 'HH-WP-Config', variable: 'config')]) {
                        sh """
                            # update repository
                            git reset --hard
                            git fetch --all
                            git checkout ${params.BRANCH}
                            git pull

                            # send start message on Slack
                            curl -X POST -H 'Content-type: application/json' --data '{"text":"Starting deployment of ${params.BRANCH} in the production namespace - HH cluster"}' $SLACK

                            # clear the cache
                            POD=`/net/isilonP/public/rw/homes/xfm_adm/.jenkins/kubectl --kubeconfig=${config} get pod -l app=memcached -o jsonpath="{.items[0].metadata.name}"`
                            /net/isilonP/public/rw/homes/xfm_adm/.jenkins/kubectl --kubeconfig=${config} exec -it \$POD -- sh -c "echo flush_all | nc localhost 11211"

                            # reinstall everything
                            cd kubernetes/helm
                            /net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm uninstall full-prod --kubeconfig ${config} --namespace prod
                            sleep 10
                            /net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm upgrade --install full-prod --kubeconfig ${config} --namespace prod --set proxy=proxy-hh,database=${DB},searchIndex=${SEARCH_INDEX},rnacentralBranch=${params.BRANCH} .
carlosribas's avatar
carlosribas committed
79 80
                            sleep 20
                            /net/isilonP/public/rw/homes/xfm_adm/.jenkins/kubectl --kubeconfig=${config} rollout status deployment rnacentral --watch --timeout=5m
carlosribas's avatar
carlosribas committed
81 82

                            # send final message on Slack
carlosribas's avatar
carlosribas committed
83
                            curl -X POST -H 'Content-type: application/json' --data '{"text":"Deployed ${params.BRANCH} in the production namespace - HH cluster."}' $SLACK
carlosribas's avatar
carlosribas committed
84 85 86 87 88 89 90
                        """
                    }
                }
            }
        }
    }
}