|
| 1 | +library changelog: false, identifier: "lib@master", retriever: modernSCM([ |
| 2 | + $class: 'GitSCMSource', |
| 3 | + remote: 'https://github.com/Percona-Lab/jenkins-pipelines.git' |
| 4 | +]) |
| 5 | + |
| 6 | +pipeline { |
| 7 | + agent { |
| 8 | + label 'min-centos-7-x64' |
| 9 | + } |
| 10 | + environment { |
| 11 | + PATH = '/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin' |
| 12 | + } |
| 13 | + parameters { |
| 14 | + choice(name: 'image', choices: ['build','tarball','predefined'], description: 'Build image from sources, build image from tarball, or use predefined docker image for tests') |
| 15 | + string(name: 'branch', defaultValue: 'release-4.4.9-10', description: 'Repo branch for build image from sources') |
| 16 | + string(name: 'version', defaultValue: '4.4.9', description: 'Version for build tag (psm_ver) to build image from sources') |
| 17 | + string(name: 'release', defaultValue: '10', description: 'Release for build tag (psm_release) to build image from sources') |
| 18 | + string(name: 'mongo_tools', defaultValue: '100.4.1', description: 'Mongo tools tag (mongo_tools_tag) to build image from sources') |
| 19 | + string(name: 'srctarball', defaultValue: 'https://downloads.percona.com/downloads/percona-server-mongodb-LATEST/percona-server-mongodb-4.4.9-10/source/tarball/percona-server-mongodb-4.4.9-10.tar.gz', description: 'Tarball with sources to build image from ready tarballs') |
| 20 | + string(name: 'bintarball', defaultValue: 'https://downloads.percona.com/downloads/percona-server-mongodb-LATEST/percona-server-mongodb-4.4.9-10/binary/tarball/percona-server-mongodb-4.4.9-10-x86_64.glibc2.17.tar.gz', description: 'Tarball with binaries to build image from ready tarballs') |
| 21 | + string(name: 'tag', defaultValue: '4.4.9', description: 'Docker image tag to push/pull to/from registry, should be defined manually') |
| 22 | + string(name: 'parallelexecutors', defaultValue: '1', description: 'Number of parallel executors') |
| 23 | + string(name: 'testsuites', defaultValue: 'core', description: 'Comma-separated list of testuites') |
| 24 | + string(name: 'listsuites', defaultValue: '', description: 'URL with list of testuites') |
| 25 | + choice(name: 'instance', choices: ['docker','docker-32gb'], description: 'Ec2 instance type for running suites') |
| 26 | + string(name: 'paralleljobs', defaultValue: '2', description: 'Number of parallel jobs passed to resmoke.py') |
| 27 | + } |
| 28 | + options { |
| 29 | + withCredentials(moleculePbmJenkinsCreds()) |
| 30 | + disableConcurrentBuilds() |
| 31 | + } |
| 32 | + stages { |
| 33 | + stage ('Build image from sources') { |
| 34 | + agent { label 'docker-32gb' } |
| 35 | + when { |
| 36 | + beforeAgent true |
| 37 | + environment name: 'image', value: 'build' |
| 38 | + } |
| 39 | + steps { |
| 40 | + git poll: false, branch: branch, url: 'https://github.com/percona/percona-server-mongodb.git' |
| 41 | + withCredentials([aws(accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: '8468e4e0-5371-4741-a9bb-7c143140acea', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY')]) { |
| 42 | + sh """ |
| 43 | + rm -rf * |
| 44 | + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" |
| 45 | + if [ -f "/usr/bin/yum" ] ; then sudo yum install -y unzip ; else sudo apt-get update && apt-get -y install unzip ; fi |
| 46 | + unzip -o awscliv2.zip |
| 47 | + sudo ./aws/install |
| 48 | + aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/e7j3v3n0 |
| 49 | + curl -o Dockerfile https://raw.githubusercontent.com/Percona-QA/psmdb-testing/main/regression-tests/build_image/Dockerfile |
| 50 | + docker build . -t public.ecr.aws/e7j3v3n0/psmdb-build:${params.tag} \ |
| 51 | + --build-arg branch=${params.branch} \ |
| 52 | + --build-arg psm_ver=${params.version} \ |
| 53 | + --build-arg psm_release=${params.release} \ |
| 54 | + --build-arg mongo_tools_tag=${params.mongo_tools} |
| 55 | + docker push public.ecr.aws/e7j3v3n0/psmdb-build:${params.tag} |
| 56 | + """ |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + stage ('Build image from tarball') { |
| 61 | + agent { label 'docker' } |
| 62 | + when { |
| 63 | + beforeAgent true |
| 64 | + environment name: 'image', value: 'tarball' |
| 65 | + } |
| 66 | + steps { |
| 67 | + withCredentials([aws(accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: '8468e4e0-5371-4741-a9bb-7c143140acea', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY')]) { |
| 68 | + sh """ |
| 69 | + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" |
| 70 | + if [ -f "/usr/bin/yum" ] ; then sudo yum install -y unzip ; else sudo apt-get update && apt-get -y install unzip ; fi |
| 71 | + unzip -o awscliv2.zip |
| 72 | + sudo ./aws/install |
| 73 | + aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/e7j3v3n0 |
| 74 | + curl -o Dockerfile https://raw.githubusercontent.com/Percona-QA/psmdb-testing/main/regression-tests/tarball_image/Dockerfile |
| 75 | + docker build . -t public.ecr.aws/e7j3v3n0/psmdb-build:${params.tag} \ |
| 76 | + --build-arg sources=${params.srctarball} \ |
| 77 | + --build-arg tarball=${params.bintarball} |
| 78 | + docker push public.ecr.aws/e7j3v3n0/psmdb-build:${params.tag} |
| 79 | + """ |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + stage ('Run suites') { |
| 84 | + steps { |
| 85 | + script { |
| 86 | + def parallelexec = "${params.parallelexecutors}".toInteger() |
| 87 | + def runners = [:] |
| 88 | + def checklist = [].asSynchronized() |
| 89 | + for (int i=0; i<parallelexec; i++) { |
| 90 | + runners["${i}"] = { |
| 91 | + node("${params.instance}") { |
| 92 | + stage ("node ${env.NODE_NAME}") { |
| 93 | + sh """ |
| 94 | + echo -e '{\n "experimental": true,\n "ipv6": true,\n "fixed-cidr-v6": "2001:db8:1::/64"\n}' | sudo tee /etc/docker/daemon.json |
| 95 | + sudo systemctl restart docker |
| 96 | + """ |
| 97 | + script { |
| 98 | + def image = "public.ecr.aws/e7j3v3n0/psmdb-build:" + params.tag |
| 99 | + sh """ |
| 100 | + docker pull ${image} |
| 101 | + """ |
| 102 | + def suites = [] |
| 103 | + if ( params.listsuites != '') { |
| 104 | + sh """ |
| 105 | + curl -o suites.txt "${params.listsuites}" |
| 106 | + """ |
| 107 | + suites = readFile(file: 'suites.txt').split('\n') |
| 108 | + } |
| 109 | + else { |
| 110 | + suites = "${params.testsuites}".split(',') |
| 111 | + } |
| 112 | + Collections.shuffle(Arrays.asList(suites)) |
| 113 | + for (int j=0; j<suites.size(); j++) { |
| 114 | + def fullsuite = suites[j] |
| 115 | + if ( !checklist.contains(fullsuite) && !fullsuite.startsWith(" ") ) { |
| 116 | + checklist.add(fullsuite) |
| 117 | + def suiteArray = fullsuite.split('\\|',-1) |
| 118 | + def suite = suiteArray[0] |
| 119 | + def storage = '' |
| 120 | + def script = '' |
| 121 | + if ( suiteArray.size() >= 2 ) { |
| 122 | + storage = suiteArray[1] |
| 123 | + } |
| 124 | + if ( suiteArray.size() >= 3 ) { |
| 125 | + script = suiteArray[2] |
| 126 | + } |
| 127 | + def suiteName = suite.split(' ')[0] |
| 128 | + suite += " --continueOnFailure --shuffle" |
| 129 | + if ( !suite.contains('--jobs') ) { |
| 130 | + suite += " --jobs=${params.paralleljobs}" |
| 131 | + } |
| 132 | + if ( storage == 'wiredTiger' ) { |
| 133 | + suite += " --storageEngine=wiredTiger --storageEngineCacheSizeGB=1 --excludeWithAnyTags=requires_mmapv1" |
| 134 | + suiteName += "-wiredTiger" |
| 135 | + } |
| 136 | + if ( storage == 'inMemory' ) { |
| 137 | + suite += " --storageEngine=inMemory --storageEngineCacheSizeGB=4 --excludeWithAnyTags=requires_persistence,requires_journaling,requires_mmapv1,uses_transactions" |
| 138 | + suiteName +="-inMemory" |
| 139 | + } |
| 140 | + if ( script ) { |
| 141 | + sh """ |
| 142 | + echo "start suite ${suiteName}" |
| 143 | + docker run -v `pwd`/test_results:/work -w /work --rm -i ${image} bash -c 'rm -rf *' |
| 144 | + docker run -v `pwd`/test_results:/work --rm ${image} bash -c "${script} && python buildscripts/resmoke.py run --suite ${suite} --reportFile=/work/resmoke_${suiteName}_s.json > /work/resmoke_${suiteName}_s.log 2>&1" || true |
| 145 | + docker run -v `pwd`/test_results:/work -w /work --rm ${image} bash -c 'python /opt/percona-server-mongodb/resmoke2junit.py && chmod -R 777 /work' |
| 146 | + echo "finish suite ${suiteName}" |
| 147 | + """ |
| 148 | + } |
| 149 | + else { |
| 150 | + sh """ |
| 151 | + echo "start suite ${suiteName}" |
| 152 | + docker run -v `pwd`/test_results:/work -w /work --rm -i ${image} bash -c 'rm -rf *' |
| 153 | + docker run -v `pwd`/test_results:/work --rm ${image} bash -c "python buildscripts/resmoke.py run --suite $suite --reportFile=/work/resmoke_${suiteName}_s.json > /work/resmoke_${suiteName}_s.log 2>&1" || true |
| 154 | + docker run -v `pwd`/test_results:/work -w /work --rm ${image} bash -c 'python /opt/percona-server-mongodb/resmoke2junit.py && chmod -R 777 /work' |
| 155 | + echo "finish suite ${suiteName}" |
| 156 | + """ |
| 157 | + } |
| 158 | + junit testResults: "test_results/junit.xml", keepLongStdio: true |
| 159 | + sh """ |
| 160 | + rm -rf test_results |
| 161 | + """ |
| 162 | + } |
| 163 | + else if ( !checklist.contains(fullsuite) && fullsuite.startsWith(" ") ) { |
| 164 | + checklist.add(fullsuite) |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | + parallel runners |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + post { |
| 178 | + always { |
| 179 | + sh ''' |
| 180 | + sudo rm -rf ./* |
| 181 | + ''' |
| 182 | + deleteDir() |
| 183 | + } |
| 184 | + } |
| 185 | +} |
0 commit comments