build.gradle.kts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
  2. import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
  3. import org.gradle.configurationcache.extensions.capitalized
  4. plugins {
  5. id("otel.spotless-conventions")
  6. id("com.bmuschko.docker-remote-api")
  7. }
  8. data class ImageTarget(
  9. val version: List<String>,
  10. val vm: List<String>,
  11. val jdk: List<String>,
  12. val args: Map<String, String> = emptyMap(),
  13. val war: String = "servlet-3.0",
  14. val windows: Boolean = true
  15. )
  16. val extraTag = findProperty("extraTag")
  17. ?: java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd.HHmmSS").format(java.time.LocalDateTime.now())
  18. // Each line under appserver describes one matrix of (version x vm x jdk), dockerfile key overrides
  19. // Dockerfile name, args key passes raw arguments to docker build
  20. val targets = mapOf(
  21. "jetty" to listOf(
  22. ImageTarget(listOf("9.4.53"), listOf("hotspot", "openj9"), listOf("8", "11", "17", "21"), mapOf("sourceVersion" to "9.4.53.v20231009")),
  23. ImageTarget(listOf("10.0.19"), listOf("hotspot", "openj9"), listOf("11", "17", "21"), mapOf("sourceVersion" to "10.0.19")),
  24. ImageTarget(listOf("11.0.19"), listOf("hotspot", "openj9"), listOf("11", "17", "21"), mapOf("sourceVersion" to "11.0.19"), "servlet-5.0"),
  25. ImageTarget(listOf("12.0.6"), listOf("hotspot", "openj9"), listOf("17", "21"), mapOf("sourceVersion" to "12.0.6"), "servlet-5.0"),
  26. ),
  27. "liberty" to listOf(
  28. ImageTarget(listOf("20.0.0.12"), listOf("hotspot", "openj9"), listOf("8", "11"), mapOf("release" to "2020-11-11_0736")),
  29. ImageTarget(listOf("21.0.0.12"), listOf("hotspot", "openj9"), listOf("8", "11", "17"), mapOf("release" to "2021-11-17_1256")),
  30. // Java 19 is not supported until 22.0.0.10
  31. ImageTarget(listOf("22.0.0.12"), listOf("hotspot", "openj9"), listOf("8", "11", "17"), mapOf("release" to "22.0.0.12")),
  32. // Java 21 is not supported until 23.0.0.3 - despite that only 20 seems to work
  33. ImageTarget(listOf("23.0.0.12"), listOf("hotspot", "openj9"), listOf("8", "11", "17", "20"), mapOf("release" to "23.0.0.12")),
  34. ),
  35. "payara" to listOf(
  36. ImageTarget(listOf("5.2020.6", "5.2021.8"), listOf("hotspot", "openj9"), listOf("8", "11")),
  37. // Test application is not deployed when server is sarted with hotspot jdk version 21
  38. ImageTarget(listOf("6.2023.12"), listOf("hotspot"), listOf("11", "17"), war = "servlet-5.0"),
  39. ImageTarget(listOf("6.2023.12"), listOf("openj9"), listOf("11", "17", "21"), war = "servlet-5.0")
  40. ),
  41. "tomcat" to listOf(
  42. ImageTarget(listOf("7.0.109"), listOf("hotspot", "openj9"), listOf("8"), mapOf("majorVersion" to "7")),
  43. ImageTarget(listOf("8.5.98"), listOf("hotspot", "openj9"), listOf("8", "11", "17", "21"), mapOf("majorVersion" to "8")),
  44. ImageTarget(listOf("9.0.85"), listOf("hotspot", "openj9"), listOf("8", "11", "17", "21"), mapOf("majorVersion" to "9")),
  45. ImageTarget(listOf("10.1.18"), listOf("hotspot", "openj9"), listOf("11", "17", "21"), mapOf("majorVersion" to "10"), "servlet-5.0"),
  46. ),
  47. "tomee" to listOf(
  48. ImageTarget(listOf("7.0.9", "7.1.4"), listOf("hotspot", "openj9"), listOf("8")),
  49. ImageTarget(listOf("8.0.16"), listOf("hotspot", "openj9"), listOf("8", "11", "17", "21")),
  50. ImageTarget(listOf("9.1.2"), listOf("hotspot", "openj9"), listOf("11", "17", "21"), war = "servlet-5.0"),
  51. ),
  52. "websphere" to listOf(
  53. ImageTarget(listOf("8.5.5.22", "9.0.5.14"), listOf("openj9"), listOf("8"), windows = false),
  54. ),
  55. "wildfly" to listOf(
  56. ImageTarget(listOf("13.0.0.Final"), listOf("hotspot", "openj9"), listOf("8")),
  57. ImageTarget(
  58. listOf("17.0.1.Final", "21.0.0.Final"),
  59. listOf("hotspot", "openj9"),
  60. listOf("8", "11", "17", "21")
  61. ),
  62. ImageTarget(
  63. listOf("28.0.1.Final", "29.0.1.Final", "30.0.1.Final"),
  64. listOf("hotspot", "openj9"),
  65. listOf("11", "17", "21"),
  66. war = "servlet-5.0"
  67. ),
  68. ),
  69. )
  70. val matrix = mutableListOf<String>()
  71. tasks {
  72. val buildLinuxTestImages by registering {
  73. group = "build"
  74. description = "Builds all Linux Docker images for the test matrix"
  75. }
  76. val buildWindowsTestImages by registering {
  77. group = "build"
  78. description = "Builds all Windows Docker images for the test matrix"
  79. }
  80. val pushMatrix by registering(DockerPushImage::class) {
  81. mustRunAfter(buildLinuxTestImages)
  82. mustRunAfter(buildWindowsTestImages)
  83. group = "publishing"
  84. description = "Push all Docker images for the test matrix"
  85. images.set(matrix)
  86. }
  87. createDockerTasks(buildLinuxTestImages, false)
  88. createDockerTasks(buildWindowsTestImages, true)
  89. val printSmokeTestsConfigurations by registering {
  90. for ((server, matrices) in targets) {
  91. val smokeTestServer = findProperty("smokeTestServer")
  92. if (smokeTestServer != null && server != smokeTestServer) {
  93. continue
  94. }
  95. println(server)
  96. val serverName = server.capitalized()
  97. for (entry in matrices) {
  98. for (version in entry.version) {
  99. val dotIndex = version.indexOf('.')
  100. val majorVersion = if (dotIndex != -1) version.substring(0, dotIndex) else version
  101. for (jdk in entry.jdk) {
  102. for (vm in entry.vm) {
  103. println("@AppServer(version = \"$version\", jdk = \"$jdk${if (vm == "hotspot") "" else "-openj9"}\")")
  104. println("class ${serverName}${majorVersion}Jdk${jdk}${if (vm == "hotspot") "" else "Openj9"} extends ${serverName}SmokeTest {")
  105. println("}")
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. }
  113. fun configureImage(
  114. parentTask: TaskProvider<out Task>,
  115. server: String,
  116. dockerfile: String,
  117. version: String,
  118. vm: String,
  119. jdk: String,
  120. warProject: String,
  121. args: Map<String, String>,
  122. isWindows: Boolean
  123. ): String {
  124. // Using separate build directory for different image
  125. val dockerWorkingDir = layout.buildDirectory.dir("docker-$server-$version-jdk$jdk-$vm-$warProject")
  126. val dockerFileName = "$dockerfile.${if (isWindows) "windows." else ""}dockerfile"
  127. val platformSuffix = if (isWindows) "-windows" else ""
  128. val prepareTask = tasks.register<Copy>("${server}ImagePrepare-$version-jdk$jdk-$vm$platformSuffix") {
  129. val warTask = project(":smoke-tests:images:servlet:$warProject").tasks.named<War>("war")
  130. dependsOn(warTask)
  131. into(dockerWorkingDir)
  132. from("src/$dockerFileName")
  133. from("src/main/docker/$server")
  134. from(warTask.get().archiveFile) {
  135. rename { "app.war" }
  136. }
  137. }
  138. val vmSuffix = if (vm == "hotspot") "" else "-$vm"
  139. val image = "ghcr.io/open-telemetry/opentelemetry-java-instrumentation/smoke-test-servlet-$server:$version-jdk$jdk$vmSuffix$platformSuffix-$extraTag"
  140. val jdkImage = if (vm == "hotspot") {
  141. if (jdk == "21") {
  142. // "The only tags which will continue to receive updates beyond July 2022 will be Early Access
  143. // builds (which are sourced from jdk.java.net), as those are not published/supported by any
  144. // of the above projects."
  145. // (see https://hub.docker.com/_/openjdk)
  146. "openjdk:$jdk"
  147. } else {
  148. "eclipse-temurin:$jdk"
  149. }
  150. } else if (vm == "openj9") {
  151. if (isWindows) {
  152. // ibm-semeru-runtimes doesn't publish windows images
  153. throw GradleException("Unexpected vm: $vm")
  154. } else {
  155. "ibm-semeru-runtimes:open-$jdk-jdk"
  156. }
  157. } else {
  158. throw GradleException("Unexpected vm: $vm")
  159. }
  160. val extraArgs = args.toMutableMap()
  161. if (server == "wildfly") {
  162. // wildfly url without .zip or .tar.gz suffix
  163. val majorVersion = version.substring(0, version.indexOf(".")).toInt()
  164. val serverBaseUrl = if (majorVersion >= 25) {
  165. "https://github.com/wildfly/wildfly/releases/download/$version/wildfly-$version"
  166. } else {
  167. "https://download.jboss.org/wildfly/$version/wildfly-$version"
  168. }
  169. extraArgs["baseDownloadUrl"] = serverBaseUrl
  170. } else if (server == "payara") {
  171. if (version == "5.2020.6") {
  172. extraArgs["domainName"] = "production"
  173. } else {
  174. extraArgs["domainName"] = "domain1"
  175. }
  176. }
  177. val buildTask = tasks.register<DockerBuildImage>("${server}Image-$version-jdk$jdk$vmSuffix$platformSuffix") {
  178. dependsOn(prepareTask)
  179. group = "build"
  180. description = "Builds Docker image with $server $version on JDK $jdk-$vm${if (isWindows) " on Windows" else ""}"
  181. inputDir.set(dockerWorkingDir)
  182. images.add(image)
  183. dockerFile.set(File(dockerWorkingDir.get().asFile, dockerFileName))
  184. buildArgs.set(extraArgs + mapOf("jdk" to jdk, "vm" to vm, "version" to version, "jdkImage" to jdkImage))
  185. doLast {
  186. matrix.add(image)
  187. }
  188. }
  189. parentTask.configure {
  190. dependsOn(buildTask)
  191. }
  192. return image
  193. }
  194. fun createDockerTasks(parentTask: TaskProvider<out Task>, isWindows: Boolean) {
  195. val resultImages = mutableSetOf<String>()
  196. for ((server, matrices) in targets) {
  197. val smokeTestServer = findProperty("smokeTestServer")
  198. if (smokeTestServer != null && server != smokeTestServer) {
  199. continue
  200. }
  201. for (entry in matrices) {
  202. val dockerfile = server
  203. val extraArgs = entry.args
  204. val warProject = entry.war
  205. val supportsWindows = entry.windows
  206. for (version in entry.version) {
  207. for (vm in entry.vm) {
  208. if (vm == "openj9" && isWindows) {
  209. // ibm-semeru-runtimes doesn't publish windows images
  210. continue
  211. }
  212. for (jdk in entry.jdk) {
  213. if (supportsWindows || !isWindows) {
  214. resultImages.add(configureImage(parentTask, server, dockerfile, version, vm, jdk, warProject, extraArgs, isWindows))
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. }