Skip to content

Commit

Permalink
Docker release builds to no longer add latest tag (hyperledger#4791)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Frame <jason.frame@consensys.net>
Co-authored-by: Justin Florentine <justin+github@florentine.us>
  • Loading branch information
jframe and jflo authored Dec 9, 2022
1 parent 19077be commit 1205e3a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: release besu
on:
release:
types: released
jobs:
dockerPromoteX64:
runs-on: ubuntu-latest
steps:
- name: Login to DockerHub
run: echo ${{ secrets.DOCKER_PASSWORD_RW }} | docker login -u ${{ secrets.DOCKER_USER_RW }} --password-stdin
- name: pull tagged image
run: docker pull ${{ secrets.DOCKER_ORG }}/besu:gitSha-${{ github.sha }}
- name: apply latest tag
run: docker tag ${{ secrets.DOCKER_ORG }}/besu:gitSha-${{ github.sha }} ${{ secrets.DOCKER_ORG }}/besu:latest
- name: push
run: docker push ${{ secrets.DOCKER_ORG }}/besu:latest
29 changes: 19 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ artifactoryPublish {
}

def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def dockerImageName = project.hasProperty("dockerImageName") ? project.getProperty("dockerImageName") : "hyperledger/besu"
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-11",
"openjdk-11-debug",
Expand Down Expand Up @@ -639,18 +641,25 @@ task distDocker {
def dockerBuildDir = "build/docker-besu/"

doLast {
for (def variant in dockerVariants) {
for (def jvmVariant in dockerVariants) {
copy {
from file("${projectDir}/docker/${variant}/Dockerfile")
from file("${projectDir}/docker/${jvmVariant}/Dockerfile")
into(dockerBuildDir)
}
exec {
def image = "${dockerImageName}:${dockerBuildVersion}-${variant}"
def image = "${dockerImageName}:${dockerBuildVersion}-${jvmVariant}"
executable "sh"
workingDir dockerBuildDir
args "-c", "docker build --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${getCheckedOutGitCommitHash()} -t ${image} ."
}
}

def shaTag = "gitSha-${getCheckedOutGitCommitHash(40)}" //full length sha
exec {
executable "sh"
args "-c", "docker tag '${dockerImageName}:${dockerBuildVersion}-${dockerVariants[0]}' '${dockerImageName}:${shaTag}'"
}

// tag the "default" (which is the variant in the zero position)
exec {
executable "sh"
Expand Down Expand Up @@ -730,10 +739,9 @@ task dockerUpload {
}

def isInterimBuild = (dockerBuildVersion ==~ /.*-SNAPSHOT/) || (dockerBuildVersion ==~ /.*-alpha/)
|| (dockerBuildVersion ==~ /.*-beta/) || (dockerBuildVersion ==~ /.*-RC/)
|| (dockerBuildVersion ==~ /.*-beta/) || (dockerBuildVersion ==~ /.*-RC.*/)

if (!isInterimBuild) {
additionalTags.add('latest')
additionalTags.add(dockerBuildVersion.split(/\./)[0..1].join('.'))
}

Expand All @@ -760,6 +768,7 @@ task dockerUpload {
}

task manifestDocker {
dependsOn distDocker

def image = "${dockerImageName}:${dockerBuildVersion}"
def archs = ["arm64", "amd64"]
Expand All @@ -770,7 +779,6 @@ task manifestDocker {
}

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

Expand Down Expand Up @@ -865,15 +873,16 @@ def calculateVersion() {
return version
}

def getCheckedOutGitCommitHash() {

def getCheckedOutGitCommitHash(length = 8) {
try {
def gitFolder = "$projectDir/.git/"
if (!file(gitFolder).isDirectory()) {
// We are in a submodule. The file's contents are `gitdir: <gitFolder>\n`.
// Read the file, cut off the front, and trim the whitespace.
gitFolder = file(gitFolder).text.substring(8).trim() + "/"
gitFolder = file(gitFolder).text.substring(length).trim() + "/"
}
def takeFromHash = 8
def takeFromHash = length
/*
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
Expand Down
9 changes: 7 additions & 2 deletions ethereum/evmtool/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ tasks.register("dockerDistUntar") {
task distDocker(type: Exec) {
dependsOn dockerDistUntar
def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def imageName = "hyperledger/besu-evmtool"
def dockerOrgName = project.hasProperty('dockerOrgName') ? project.getProperty("dockerOrgName") : "hyperledger"
def dockerArtifactName = project.hasProperty("dockerArtifactName") ? project.getProperty("dockerArtifactName") : "besu-evmtool"
def imageName = "${dockerOrgName}/${dockerArtifactName}"

def image = "${imageName}:${dockerBuildVersion}"
def dockerBuildDir = "${buildDir}/docker-besu-evmtool/"
workingDir "${dockerBuildDir}"
Expand All @@ -122,7 +125,9 @@ task distDocker(type: Exec) {
task dockerUpload(type: Exec) {
dependsOn distDocker
def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def imageName = "hyperledger/besu-evmtool"
def dockerOrgName = project.hasProperty('dockerOrgName') ? project.getProperty("dockerOrgName") : "hyperledger"
def dockerArtifactName = project.hasProperty("dockerArtifactName") ? project.getProperty("dockerArtifactName") : "besu-evmtool"
def imageName = "${dockerOrgName}/${dockerArtifactName}"
def image = "${imageName}:${dockerBuildVersion}"
def cmd = "docker push '${image}'"
def additionalTags = []
Expand Down

0 comments on commit 1205e3a

Please sign in to comment.