From 2168920da868080f0fb30451a94b7f66c13cee70 Mon Sep 17 00:00:00 2001 From: Chad Wilson Date: Tue, 28 Sep 2021 15:11:45 +0800 Subject: [PATCH] Allow targetting Alpine Linux independently of regular Linux when downloading Adoptium/Eclipse Temurin builds Adoptium now publish validated Alpine Linux builds of Eclipse Temurin JVM, compiled directly against musl libc (rather than glibc). Using these would avoid the need to use the Alpine GLIBC package which is not recommended by the Alpine team, and which is no longer supported by Adopt in their own containers. See the long discussion at https://github.com/adoptium/containers/issues/1 At time of writing we cannot move away from glibc because the Tanuki wrapper does not seem to work against musl, OR with either gcompat or libc6-compat compatibility layers (both seem to be missing some symbols). However this allows us to do so in future by changing the targetted `OperatingSystem` in the alpine and docker-dind `Distro`s --- .../go/build/AdoptiumUrlHelper.groovy | 11 +------ .../go/build/OperatingSystem.groovy | 31 +++++++++++++++++++ .../go/build/docker/Distro.groovy | 12 ++++++- .../go/build/docker/DistroBehavior.groovy | 7 ++++- 4 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 buildSrc/src/main/groovy/com/thoughtworks/go/build/OperatingSystem.groovy diff --git a/buildSrc/src/main/groovy/com/thoughtworks/go/build/AdoptiumUrlHelper.groovy b/buildSrc/src/main/groovy/com/thoughtworks/go/build/AdoptiumUrlHelper.groovy index ad269bc1bb20..f7f941baef1c 100644 --- a/buildSrc/src/main/groovy/com/thoughtworks/go/build/AdoptiumUrlHelper.groovy +++ b/buildSrc/src/main/groovy/com/thoughtworks/go/build/AdoptiumUrlHelper.groovy @@ -16,22 +16,13 @@ package com.thoughtworks.go.build -enum OperatingSystem { - windows("zip"), linux("tar.gz"), mac("tar.gz") - - final String extension - - OperatingSystem(String extension) { - this.extension = extension - } -} class AdoptiumUrlHelper { static String downloadURL(OperatingSystem operatingSystem, Integer featureVersion, Integer interimVersion, Integer updateVersion, Integer buildVersion) { String versionComponent = [featureVersion, interimVersion, updateVersion].findAll({ it != null }).join('.') String featureSuffix = updateVersion == null ? '' : 'U' - "https://github.com/adoptium/temurin${featureVersion}-binaries/releases/download/jdk-${versionComponent}%2B${buildVersion}/OpenJDK${featureVersion}${featureSuffix}-jre_x64_${operatingSystem.name()}_hotspot_${versionComponent}_${buildVersion}.${operatingSystem.extension}" + "https://github.com/adoptium/temurin${featureVersion}-binaries/releases/download/jdk-${versionComponent}%2B${buildVersion}/OpenJDK${featureVersion}${featureSuffix}-jre_x64_${operatingSystem.adoptiumAlias()}_hotspot_${versionComponent}_${buildVersion}.${operatingSystem.extension}" } static String sha256sumURL(OperatingSystem operatingSystem, Integer featureVersion, Integer interimVersion, Integer updateVersion, Integer buildVersion) { diff --git a/buildSrc/src/main/groovy/com/thoughtworks/go/build/OperatingSystem.groovy b/buildSrc/src/main/groovy/com/thoughtworks/go/build/OperatingSystem.groovy new file mode 100644 index 000000000000..e2ff4f9a35f4 --- /dev/null +++ b/buildSrc/src/main/groovy/com/thoughtworks/go/build/OperatingSystem.groovy @@ -0,0 +1,31 @@ +/* + * Copyright 2021 ThoughtWorks, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.thoughtworks.go.build + +enum OperatingSystem { + windows("zip"), linux("tar.gz"), alpine_linux("tar.gz"), mac("tar.gz") + + final String extension + + OperatingSystem(String extension) { + this.extension = extension + } + + String adoptiumAlias() { + name().replace('_', '-') + } +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/com/thoughtworks/go/build/docker/Distro.groovy b/buildSrc/src/main/groovy/com/thoughtworks/go/build/docker/Distro.groovy index f36fb672fa01..0c3666f4376d 100644 --- a/buildSrc/src/main/groovy/com/thoughtworks/go/build/docker/Distro.groovy +++ b/buildSrc/src/main/groovy/com/thoughtworks/go/build/docker/Distro.groovy @@ -16,11 +16,17 @@ package com.thoughtworks.go.build.docker +import com.thoughtworks.go.build.OperatingSystem import org.gradle.api.Project enum Distro implements DistroBehavior { alpine{ + @Override + OperatingSystem getOperatingSystem() { + OperatingSystem.linux + } + @Override List getSupportedVersions() { def installSasl_Post_3_9 = ['apk add --no-cache libsasl'] @@ -183,6 +189,11 @@ enum Distro implements DistroBehavior { }, docker{ + @Override + OperatingSystem getOperatingSystem() { + return alpine.getOperatingSystem() + } + @Override boolean isPrivilegedModeSupport() { return true @@ -212,7 +223,6 @@ enum Distro implements DistroBehavior { return alpine.getInstallPrerequisitesCommands(distroVersion) } - @Override List getInstallJavaCommands(Project project) { return alpine.getInstallJavaCommands(project) diff --git a/buildSrc/src/main/groovy/com/thoughtworks/go/build/docker/DistroBehavior.groovy b/buildSrc/src/main/groovy/com/thoughtworks/go/build/docker/DistroBehavior.groovy index 470f91a3cf34..26eb7dad9239 100644 --- a/buildSrc/src/main/groovy/com/thoughtworks/go/build/docker/DistroBehavior.groovy +++ b/buildSrc/src/main/groovy/com/thoughtworks/go/build/docker/DistroBehavior.groovy @@ -17,6 +17,7 @@ package com.thoughtworks.go.build.docker import com.thoughtworks.go.build.AdoptiumUrlHelper +import com.thoughtworks.go.build.OperatingSystem import org.gradle.api.Project trait DistroBehavior { @@ -54,7 +55,7 @@ trait DistroBehavior { List getInstallJavaCommands(Project project) { def downloadUrl = AdoptiumUrlHelper.downloadURL( - com.thoughtworks.go.build.OperatingSystem.linux, + getOperatingSystem(), project.packaging.adoptOpenjdk.featureVersion, project.packaging.adoptOpenjdk.interimVersion, project.packaging.adoptOpenjdk.updateVersion, @@ -68,6 +69,10 @@ trait DistroBehavior { ] } + OperatingSystem getOperatingSystem() { + OperatingSystem.linux + } + Map getEnvironmentVariables(DistroVersion distroVersion) { return [GO_JAVA_HOME: '/gocd-jre'] }