From 947a9cf86e6f2a32ac8d1da8eb12d5c63c2e3d8d Mon Sep 17 00:00:00 2001 From: Anton Dolgopolov Date: Fri, 12 Jul 2019 16:46:37 +0300 Subject: [PATCH] Updated CI --- Jenkinsfile | 158 ++++++++--------------- build.gradle | 11 ++ deploy/docker-compose.yml | 27 ---- notary-btc-integration-test/build.gradle | 13 +- 4 files changed, 74 insertions(+), 135 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 767d4a8f..e4025e96 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,112 +1,62 @@ - pipeline { - environment { - DOCKER_NETWORK = '' - } - options { - skipDefaultCheckout() - buildDiscarder(logRotator(numToKeepStr: '20')) - timestamps() - } - agent any - stages { - stage('Stop same job builds') { - agent { label 'master' } - steps { - script { - def scmVars = checkout scm - // need this for develop->master PR cases - // CHANGE_BRANCH is not defined if this is a branch build - try { - scmVars.CHANGE_BRANCH_LOCAL = scmVars.CHANGE_BRANCH - } - catch (MissingPropertyException e) { - } - if (scmVars.GIT_LOCAL_BRANCH != "develop" && scmVars.CHANGE_BRANCH_LOCAL != "develop") { - def builds = load ".jenkinsci/cancel-builds-same-job.groovy" - builds.cancelSameJobBuilds() - } + options { + buildDiscarder(logRotator(numToKeepStr: '20')) + timestamps() + } + agent { + docker { + label 'd3-build-agent' + image 'openjdk:8-jdk-alpine' + args '-v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp' } - } } - stage('Tests') { - agent { label 'd3-build-agent' } - steps { - script { - def scmVars = checkout scm - env.WORKSPACE = pwd() - - DOCKER_NETWORK = "${scmVars.CHANGE_ID}-${scmVars.GIT_COMMIT}-${BUILD_NUMBER}" - writeFile file: ".env", text: "SUBNET=${DOCKER_NETWORK}" - withCredentials([usernamePassword(credentialsId: 'nexus-d3-docker', usernameVariable: 'login', passwordVariable: 'password')]) { - sh "docker login nexus.iroha.tech:19002 -u ${login} -p '${password}'" - - sh "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.ci.yml pull" - sh(returnStdout: true, script: "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.ci.yml up --build -d") - sh "docker cp d3-btc-node0-${DOCKER_NETWORK}:/usr/bin/bitcoin-cli deploy/bitcoin/" - } - - iC = docker.image("gradle:4.10.2-jdk8-slim") - iC.inside("--network='d3-${DOCKER_NETWORK}' -e JVM_OPTS='-Xmx3200m' -e TERM='dumb' -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp") { - sh "ln -s deploy/bitcoin/bitcoin-cli /usr/bin/bitcoin-cli" - sh "gradle dependencies" - sh "gradle test --info" - sh "gradle shadowJar" - sh "gradle dockerfileCreate" - sh "gradle compileIntegrationTestKotlin --info" - sh "gradle integrationTest --info" - sh "gradle d3TestReport" - } - publishHTML (target: [ - allowMissing: false, - alwaysLinkToLastBuild: false, - keepAll: true, - reportDir: 'build/reports', - reportFiles: 'd3-test-report.html', - reportName: "D3 test report" - ]) + stages { + stage('Build') { + steps { + script { + sh "./gradlew build --info" + } + } } - } - post { - cleanup { - sh "mkdir -p build-logs" - sh """#!/bin/bash - while read -r LINE; do \ - docker logs \$(echo \$LINE | cut -d ' ' -f1) | gzip -6 > build-logs/\$(echo \$LINE | cut -d ' ' -f2).log.gz; \ - done < <(docker ps --filter "network=d3-${DOCKER_NETWORK}" --format "{{.ID}} {{.Names}}") - """ - - sh "tar -zcvf build-logs/notaryBtcIntegrationTest.gz -C notary-btc-integration-test/build/reports/tests integrationTest || true" - sh "tar -zcvf build-logs/dokka.gz -C build/reports dokka || true" - archiveArtifacts artifacts: 'build-logs/*.gz' - sh "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.ci.yml down" - cleanWs() + stage('Test') { + steps { + script { + sh "./gradlew runDockerCompose --info" + sh "./gradlew test --info" + sh "./gradlew stopDockerCompose --info" + } + } + } + stage('Build artifacts') { + steps { + script { + if (env.BRANCH_NAME ==~ /(master|develop)/ || env.TAG_NAME) { + DOCKER_TAGS = ['master': 'latest', 'develop': 'develop'] + withCredentials([usernamePassword(credentialsId: 'nexus-d3-docker', usernameVariable: 'login', passwordVariable: 'password')]) { + env.DOCKER_REGISTRY_URL = "https://nexus.iroha.tech:19002" + env.DOCKER_REGISTRY_USERNAME = "${login}" + env.DOCKER_REGISTRY_PASSWORD = "${password}" + env.TAG = env.TAG_NAME ? env.TAG_NAME : DOCKER_TAGS[env.BRANCH_NAME] + sh "./gradlew dockerPush" + } + } + } + } } - } } - - stage('Build and push docker images') { - agent { label 'd3-build-agent' } - steps { - script { - def scmVars = checkout scm - if (env.BRANCH_NAME ==~ /(master|develop|reserved)/ || env.TAG_NAME) { - withCredentials([usernamePassword(credentialsId: 'nexus-d3-docker', usernameVariable: 'login', passwordVariable: 'password')]) { - TAG = env.TAG_NAME ? env.TAG_NAME : env.BRANCH_NAME - iC = docker.image("gradle:4.10.2-jdk8-slim") - iC.inside(" -e JVM_OPTS='-Xmx3200m' -e TERM='dumb'"+ - " -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp"+ - " -e DOCKER_REGISTRY_URL='https://nexus.iroha.tech:19002'"+ - " -e DOCKER_REGISTRY_USERNAME='${login}'"+ - " -e DOCKER_REGISTRY_PASSWORD='${password}'"+ - " -e TAG='${TAG}'") { - sh "gradle shadowJar" - sh "gradle dockerPush" - } - } - } + post { + always { + publishHTML (target: [ + allowMissing: false, + alwaysLinkToLastBuild: false, + keepAll: true, + reportDir: 'build/reports', + reportFiles: 'd3-test-report.html', + reportName: "D3 test report" + ]) + } + cleanup { + cleanWs() } - } } - } -} +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 0cc96d86..e4d5e540 100644 --- a/build.gradle +++ b/build.gradle @@ -90,3 +90,14 @@ pitest { mutators = ['CONDITIONALS_BOUNDARY', 'NEGATE_CONDITIONALS', 'REMOVE_CONDITIONALS', 'MATH', 'INCREMENTS', 'INVERT_NEGS', 'INLINE_CONSTS', 'VOID_METHOD_CALLS'] } + + +task stopDockerCompose(type: Exec) { + executable "sh" + args "-c", "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml down" +} + +task runDockerCompose(type: Exec) { + executable "sh" + args "-c", "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml up" +} \ No newline at end of file diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index 02646f8f..519938b5 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -1,33 +1,6 @@ version: '3.5' services: - d3-iroha: - image: hyperledger/iroha:1.0.0 - container_name: d3-iroha - depends_on: - - d3-iroha-postgres - tty: true - environment: - - KEY=keys/node0 - entrypoint: - - /opt/iroha_data/entrypoint.sh - volumes: - - iroha_block_store:/tmp/block_store - - ../deploy/iroha/:/opt/iroha_data - networks: - - d3-network - - d3-iroha-postgres: - image: postgres:9.5 - container_name: d3-iroha-postgres - expose: - - 5432 - environment: - - POSTGRES_PASSWORD=mysecretpassword - volumes: - - /var/lib/postgresql/data - networks: - - d3-network # bitcoin d3-btc-node0: diff --git a/notary-btc-integration-test/build.gradle b/notary-btc-integration-test/build.gradle index 6001cb36..e2ac02a2 100644 --- a/notary-btc-integration-test/build.gradle +++ b/notary-btc-integration-test/build.gradle @@ -4,8 +4,17 @@ buildscript { jcenter() } } + +plugins { + id 'com.avast.gradle.docker-compose' version '0.7.1' +} + apply plugin: "kotlin-spring" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#kotlin-spring-compiler-plugin +dockerCompose { + useComposeFiles = ['../deploy/docker-compose.dev.yml', '../deploy/docker-compose.yml'] +} + sourceSets { integrationTest { kotlin { @@ -35,11 +44,7 @@ task integrationTest(type: Test) { // Enable JUnit5 tests useJUnitPlatform { } - - mustRunAfter test } -check.dependsOn integrationTest - dependencies { compile project(":btc-registration")