diff --git a/Jenkinsfile b/Jenkinsfile index 767d4a8f..dfec9198 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 composeUp --info" + sh "./gradlew test --info" + sh "./gradlew composeDown --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/deploy/docker-compose.dev.yml b/deploy/docker-compose.dev.yml index b91c09e1..e026e082 100644 --- a/deploy/docker-compose.dev.yml +++ b/deploy/docker-compose.dev.yml @@ -1,11 +1,7 @@ version: '3.5' services: - d3-iroha: - ports: - - 50051:50051 - networks: - - d3-network + d3-btc-node0: ports: - 8332:8332 diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index 02646f8f..c74edc76 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: @@ -41,63 +14,6 @@ services: networks: - d3-network - d3-rmq: - image: rabbitmq:3-management - container_name: d3-rmq - ports: - - 8181:15672 - - 5672:5672 - networks: - - d3-network - - d3-chain-adapter: - image: nexus.iroha.tech:19002/d3-deploy/chain-adapter:develop - container_name: d3-chain-adapter - restart: on-failure - depends_on: - - d3-iroha - - d3-rmq - volumes: - - ../deploy/chain-adapter/:/deploy/chain-adapter - environment: - - PROFILE - networks: - - d3-network - - d3-brvs-mongodb: - image: mongo:4.0.6 - container_name: d3-brvs-mongodb - environment: - - MONGO_DATA_DIR=/data/brvs/db - - MONGO_LOG_DIR=/data/brvs/logs - volumes: - - ../deploy/data/db:/data/brvs/db - - ../deploy/data/logs:/data/brvs/logs - ports: - - 27017:27017 - command: mongod --smallfiles - networks: - - d3-network - - d3-brvs: - image: nexus.iroha.tech:19002/brvs-deploy/brvs:latest - container_name: d3-brvs - ports: - - 8083:8080 - depends_on: - - d3-brvs-mongodb - - d3-rmq - environment: - WAIT_HOSTS: d3-brvs-mongodb:27017, d3-rmq:5672, d3-iroha:50051 - WAIT_BEFORE_HOSTS: 10 - WAIT_HOSTS_TIMEOUT: 60 - CREDENTIAL_PUBKEY: b9679bbf526a1c936cd1144b56a370d376fa8246b248cd72f952b45a2f20bdad - CREDENTIAL_PRIVKEY: 56a3c52cd039d9b73a1720052600a20962350b1ea169b4783cefbf87ed99406a - volumes: - - ../configs/brvs/keys:/opt/brvs/config/keys/ - networks: - - d3-network - volumes: iroha_block_store: diff --git a/notary-btc-integration-test/build.gradle b/notary-btc-integration-test/build.gradle index 6001cb36..de05a164 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")