Skip to content

Commit

Permalink
Updated CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dolgopolovwork committed Jul 12, 2019
1 parent fdceeb5 commit 947a9cf
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 135 deletions.
158 changes: 54 additions & 104 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
}
}
}
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
27 changes: 0 additions & 27 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
13 changes: 9 additions & 4 deletions notary-btc-integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -35,11 +44,7 @@ task integrationTest(type: Test) {
// Enable JUnit5 tests
useJUnitPlatform {
}

mustRunAfter test
}
check.dependsOn integrationTest


dependencies {
compile project(":btc-registration")
Expand Down

0 comments on commit 947a9cf

Please sign in to comment.