From 7246fce59a607fd869e23a3aac2ba7e12af04fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= Date: Thu, 9 May 2024 11:41:46 +0200 Subject: [PATCH 1/2] chore: factorise jdk in docker-bake.hcl --- docker-bake.hcl | 228 ++++++++++++++++++------------------------------ 1 file changed, 87 insertions(+), 141 deletions(-) diff --git a/docker-bake.hcl b/docker-bake.hcl index 2560559a7..434634fd1 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,22 +1,18 @@ group "linux" { targets = [ - "alpine_jdk11", - "alpine_jdk17", - "alpine_jdk21", "agent_archlinux_jdk11", - "debian_jdk11", - "debian_jdk17", - "debian_jdk21", + "alpine", + "debian", "debian_jdk21_preview" ] } group "linux-agent-only" { targets = [ + "agent_archlinux_jdk11", "agent_alpine_jdk11", "agent_alpine_jdk17", "agent_alpine_jdk21", - "agent_archlinux_jdk11", "agent_debian_jdk11", "agent_debian_jdk17", "agent_debian_jdk21", @@ -38,9 +34,7 @@ group "linux-inbound-agent-only" { group "linux-arm64" { targets = [ - "debian_jdk11", - "debian_jdk17", - "debian_jdk21", + "debian", "alpine_jdk21", ] } @@ -62,9 +56,7 @@ group "linux-s390x" { group "linux-ppc64le" { targets = [ - "debian_jdk11", - "debian_jdk17", - "debian_jdk21" + "debian" ] } @@ -129,173 +121,127 @@ function "orgrepo" { result = equal("agent", agentType) ? "${REGISTRY_ORG}/${REGISTRY_REPO_AGENT}" : "${REGISTRY_ORG}/${REGISTRY_REPO_INBOUND_AGENT}" } -target "agent_archlinux_jdk11" { - dockerfile = "archlinux/Dockerfile" - context = "." - args = { - JAVA_VERSION = JAVA11_VERSION - VERSION = REMOTING_VERSION - } - tags = [ - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo("agent")}:${REMOTING_VERSION}-${BUILD_NUMBER}-archlinux" : "", - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo("agent")}:${REMOTING_VERSION}-${BUILD_NUMBER}-archlinux-jdk11" : "", - "${REGISTRY}/${orgrepo("agent")}:archlinux", - "${REGISTRY}/${orgrepo("agent")}:latest-archlinux", - "${REGISTRY}/${orgrepo("agent")}:archlinux-jdk11", - "${REGISTRY}/${orgrepo("agent")}:latest-archlinux-jdk11", - ] - platforms = ["linux/amd64"] +variable "default_jdk" { + default = 17 } -target "alpine_jdk11" { - matrix = { - type = ["agent", "inbound-agent"] - } - name = "${type}_alpine_jdk11" - target = type - dockerfile = "alpine/Dockerfile" - context = "." - args = { - ALPINE_TAG = ALPINE_FULL_TAG - JAVA_VERSION = JAVA11_VERSION - VERSION = REMOTING_VERSION - } - tags = [ - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine-jdk11" : "", - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine${ALPINE_SHORT_TAG}-jdk11" : "", - "${REGISTRY}/${orgrepo(type)}:alpine-jdk11", - "${REGISTRY}/${orgrepo(type)}:alpine${ALPINE_SHORT_TAG}-jdk11", - "${REGISTRY}/${orgrepo(type)}:latest-alpine-jdk11", - "${REGISTRY}/${orgrepo(type)}:latest-alpine${ALPINE_SHORT_TAG}-jdk11", - ] - platforms = ["linux/amd64"] +# Return "true" if the jdk passed as parameter is the same as the default jdk, "false" otherwise +function "is_default_jdk" { + params = [jdk] + result = equal(default_jdk, jdk) ? true : false } -target "alpine_jdk17" { - matrix = { - type = ["agent", "inbound-agent"] - } - name = "${type}_alpine_jdk17" - target = type - dockerfile = "alpine/Dockerfile" - context = "." - args = { - ALPINE_TAG = ALPINE_FULL_TAG - JAVA_VERSION = JAVA17_VERSION - VERSION = REMOTING_VERSION - } - tags = [ - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine" : "", - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine${ALPINE_SHORT_TAG}" : "", - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine-jdk17" : "", - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine${ALPINE_SHORT_TAG}-jdk17" : "", - "${REGISTRY}/${orgrepo(type)}:alpine", - "${REGISTRY}/${orgrepo(type)}:alpine${ALPINE_SHORT_TAG}", - "${REGISTRY}/${orgrepo(type)}:alpine-jdk17", - "${REGISTRY}/${orgrepo(type)}:alpine${ALPINE_SHORT_TAG}-jdk17", - "${REGISTRY}/${orgrepo(type)}:latest-alpine", - "${REGISTRY}/${orgrepo(type)}:latest-alpine${ALPINE_SHORT_TAG}", - "${REGISTRY}/${orgrepo(type)}:latest-alpine-jdk17", - "${REGISTRY}/${orgrepo(type)}:latest-alpine${ALPINE_SHORT_TAG}-jdk17", - ] - platforms = ["linux/amd64"] +# Return the complete Java version corresponding to the jdk passed as parameter +function "javaversion" { + params = [jdk] + result = (equal(11, jdk) + ? "${JAVA11_VERSION}" + : (equal(17, jdk) + ? "${JAVA17_VERSION}" + : "${JAVA21_VERSION}") + ) +} + +# Return an array of Alpine platforms to use depending on the jdk passed as parameter +function "alpine_platforms" { + params = [jdk] + result = (equal(21, jdk) + ? ["linux/amd64", "linux/arm64"] + : ["linux/amd64"] + ) +} + +# Return an array of Debian platforms to use depending on the jdk passed as parameter +function "debian_platforms" { + params = [jdk] + result = (equal(11, jdk) + ? ["linux/amd64", "linux/arm64", "linux/ppc64le", "linux/arm/v7", "linux/s390x"] + : (equal(17, jdk) + ? ["linux/amd64", "linux/arm64", "linux/ppc64le", "linux/arm/v7"] + : ["linux/amd64", "linux/arm64", "linux/ppc64le", "linux/s390x"])) } -target "alpine_jdk21" { +target "alpine" { matrix = { type = ["agent", "inbound-agent"] + jdk = [11, 17, 21] } - name = "${type}_alpine_jdk21" + name = "${type}_alpine_jdk${jdk}" target = type dockerfile = "alpine/Dockerfile" context = "." args = { ALPINE_TAG = ALPINE_FULL_TAG - JAVA_VERSION = JAVA21_VERSION VERSION = REMOTING_VERSION + JAVA_VERSION = "${javaversion(jdk)}" } tags = [ - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine-jdk21" : "", - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine${ALPINE_SHORT_TAG}-jdk21" : "", - "${REGISTRY}/${orgrepo(type)}:alpine-jdk21", - "${REGISTRY}/${orgrepo(type)}:alpine${ALPINE_SHORT_TAG}-jdk21", - "${REGISTRY}/${orgrepo(type)}:latest-alpine-jdk21", - "${REGISTRY}/${orgrepo(type)}:latest-alpine${ALPINE_SHORT_TAG}-jdk21", - ] - platforms = ["linux/amd64", "linux/arm64"] -} - -target "debian_jdk11" { - matrix = { - type = ["agent", "inbound-agent"] - } - name = "${type}_debian_jdk11" - target = type - dockerfile = "debian/Dockerfile" - context = "." - args = { - JAVA_VERSION = JAVA11_VERSION - VERSION = REMOTING_VERSION - DEBIAN_RELEASE = DEBIAN_RELEASE - } - tags = [ - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-jdk11" : "", - "${REGISTRY}/${orgrepo(type)}:bookworm-jdk11", - "${REGISTRY}/${orgrepo(type)}:jdk11", - "${REGISTRY}/${orgrepo(type)}:latest-bookworm-jdk11", - "${REGISTRY}/${orgrepo(type)}:latest-jdk11", + # If there is a tag, add versioned tags suffixed by the jdk + equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine-jdk${jdk}" : "", + equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine${ALPINE_SHORT_TAG}-jdk${jdk}" : "", + # If there is a tag and if the jdk is the default one, add Alpine short tags + equal(ON_TAG, "true") ? (is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine" : "") : "", + equal(ON_TAG, "true") ? (is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-alpine${ALPINE_SHORT_TAG}" : "") : "", + # If the jdk is the default one, add Alpine short tags + is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:alpine" : "", + is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:alpine${ALPINE_SHORT_TAG}" : "", + is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:latest-alpine" : "", + is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:latest-alpine${ALPINE_SHORT_TAG}" : "", + "${REGISTRY}/${orgrepo(type)}:alpine-jdk${jdk}", + "${REGISTRY}/${orgrepo(type)}:alpine${ALPINE_SHORT_TAG}-jdk${jdk}", + "${REGISTRY}/${orgrepo(type)}:latest-alpine-jdk${jdk}", + "${REGISTRY}/${orgrepo(type)}:latest-alpine${ALPINE_SHORT_TAG}-jdk${jdk}", ] - platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/s390x", "linux/ppc64le"] + platforms = alpine_platforms(jdk) } -target "debian_jdk17" { +target "debian" { matrix = { type = ["agent", "inbound-agent"] + jdk = [11, 17, 21] } - name = "${type}_debian_jdk17" + name = "${type}_debian_${jdk}" target = type dockerfile = "debian/Dockerfile" context = "." args = { - JAVA_VERSION = JAVA17_VERSION VERSION = REMOTING_VERSION DEBIAN_RELEASE = DEBIAN_RELEASE + JAVA_VERSION = "${javaversion(jdk)}" } tags = [ - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}" : "", - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-jdk17" : "", - "${REGISTRY}/${orgrepo(type)}:bookworm", - "${REGISTRY}/${orgrepo(type)}:bookworm-jdk17", - "${REGISTRY}/${orgrepo(type)}:jdk17", - "${REGISTRY}/${orgrepo(type)}:latest", - "${REGISTRY}/${orgrepo(type)}:latest-bookworm", - "${REGISTRY}/${orgrepo(type)}:latest-bookworm-jdk17", - "${REGISTRY}/${orgrepo(type)}:latest-jdk17", + # If there is a tag, add versioned tag suffixed by the jdk + equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-jdk${jdk}" : "", + # If there is a tag and if the jdk is the default one, add versioned short tag + equal(ON_TAG, "true") ? (is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}" : "") : "", + # If the jdk is the default one, add Debian and latest short tags + is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:bookworm" : "", + is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:latest" : "", + is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:latest-bookworm" : "", + "${REGISTRY}/${orgrepo(type)}:bookworm-jdk${jdk}", + "${REGISTRY}/${orgrepo(type)}:jdk${jdk}", + "${REGISTRY}/${orgrepo(type)}:latest-bookworm-jdk${jdk}", + "${REGISTRY}/${orgrepo(type)}:latest-jdk${jdk}", ] - platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/ppc64le"] + platforms = debian_platforms(jdk) } -target "debian_jdk21" { - matrix = { - type = ["agent", "inbound-agent"] - } - name = "${type}_debian_jdk21" - target = type - dockerfile = "debian/Dockerfile" +target "agent_archlinux_jdk11" { + dockerfile = "archlinux/Dockerfile" context = "." args = { - JAVA_VERSION = JAVA21_VERSION - VERSION = REMOTING_VERSION - DEBIAN_RELEASE = DEBIAN_RELEASE + JAVA_VERSION = JAVA11_VERSION + VERSION = REMOTING_VERSION } tags = [ - equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-jdk21" : "", - "${REGISTRY}/${orgrepo(type)}:bookworm-jdk21", - "${REGISTRY}/${orgrepo(type)}:jdk21", - "${REGISTRY}/${orgrepo(type)}:latest-bookworm-jdk21", - "${REGISTRY}/${orgrepo(type)}:latest-jdk21", + equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo("agent")}:${REMOTING_VERSION}-${BUILD_NUMBER}-archlinux" : "", + equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo("agent")}:${REMOTING_VERSION}-${BUILD_NUMBER}-archlinux-jdk11" : "", + "${REGISTRY}/${orgrepo("agent")}:archlinux", + "${REGISTRY}/${orgrepo("agent")}:latest-archlinux", + "${REGISTRY}/${orgrepo("agent")}:archlinux-jdk11", + "${REGISTRY}/${orgrepo("agent")}:latest-archlinux-jdk11", ] - platforms = ["linux/amd64", "linux/arm64", "linux/ppc64le", "linux/s390x"] + platforms = ["linux/amd64"] } target "debian_jdk21_preview" { From b1c46e36bb2502db042ec330390f0ffc2dba138d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= <91831478+lemeurherve@users.noreply.github.com> Date: Wed, 15 May 2024 20:16:38 +0200 Subject: [PATCH 2/2] consistency --- docker-bake.hcl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docker-bake.hcl b/docker-bake.hcl index 434634fd1..c9f349d83 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -138,8 +138,7 @@ function "javaversion" { ? "${JAVA11_VERSION}" : (equal(17, jdk) ? "${JAVA17_VERSION}" - : "${JAVA21_VERSION}") - ) + : "${JAVA21_VERSION}")) } # Return an array of Alpine platforms to use depending on the jdk passed as parameter @@ -147,8 +146,7 @@ function "alpine_platforms" { params = [jdk] result = (equal(21, jdk) ? ["linux/amd64", "linux/arm64"] - : ["linux/amd64"] - ) + : ["linux/amd64"]) } # Return an array of Debian platforms to use depending on the jdk passed as parameter