Skip to content

Commit

Permalink
allow setting docker variables through gradle arguments (hyperledger#…
Browse files Browse the repository at this point in the history
…4559)

* allow setting dockerVariant, dockerImagesName through project properties arguments

Signed-off-by: Pedro Novais <jpvnovais@gmail.com>
  • Loading branch information
jpnovais authored Nov 1, 2022
1 parent aff38f4 commit 8535788
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Additions and Improvements
- Updated jackson-databind library to version 2.13.4.2 addressing [CVE-2022-42003](https://nvd.nist.gov/vuln/detail/CVE-2022-42003)
- Gradle task allows custom docker image configs e.g. `./gradlew distDocker -PdockerImageName=my/besu -PdockerVariants=openjdk-17,openjdk-19`

### Bug Fixes
- Fixed default fromBlock value and improved parameter interpretation in eth_getLogs RPC handler [#4513](https://github.com/hyperledger/besu/pull/4513)
Expand Down
34 changes: 15 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ artifactoryPublish {
dependsOn distZip
}

def dockerVariants = [
def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def dockerImageName = project.hasProperty("dockerImageName") ? project.getProperty("dockerImageName") : "hyperledger/besu"
def dockerVariants = project.hasProperty("dockerVariants") ? project.getProperty("dockerVariants").split(",") : [
"openjdk-11",
"openjdk-11-debug",
"graalvm",
Expand Down Expand Up @@ -634,9 +636,7 @@ tasks.register("dockerDistUntar") {
task distDocker {
dependsOn dockerDistUntar
inputs.dir("build/docker-besu/")
def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def dockerBuildDir = "build/docker-besu/"
def imageName = "hyperledger/besu"

doLast {
for (def variant in dockerVariants) {
Expand All @@ -645,7 +645,7 @@ task distDocker {
into(dockerBuildDir)
}
exec {
def image = "${imageName}:${dockerBuildVersion}-${variant}"
def image = "${dockerImageName}:${dockerBuildVersion}-${variant}"
executable "sh"
workingDir dockerBuildDir
args "-c", "docker build --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${getCheckedOutGitCommitHash()} -t ${image} ."
Expand All @@ -654,12 +654,12 @@ task distDocker {
// tag the "default" (which is the variant in the zero position)
exec {
executable "sh"
args "-c", "docker tag '${imageName}:${dockerBuildVersion}-${dockerVariants[0]}' '${imageName}:${dockerBuildVersion}'"
args "-c", "docker tag '${dockerImageName}:${dockerBuildVersion}-${dockerVariants[0]}' '${dockerImageName}:${dockerBuildVersion}'"
}
// create a static tag for the benchmark target
exec {
executable "sh"
args "-c", "docker tag '${imageName}:${dockerBuildVersion}-${dockerVariants[0]}' '${imageName}:benchmark'"
args "-c", "docker tag '${dockerImageName}:${dockerBuildVersion}-${dockerVariants[0]}' '${dockerImageName}:benchmark'"
}
}
}
Expand All @@ -675,7 +675,7 @@ task testDocker {
doLast {
for (def variant in dockerVariants) {
exec {
def image = project.hasProperty('release.releaseVersion') ? "hyperledger/besu:" + project.property('release.releaseVersion') : "hyperledger/besu:${project.version}"
def image = project.hasProperty('release.releaseVersion') ? "${dockerImageName}:" + project.property('release.releaseVersion') : "${dockerImageName}:${project.version}"
workingDir "${projectDir}/docker/${variant}"
executable "sh"
args "-c", "bash ../test.sh ${image}-${variant}"
Expand Down Expand Up @@ -710,7 +710,7 @@ task acceptanceTestsQuorum {
new File(dataDirectory).mkdirs()
new File(reportsDirectory).mkdirs()

def image = project.hasProperty('release.releaseVersion') ? "hyperledger/besu:" + project.property('release.releaseVersion') : "hyperledger/besu:${project.version}"
def image = project.hasProperty('release.releaseVersion') ? "${dockerImageName}:" + project.property('release.releaseVersion') : "${dockerImageName}:${project.version}"
def dockerEnv = "--env LOGGING_LEVEL_COM_QUORUM_GAUGE=DEBUG --env TF_VAR_besu_docker_image='{name=\"${image}-${variant}\",local=true}'"
def dockerVolumes = "-v ${reportsDirectory}:/workspace/target/gauge/reports/ -v /var/run/docker.sock:/var/run/docker.sock -v ${dataDirectory}:${dataDirectory}"
executable "sh"
Expand All @@ -719,13 +719,10 @@ task acceptanceTestsQuorum {
}
}

def dockerImage = "hyperledger/besu"

task dockerUpload {
dependsOn distDocker
def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def architecture = System.getenv('architecture')
def image = "${dockerImage}:${dockerBuildVersion}"
def image = "${dockerImageName}:${dockerBuildVersion}"
def additionalTags = []

if (project.hasProperty('branch') && project.property('branch') == 'main') {
Expand All @@ -743,7 +740,7 @@ task dockerUpload {
exec {
def archVariantImage = "${variantImage}-${architecture}"
def cmd = "docker tag '${variantImage}' '${archVariantImage}' && docker push '${archVariantImage}'"
additionalTags.each { tag -> cmd += " && docker tag '${variantImage}' '${dockerImage}:${tag.trim()}-${variant}-${architecture}' && docker push '${dockerImage}:${tag.trim()}-${variant}-${architecture}'" }
additionalTags.each { tag -> cmd += " && docker tag '${variantImage}' '${dockerImageName}:${tag.trim()}-${variant}-${architecture}' && docker push '${dockerImageName}:${tag.trim()}-${variant}-${architecture}'" }
executable "sh"
args "-c", cmd
}
Expand All @@ -752,7 +749,7 @@ task dockerUpload {
exec {
def archImage = "${image}-${architecture}"
def cmd = "docker tag ${image} ${archImage} && docker push '${archImage}'"
additionalTags.each { tag -> cmd += " && docker tag '${image}' '${dockerImage}:${tag.trim()}-${architecture}' && docker push '${dockerImage}:${tag.trim()}-${architecture}'" }
additionalTags.each { tag -> cmd += " && docker tag '${image}' '${dockerImageName}:${tag.trim()}-${architecture}' && docker push '${dockerImageName}:${tag.trim()}-${architecture}'" }
executable "sh"
args "-c", cmd
}
Expand All @@ -761,18 +758,17 @@ task dockerUpload {

task manifestDocker {

def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def image = "${dockerImage}:${dockerBuildVersion}"
def image = "${dockerImageName}:${dockerBuildVersion}"
def archs = ["arm64", "amd64"]
def tags = ["${image}"]

if (project.hasProperty('branch') && project.property('branch') == 'main') {
tags.add("${dockerImage}:develop")
tags.add("${dockerImageName}:develop")
}

if (!(dockerBuildVersion ==~ /.*-SNAPSHOT/)) {
tags.add("${dockerImage}:latest")
tags.add("${dockerImage}:" + dockerBuildVersion.split(/\./)[0..1].join('.'))
tags.add("${dockerImageName}:latest")
tags.add("${dockerImageName}:" + dockerBuildVersion.split(/\./)[0..1].join('.'))
}

doLast {
Expand Down

0 comments on commit 8535788

Please sign in to comment.