From 1c59bdc7d8fc666e3e1be1b5694d6458ea96a338 Mon Sep 17 00:00:00 2001 From: Jason Frame Date: Thu, 15 Dec 2022 07:24:59 +1000 Subject: [PATCH] Docker release task for latest tags (#4810) Signed-off-by: Jason Frame --- .github/workflows/release.yml | 13 ++++---- build.gradle | 60 ++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 19c523ada6..1805b4af88 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,11 +6,12 @@ jobs: dockerPromoteX64: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 - 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 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + - name: Docker upload + run: ./gradlew "-Prelease.releaseVersion=${{ github.ref_name }}" "-PdockerOrgName=${{ secrets.DOCKER_ORG }}" dockerUploadRelease + - name: Docker manifest + run: ./gradlew "-Prelease.releaseVersion=${{ github.ref_name }}" "-PdockerOrgName=${{ secrets.DOCKER_ORG }}" manifestDockerRelease diff --git a/build.gradle b/build.gradle index 2052788a3e..7f67cce3a1 100644 --- a/build.gradle +++ b/build.gradle @@ -654,12 +654,6 @@ task distDocker { } } - 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" @@ -767,9 +761,32 @@ task dockerUpload { } } -task manifestDocker { - dependsOn distDocker +task dockerUploadRelease { + def archs = ["arm64", "amd64"] + def image = "${dockerImageName}:${dockerBuildVersion}" + + 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}' && docker push '${dockerImageName}:latest-${variant}-${architecture}'" + executable "sh" + args "-c", cmd + } + } + exec { + def archImage = "${image}-${architecture}" + def cmd = "docker pull '${archImage}' && docker tag ${archImage} '${dockerImageName}:latest-${architecture}' && docker push '${dockerImageName}:latest-${architecture}'" + executable "sh" + args "-c", cmd + } + } + } +} + +task manifestDocker { def image = "${dockerImageName}:${dockerBuildVersion}" def archs = ["arm64", "amd64"] def tags = ["${image}"] @@ -807,6 +824,33 @@ task manifestDocker { } } +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} && docker manifest push '${variantImage}'" + executable "sh" + args "-c", cmd + } + } + + exec { + def targets = "" + archs.forEach { arch -> targets += "'${baseTag}-${arch}' " } + def cmd = "docker manifest create '${baseTag}' ${targets} && docker manifest push '${baseTag}'" + executable "sh" + args "-c", cmd + } + } +} + task checkSpdxHeader(type: CheckSpdxHeader) { apply plugin: 'groovy'