diff --git a/.ci/job.dsl b/.ci/job.dsl deleted file mode 100644 index 41abb6ae..00000000 --- a/.ci/job.dsl +++ /dev/null @@ -1,283 +0,0 @@ -// vim: set filetype=groovy: - -def jobName = 'zeebe-simple-monitor-DISTRO-maven-deploy' -def repository = 'zeebe-simple-monitor' -def gitBranch = 'master' - -def pom = 'pom.xml' -def mvnGoals = 'clean verify -B' - -def mavenVersion = 'maven-3.3-latest' -def mavenSettingsId = 'camunda-maven-settings' - -// script to set access rights on ssh keys -// and configure git user name and email -def setupGitConfig = '''\ -#!/bin/bash -xe - -chmod 600 ~/.ssh/id_rsa -chmod 600 ~/.ssh/id_rsa.pub - -git config --global user.email "ci@camunda.com" -git config --global user.name "camunda-jenkins" -''' - -def mavenGpgKeys = '''\ -#!/bin/bash - -if [ -e "${MVN_CENTRAL_GPG_KEY_SEC}" ] -then - gpg -q --allow-secret-key-import --import ${MVN_CENTRAL_GPG_KEY_SEC} || echo 'Private GPG Sign Key is already imported!.' - rm ${MVN_CENTRAL_GPG_KEY_SEC} -else - echo 'Private GPG Key not found.' -fi - -if [ -e "${MVN_CENTRAL_GPG_KEY_PUB}" ] -then - gpg -q --import ${MVN_CENTRAL_GPG_KEY_PUB} || echo 'Public GPG Sign Key is already imported!.' - rm ${MVN_CENTRAL_GPG_KEY_PUB} -else - echo 'Public GPG Key not found.' -fi -''' - -def githubRelease = '''\ -#!/bin/bash - -# do github release -curl -sL https://github.com/aktau/github-release/releases/download/v0.7.2/linux-amd64-github-release.tar.bz2 | tar xjvf - --strip 3 - -./github-release release --user zeebe-io --repo zeebe-simple-monitor --tag ${RELEASE_VERSION} --name "Zeebe Simple Monitor ${RELEASE_VERSION}" --description "" - - -cd app/target - -JAR="zeebe-simple-monitor-app-${RELEASE_VERSION}.jar" -CHECKSUM="${JAR}.sha1sum" - -# create checksum files -sha1sum ${JAR} > ${CHECKSUM} - -../../github-release upload --user zeebe-io --repo zeebe-simple-monitor --tag ${RELEASE_VERSION} --name "${JAR}" --file "${JAR}" -../../github-release upload --user zeebe-io --repo zeebe-simple-monitor --tag ${RELEASE_VERSION} --name "${CHECKSUM}" --file "${CHECKSUM}" - -cd ../../exporter/target - -JAR="zeebe-simple-monitor-exporter-${RELEASE_VERSION}.jar" -CHECKSUM="${JAR}.sha1sum" - -# create checksum files -sha1sum ${JAR} > ${CHECKSUM} - -../../github-release upload --user zeebe-io --repo zeebe-simple-monitor --tag ${RELEASE_VERSION} --name "${JAR}" --file "${JAR}" -../../github-release upload --user zeebe-io --repo zeebe-simple-monitor --tag ${RELEASE_VERSION} --name "${CHECKSUM}" --file "${CHECKSUM}" - -''' - -def dockerRelease = '''\ -#!/bin/bash -xeu - -cd app/ - -# clear docker host env set by jenkins job -unset DOCKER_HOST - -IMAGE="camunda/zeebe-simple-monitor" - -echo "Building Zeebe Simple Monitor Docker image ${RELEASE_VERSION}." -docker build --no-cache --build-arg JAR=target/zeebe-simple-monitor-app-${RELEASE_VERSION}.jar -t ${IMAGE}:${RELEASE_VERSION} . - -echo "Authenticating with DockerHub and pushing image." -docker login --username ${DOCKER_HUB_USERNAME} --password ${DOCKER_HUB_PASSWORD} --email ci@camunda.com - -echo "Pushing ${IMAGE}:${RELEASE_VERSION}" -docker push ${IMAGE}:${RELEASE_VERSION} - -docker tag -f ${IMAGE}:${RELEASE_VERSION} ${IMAGE}:latest - -echo "Pushing ${IMAGE}:latest" -docker push ${IMAGE}:latest -''' - -def dockerSnapshot = '''\ -#!/bin/bash -cd app/ -# clear docker host env set by jenkins job -unset DOCKER_HOST - -if [ -f target/zeebe-simple-monitor-app-*-SNAPSHOT.jar ]; then - IMAGE="camunda/zeebe-simple-monitor:SNAPSHOT" - - echo "Building Zeebe Simple Monitor Docker image ${IMAGE}." - docker build --no-cache -t ${IMAGE} . - - echo "Authenticating with DockerHub and pushing image." - docker login --username ${DOCKER_HUB_USERNAME} --password ${DOCKER_HUB_PASSWORD} --email ci@camunda.com - - echo "Pushing ${IMAGE}" - docker push ${IMAGE} -fi -''' - -// properties used by the release build -def releaseProperties = [ - resume: 'false', - tag: '${RELEASE_VERSION}', - releaseVersion: '${RELEASE_VERSION}', - developmentVersion: '${DEVELOPMENT_VERSION}', - pushChanges: '${PUSH_CHANGES}', - remoteTagging: '${PUSH_CHANGES}', - localCheckout: '${USE_LOCAL_CHECKOUT}', - arguments: '--settings=${NEXUS_SETTINGS} -Dgpg.passphrase="${GPG_PASSPHRASE}" -Dskip.central.release=${SKIP_DEPLOY_TO_MAVEN_CENTRAL} -Dskip.camunda.release=${SKIP_DEPLOY_TO_CAMUNDA_NEXUS}', -] - - -mavenJob(jobName) -{ - scm - { - git - { - remote - { - github 'zeebe-io/' + repository, 'ssh' - credentials 'camunda-jenkins-github-ssh' - } - branch gitBranch - extensions - { - localBranch gitBranch - } - } - } - triggers - { - githubPush() - } - label 'dind' - jdk 'jdk-8-latest' - - rootPOM pom - goals mvnGoals - localRepository LocalRepositoryLocation.LOCAL_TO_WORKSPACE - providedSettings mavenSettingsId - mavenInstallation mavenVersion - - postBuildSteps('SUCCESS') { - shell dockerSnapshot - } - - wrappers - { - timestamps() - - timeout - { - absolute 60 - } - - configFiles - { - // jenkins github public ssh key needed to push to github - custom('Jenkins CI GitHub SSH Public Key') - { - targetLocation '/home/camunda/.ssh/id_rsa.pub' - } - // jenkins github private ssh key needed to push to github - custom('Jenkins CI GitHub SSH Private Key') - { - targetLocation '/home/camunda/.ssh/id_rsa' - } - // nexus settings xml - mavenSettings(mavenSettingsId) - { - variable('NEXUS_SETTINGS') - } - } - - credentialsBinding { - // maven central signing credentials - string('GPG_PASSPHRASE', 'password_maven_central_gpg_signing_key') - file('MVN_CENTRAL_GPG_KEY_SEC', 'maven_central_gpg_signing_key') - file('MVN_CENTRAL_GPG_KEY_PUB', 'maven_central_gpg_signing_key_pub') - // github token for release upload - string('GITHUB_TOKEN', 'github-camunda-jenkins-token') - // docker hub credentials for docker push - usernamePassword('DOCKER_HUB_USERNAME', 'DOCKER_HUB_PASSWORD', 'camundajenkins-dockerhub') - } - - release - { - doNotKeepLog false - overrideBuildParameters true - - parameters - { - stringParam('RELEASE_VERSION', '0.1.0', 'Version to release') - stringParam('DEVELOPMENT_VERSION', '0.2.0-SNAPSHOT', 'Next development version') - booleanParam('PUSH_CHANGES', true, 'If TRUE, push the changes to remote repositories. If FALSE, do not push changes to remote repositories. Must be used in conjunction with USE_LOCAL_CHECKOUT = TRUE to test the release!') - booleanParam('USE_LOCAL_CHECKOUT', false, 'If TRUE, uses the local git repository to checkout the release tag to build. If FALSE, checks out the release tag from the remote repositoriy. Must be used in conjunction with PUSH_CHANGES = FALSE to test the release!') - booleanParam('SKIP_DEPLOY_TO_MAVEN_CENTRAL', false, 'If TRUE, skip the deployment to maven central. Should be used when testing the release.') - booleanParam('SKIP_DEPLOY_TO_CAMUNDA_NEXUS', false, 'If TRUE, skip the deployment to camunda nexus. Should be used when testing the release.') - } - - preBuildSteps - { - // setup git configuration to push to github - shell setupGitConfig - - // execute maven release - maven - { - mavenInstallation mavenVersion - providedSettings mavenSettingsId - goals 'release:prepare release:perform -Dgpg.passphrase="${GPG_PASSPHRASE}" -B' - - properties releaseProperties - localRepository LocalRepositoryLocation.LOCAL_TO_WORKSPACE - } - - shell githubRelease - - shell dockerRelease - - } - - } - - } - - publishers - { - - archiveJunit('**/target/surefire-reports/*.xml') - { - retainLongStdout() - } - - extendedEmail - { - triggers - { - firstFailure - { - sendTo - { - culprits() - } - } - fixed - { - sendTo - { - culprits() - } - } - } - } - } - - logRotator(-1, 5, -1, 1) - -} diff --git a/.ci/scripts/docker-release.sh b/.ci/scripts/docker-release.sh new file mode 100755 index 00000000..be8de876 --- /dev/null +++ b/.ci/scripts/docker-release.sh @@ -0,0 +1,19 @@ +#!/bin/sh -xeu + +cd app/ + +IMAGE="camunda/zeebe-simple-monitor" + +echo "Building Zeebe Simple Monitor Docker image ${RELEASE_VERSION}." +docker build --no-cache --build-arg JAR=target/zeebe-simple-monitor-app-${RELEASE_VERSION}.jar -t ${IMAGE}:${RELEASE_VERSION} . + +echo "Authenticating with DockerHub and pushing image." +docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW} + +echo "Pushing ${IMAGE}:${RELEASE_VERSION}" +docker push ${IMAGE}:${RELEASE_VERSION} + +docker tag ${IMAGE}:${RELEASE_VERSION} ${IMAGE}:latest + +echo "Pushing ${IMAGE}:latest" +docker push ${IMAGE}:latest diff --git a/.ci/scripts/docker-snapshot.sh b/.ci/scripts/docker-snapshot.sh new file mode 100755 index 00000000..5a90091b --- /dev/null +++ b/.ci/scripts/docker-snapshot.sh @@ -0,0 +1,16 @@ +#!/bin/sh -xeu + +cd app/ + +if [ -f target/zeebe-simple-monitor-app-*-SNAPSHOT.jar ]; then + IMAGE="camunda/zeebe-simple-monitor:SNAPSHOT" + + echo "Building Zeebe Simple Monitor Docker image ${IMAGE}." + docker build --no-cache -t ${IMAGE} . + + echo "Authenticating with DockerHub and pushing image." + docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW} + + echo "Pushing ${IMAGE}" + docker push ${IMAGE} +fi diff --git a/.ci/scripts/github-release.sh b/.ci/scripts/github-release.sh new file mode 100755 index 00000000..f016ea8f --- /dev/null +++ b/.ci/scripts/github-release.sh @@ -0,0 +1,33 @@ +#!/bin/bash -xeu + +export GITHUB_TOKEN=${GITHUB_TOKEN_PSW} +export GITHUB_ORG=zeebe-io +export GITHUB_REPO=zeebe-simple-monitor + +# do github release +curl -sL https://github.com/aktau/github-release/releases/download/v0.7.2/linux-amd64-github-release.tar.bz2 | tar xjvf - --strip 3 +./github-release release --user ${GITHUB_ORG} --repo ${GITHUB_REPO} --tag ${RELEASE_VERSION} --draft --name "Zeebe Hazelcast Exporter ${RELEASE_VERSION}" --description "" + +# upload app +cd app/target + +export ARTIFACT=zeebe-simple-monitor-app-${RELEASE_VERSION}.jar +export CHECKSUM=${ARTIFACT}.sha1sum + +# create checksum files +sha1sum ${ARTIFACT} > ${CHECKSUM} + +../../github-release upload --user ${GITHUB_ORG} --repo ${GITHUB_REPO} --tag ${RELEASE_VERSION} --name "${ARTIFACT}" --file "${ARTIFACT}" +../../github-release upload --user ${GITHUB_ORG} --repo ${GITHUB_REPO} --tag ${RELEASE_VERSION} --name "${CHECKSUM}" --file "${CHECKSUM}" + +# upload exporter +cd ../../exporter/target + +export ARTIFACT=zeebe-simple-monitor-exporter-${RELEASE_VERSION}.jar +export CHECKSUM=${ARTIFACT}.sha1sum + +# create checksum files +sha1sum ${ARTIFACT} > ${CHECKSUM} + +../../github-release upload --user ${GITHUB_ORG} --repo ${GITHUB_REPO} --tag ${RELEASE_VERSION} --name "${ARTIFACT}" --file "${ARTIFACT}" +../../github-release upload --user ${GITHUB_ORG} --repo ${GITHUB_REPO} --tag ${RELEASE_VERSION} --name "${CHECKSUM}" --file "${CHECKSUM}" diff --git a/.ci/settings.xml b/.ci/settings.xml new file mode 100644 index 00000000..7ebd208c --- /dev/null +++ b/.ci/settings.xml @@ -0,0 +1,29 @@ + + + + + camunda-nexus + ${env.NEXUS_USR} + ${env.NEXUS_PSW} + + + central + ${env.MAVEN_CENTRAL_USR} + ${env.MAVEN_CENTRAL_PSW} + + + + + camunda-nexus + * + Camunda Nexus + + + http://repository-ci-camunda-cloud.nexus:8081/content/groups/internal/ + + + diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..6d994662 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,158 @@ +pipeline { + + agent { + kubernetes { + cloud 'zeebe-ci' + label "zeebe-ci-build_${env.JOB_BASE_NAME}-${env.BUILD_ID}" + defaultContainer 'jnlp' + yaml '''\ +apiVersion: v1 +kind: Pod +metadata: + labels: + agent: zeebe-ci-build +spec: + nodeSelector: + cloud.google.com/gke-nodepool: slaves + tolerations: + - key: "slaves" + operator: "Exists" + effect: "NoSchedule" + containers: + - name: maven + image: maven:3.6.0-jdk-8 + command: ["cat"] + tty: true + env: + - name: JAVA_TOOL_OPTIONS + value: | + -XX:+UnlockExperimentalVMOptions + -XX:+UseCGroupMemoryLimitForHeap + resources: + limits: + cpu: 1 + memory: 2Gi + requests: + cpu: 1 + memory: 2Gi + - name: docker + image: docker:18.09.4-dind + args: ["--storage-driver=overlay2"] + securityContext: + privileged: true + tty: true + resources: + limits: + cpu: 1 + memory: 1Gi + requests: + cpu: 500m + memory: 512Mi +''' + } + } + + options { + buildDiscarder(logRotator(numToKeepStr: '10')) + skipDefaultCheckout() + timestamps() + timeout(time: 15, unit: 'MINUTES') + } + + environment { + NEXUS = credentials("camunda-nexus") + DOCKER_HUB = credentials("camunda-dockerhub") + } + + parameters { + booleanParam(name: 'RELEASE', defaultValue: false, description: 'Build a release from current commit?') + string(name: 'RELEASE_VERSION', defaultValue: '0.X.0', description: 'Which version to release?') + string(name: 'DEVELOPMENT_VERSION', defaultValue: '0.Y.0-SNAPSHOT', description: 'Next development version?') + } + + stages { + stage('Prepare') { + steps { + checkout scm + container('maven') { + sh 'mvn clean install -B -s .ci/settings.xml -DskipTests' + } + } + } + + stage('Build') { + when { not { expression { params.RELEASE } } } + steps { + container('maven') { + sh 'mvn install -B -s .ci/settings.xml' + } + } + + post { + always { + junit testResults: "**/*/TEST-*.xml", keepLongStdio: true + } + } + } + + stage('Upload') { + when { not { expression { params.RELEASE } } } + steps { + container('maven') { + sh 'mvn -B -s .ci/settings.xml generate-sources source:jar javadoc:jar deploy -DskipTests' + } + + container('docker') { + sh '.ci/scripts/docker-snapshot.sh' + } + } + } + + stage('Release') { + when { expression { params.RELEASE } } + + environment { + MAVEN_CENTRAL = credentials('maven_central_deployment_credentials') + GPG_PASS = credentials('password_maven_central_gpg_signing_key') + GPG_PUB_KEY = credentials('maven_central_gpg_signing_key_pub') + GPG_SEC_KEY = credentials('maven_central_gpg_signing_key_sec') + GITHUB_TOKEN = credentials('camunda-jenkins-github') + RELEASE_VERSION = "${params.RELEASE_VERSION}" + DEVELOPMENT_VERSION = "${params.DEVELOPMENT_VERSION}" + } + + steps { + container('maven') { + sshagent(['camunda-jenkins-github-ssh']) { + sh 'gpg -q --import ${GPG_PUB_KEY} ' + sh 'gpg -q --allow-secret-key-import --import --no-tty --batch --yes ${GPG_SEC_KEY}' + sh 'git config --global user.email "ci@camunda.com"' + sh 'git config --global user.name "camunda-jenkins"' + sh 'mkdir ~/.ssh/ && ssh-keyscan github.com >> ~/.ssh/known_hosts' + sh 'mvn -B -s .ci/settings.xml -DskipTests source:jar javadoc:jar release:prepare release:perform -Prelease' + sh '.ci/scripts/github-release.sh' + } + } + + container('docker') { + sh '.ci/scripts/docker-release.sh' + } + } + } + } + + post { + always { + // Retrigger the build if the node disconnected + script { + if (nodeDisconnected()) { + build job: currentBuild.projectName, propagate: false, quietPeriod: 60, wait: false + } + } + } + } +} + +boolean nodeDisconnected() { + return currentBuild.rawBuild.getLog(500).join('') ==~ /.*(ChannelClosedException|KubernetesClientException|ClosedChannelException).*/ +} diff --git a/pom.xml b/pom.xml index 4d339f9d..a9213b1b 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,37 @@ + + + release + + 1.6 + ${env.GPG_PASS} + false + ${env.RELEASE_VERSION} + ${env.RELEASE_VERSION} + ${env.DEVELOPMENT_VERSION} + -s .ci/settings.xml -DskipTests + + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + --pinentry-mode + loopback + + + + + + + + + zeebe @@ -101,24 +132,6 @@ - - - sonatype-oss-release - - - - org.apache.maven.plugins - maven-gpg-plugin - - - true - - - - - - - https://github.com/zeebe-io/zeebe-simple-monitor scm:git:git@github.com:zeebe-io/zeebe-simple-monitor.git