Skip to content

Commit

Permalink
Issue checkstyle#6359: switch Jenkins from Hyper.sh to AWS EC2 spot i…
Browse files Browse the repository at this point in the history
…nstances
  • Loading branch information
daniilyar authored and rnveach committed Jan 9, 2019
1 parent 6a315a1 commit 8c93071
Showing 1 changed file with 3 additions and 65 deletions.
68 changes: 3 additions & 65 deletions Jenkinsfile
@@ -1,31 +1,11 @@
// Node label that specifies on which slave(s) the job should run
BUILD_SLAVES_LABEL = 'build-servers'

DEFAULT_MAVEN_OPTS = "-Xss256k -Xmx300m -XX:MaxMetaspaceSize=80m -XX:MaxMetaspaceExpansion=10m " +
"-Dmaven.test.failure.ignore=false -XshowSettings:vm " +
"-XX:+TieredCompilation -XX:TieredStopAtLevel=1"

// 'sha1' envvar is injected by Jenkins GHPRB plugin in case if build is started by pull request
IS_TRIGGERED_BY_PR = env.sha1?.trim()

GIT_BRANCH = '<unknown>'

enum HyperSize {
S4("s4"),
M1("m1"),
M2("m2");

private size;

HyperSize(String size) {
this.size = size
}

public String toString() {
return size;
}
}

// Text colours definition
def GREEN( String msg ) { return "\u001B[32m${msg}\u001B[0m" }
def YELLOW( String msg ) { return "\u001B[33m${msg}\u001B[0m" }
Expand All @@ -43,42 +23,6 @@ def getCauseDescription(def build) {
return getCause(build).shortDescription
}

// See more about Hyper container sizes at https://hyper.sh/pricing.html
def runOnHyper(HyperSize size, String mavenOpts, String command) {

String name = UUID.randomUUID()

image = 'checkstyle/maven-builder-image:jdk-8u162b12-maven-3.5.3-groovy-2.4.15'
containerTTL = 1800 // sec

echo GREEN("To try this build locally, execute the following command: [ $command ]")

// 1. Start empty Hyper container with timeout and let it put it's id to the file for further use
retry(3) {
sh "hyper -l=warn run -d --name '${name}' --size=${size.toString()} --cidfile ${name}.cid " +
" --noauto-volume --restart=no -v \$(pwd):/usr/local/checkstyle/ " +
" -e MAVEN_OPTS='${mavenOpts}' ${image} sleep '${containerTTL}'"
}

// 2. Run the build command inside the container
sh "hyper -l=info exec -i '${name}' bash -c '${command}'"

// 3. Cleanup the container as soon as after build finish
sh "hyper rm -fv '${name}' | cat"
}

def runOnHyperS4(String command) {
runOnHyper(HyperSize.S4, DEFAULT_MAVEN_OPTS, command)
}

def runOnHyperM1(String command) {
runOnHyper(HyperSize.M1, DEFAULT_MAVEN_OPTS, command)
}

def runOnHyperM2(String command) {
runOnHyper(HyperSize.M2, DEFAULT_MAVEN_OPTS, command)
}

pipeline {

agent {
Expand Down Expand Up @@ -108,6 +52,8 @@ pipeline {

// Debug: print all the build envvars
// echo sh(returnStdout: true, script: 'env')

sh "mvn --version"
}
}

Expand All @@ -129,14 +75,9 @@ pipeline {

stage('Build') {
parallel {
stage('Compile') {
steps {
runOnHyperS4("mvn -B compile")
}
}
stage('Package') {
steps {
runOnHyperM1("mvn -B package")
sh "mvn -B package"
}
}
}
Expand All @@ -145,9 +86,6 @@ pipeline {

post {
always {
// Cleanup any Hyper.sh containers left by the build, if any
sh "ls | grep '.cid' | xargs -I {} bash -c 'cat {}; echo' | xargs -I {} hyper rm -fv {} | cat"

// Clean up workspace
deleteDir()
}
Expand Down

0 comments on commit 8c93071

Please sign in to comment.