Skip to content
/ besu Public
forked from hyperledger/besu

Commit

Permalink
One JDK to rule them all (hyperledger#6865)
Browse files Browse the repository at this point in the history
* reduce number of jvms provided
* consistent sha length

---------

Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: amsmota <antonio.mota@citi.com>
  • Loading branch information
jflo authored and amsmota committed Apr 16, 2024
1 parent 87ef9cb commit 01480ca
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 379 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,8 @@ jobs:
uses: gradle/actions/setup-gradle@9e899d11ad247ec76be7a60bc1cf9d3abbb9e7f1
with:
cache-disabled: true
- name: hadoLint_openj9-jdk_17
run: docker run --rm -i hadolint/hadolint < docker/openj9-jdk-17/Dockerfile
- name: hadoLint_openjdk_17
run: docker run --rm -i hadolint/hadolint < docker/openjdk-17/Dockerfile
- name: hadoLint_openjdk_17_debug
run: docker run --rm -i hadolint/hadolint < docker/openjdk-17-debug/Dockerfile
- name: hadoLint_openjdk_latest
run: docker run --rm -i hadolint/hadolint < docker/openjdk-latest/Dockerfile
- name: hadoLint_graalvm
run: docker run --rm -i hadolint/hadolint < docker/graalvm/Dockerfile
- name: hadoLint
run: docker run --rm -i hadolint/hadolint < docker/Dockerfile
buildDocker:
needs: hadolint
permissions:
Expand Down
176 changes: 47 additions & 129 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -704,13 +704,6 @@ def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project
def dockerOrgName = project.hasProperty('dockerOrgName') ? project.getProperty("dockerOrgName") : "hyperledger"
def dockerArtifactName = project.hasProperty("dockerArtifactName") ? project.getProperty("dockerArtifactName") : "besu"
def dockerImageName = "${dockerOrgName}/${dockerArtifactName}"
def dockerVariants = project.hasProperty("dockerVariants") ? project.getProperty("dockerVariants").split(",") : [
"openjdk-17",
"openjdk-17-debug",
"openj9-jdk-17",
"graalvm",
"openjdk-latest"
]

// rename the top level dir from besu-<version> to besu and this makes it really
// simple for use in docker
Expand Down Expand Up @@ -738,34 +731,21 @@ task distDocker {
def dockerBuildDir = "build/docker-besu/"

doLast {
for (def jvmVariant in dockerVariants) {
copy {
from file("${projectDir}/docker/${jvmVariant}/Dockerfile")
into(dockerBuildDir)
}
exec {
def image = "${dockerImageName}:${dockerBuildVersion}-${jvmVariant}"
def dockerPlatform = ""
if (project.hasProperty('docker-platform')){
dockerPlatform = "--platform ${project.getProperty('docker-platform')}"
println "Building for platform ${project.getProperty('docker-platform')}"
}
def gitDetails = getGitCommitDetails(10)
executable shell
workingDir dockerBuildDir
args "-c", "docker build ${dockerPlatform} --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${gitDetails.hash} -t ${image} ."
}
}

// tag the "default" (which is the variant in the zero position)
exec {
executable shell
args "-c", "docker tag '${dockerImageName}:${dockerBuildVersion}-${dockerVariants[0]}' '${dockerImageName}:${dockerBuildVersion}'"
copy {
from file("${projectDir}/docker/Dockerfile")
into(dockerBuildDir)
}
// create a static tag for the benchmark target
exec {
def image = "${dockerImageName}:${dockerBuildVersion}"
def dockerPlatform = ""
if (project.hasProperty('docker-platform')){
dockerPlatform = "--platform ${project.getProperty('docker-platform')}"
println "Building for platform ${project.getProperty('docker-platform')}"
}
def gitDetails = getGitCommitDetails(7)
executable shell
args "-c", "docker tag '${dockerImageName}:${dockerBuildVersion}-${dockerVariants[0]}' '${dockerImageName}:benchmark'"
workingDir dockerBuildDir
args "-c", "docker build ${dockerPlatform} --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${gitDetails.hash} -t ${image} ."
}
}
}
Expand All @@ -779,14 +759,13 @@ task testDocker {
}

doLast {
for (def variant in dockerVariants) {
exec {
def image = project.hasProperty('release.releaseVersion') ? "${dockerImageName}:" + project.property('release.releaseVersion') : "${dockerImageName}:${project.version}"
workingDir "${projectDir}/docker/${variant}"
executable shell
args "-c", "../test.sh ${image}-${variant}"
}
exec {
def image = project.hasProperty('release.releaseVersion') ? "${dockerImageName}:" + project.property('release.releaseVersion') : "${dockerImageName}:${project.version}"
workingDir "${projectDir}/docker"
executable shell
args "-c", "./test.sh ${image}"
}

}
}

Expand All @@ -805,22 +784,9 @@ task dockerUpload {
}

doLast {
for (def variant in dockerVariants) {
def variantImage = "${image}-${variant}"
exec {
def archVariantImage = "${variantImage}-${architecture}"
def cmd = "docker tag '${variantImage}' '${archVariantImage}' && docker push '${archVariantImage}'"
additionalTags.each { tag -> cmd += " && docker tag '${variantImage}' '${dockerImageName}:${tag.trim()}-${variant}-${architecture}' && docker push '${dockerImageName}:${tag.trim()}-${variant}-${architecture}'" }
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
}

exec {
def archImage = "${image}-${architecture}"
def cmd = "docker tag ${image} ${archImage} && docker push '${archImage}'"
additionalTags.each { tag -> cmd += " && docker tag '${image}' '${dockerImageName}:${tag.trim()}-${architecture}' && docker push '${dockerImageName}:${tag.trim()}-${architecture}'" }
def archVariantImage = "${image}-${architecture}"
def cmd = "docker tag '${image}' '${archVariantImage}' && docker push '${archVariantImage}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
Expand All @@ -834,25 +800,9 @@ task dockerUploadRelease {

doLast {
for (def architecture in archs) {
for (def variant in dockerVariants) {
def variantImage = "${image}-${variant}"
exec {
def cmd = "docker pull '${variantImage}-${architecture}' && docker tag '${variantImage}-${architecture}' '${dockerImageName}:latest-${variant}-${architecture}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker push '${dockerImageName}:latest-${variant}-${architecture}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
}

exec {
def archImage = "${image}-${architecture}"
def cmd = "docker pull '${archImage}' && docker tag ${archImage} '${dockerImageName}:latest-${architecture}'"
def cmd = "docker pull '${image}-${architecture}' && docker tag '${image}-${architecture}' '${dockerImageName}:latest-${architecture}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
Expand All @@ -863,54 +813,17 @@ task dockerUploadRelease {
executable shell
args "-c", cmd
}
}
}
}

task manifestDocker {
def image = "${dockerImageName}:${dockerBuildVersion}"
def archs = ["arm64", "amd64"]
def tags = ["${image}"]

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

if (!isInterimBuild(dockerBuildVersion)) {
tags.add("${dockerImageName}:" + dockerBuildVersion.split(/\./)[0..1].join('.'))
}

doLast {
for (baseTag in tags) {
for (def variant in dockerVariants) {
def variantImage = "${baseTag}-${variant}"
def targets = ""
archs.forEach { arch -> targets += "'${variantImage}-${arch}' " }

exec {
def cmd = "docker manifest create '${variantImage}' ${targets}"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker manifest push '${variantImage}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
}

exec {
def targets = ""
archs.forEach { arch -> targets += "'${baseTag}-${arch}' " }
def cmd = "docker manifest create '${baseTag}' ${targets}"
def archImage = "${image}-${architecture}"
def cmd = "docker pull '${archImage}' && docker tag ${archImage} '${dockerImageName}:latest-${architecture}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker manifest push '${baseTag}'"
def cmd = "docker push '${dockerImageName}:latest-${architecture}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
Expand All @@ -919,29 +832,34 @@ task manifestDocker {
}
}

task manifestDocker {
def image = "${dockerImageName}:${dockerBuildVersion}"
def archs = [
"arm64",
"amd64"] //TODO: this assumes dockerUpload task has already been run on 2 different archs!
doLast {
exec {
def targets = ""
archs.forEach { arch -> targets += "'${image}-${arch}' " }
def cmd = "docker manifest create '${image}' ${targets}"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker manifest push '${image}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
}
}

task manifestDockerRelease {
def archs = ["arm64", "amd64"]
def baseTag = "${dockerImageName}:latest";

doLast {
for (def variant in dockerVariants) {
def variantImage = "${baseTag}-${variant}"
def targets = ""
archs.forEach { arch -> targets += "'${variantImage}-${arch}' " }

exec {
def cmd = "docker manifest create '${variantImage}' ${targets} --amend"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
exec {
def cmd = "docker manifest push '${variantImage}'"
println "Executing '${cmd}'"
executable shell
args "-c", cmd
}
}

exec {
def targets = ""
Expand Down
File renamed without changes.
49 changes: 0 additions & 49 deletions docker/graalvm/Dockerfile

This file was deleted.

72 changes: 0 additions & 72 deletions docker/openj9-jdk-17/Dockerfile

This file was deleted.

Loading

0 comments on commit 01480ca

Please sign in to comment.