diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt index ded62cc..80b4e17 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt @@ -15,8 +15,37 @@ fun Prov.installDevOps() = task { installTerraform() installKubectlAndTools() installYq() + installGraalVM() } +fun Prov.installGraalVM():ProvResult = task{ + val version = "21.0.2" + val tmpDir = "~/tmp" + val filename = "graalvm-community-jdk-" + val additionalPartFilename = "_linux-x64_bin" + val packedFilename = "$filename$version$additionalPartFilename.tar.gz" + val extractedFilenameHunch = "graalvm-community-openjdk-" + val installationPath = "/usr/lib/jvm/" + + if ( !chk("/usr/local/bin/native-image --version") || version != cmd("/usr/local/bin/native-image --version").out?.trim() || !chk("ls -d $installationPath$extractedFilenameHunch$version*")) { + downloadFromURL( + "https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-$version/$packedFilename", + path = tmpDir, + sha256sum = "b048069aaa3a99b84f5b957b162cc181a32a4330cbc35402766363c5be76ae48" + ) + if (!chk("ls -d $installationPath")) + cmd("sudo mkdir $installationPath") + else { + ProvResult(true, out = "$installationPath just exists, mkdir not necessary.") + } + cmd("sudo tar -C $installationPath -xzf $packedFilename", tmpDir) + val graalInstPath = installationPath + (cmd("ls /usr/lib/jvm/|grep -e graalvm-community-openjdk-$version").out?.replace("\n", "")) + cmd("sudo ln -s $graalInstPath/lib/svm/bin/native-image /usr/local/bin/native-image") + cmd("/usr/local/bin/native-image --version") + } else { + ProvResult(true, out = "GraalVM $version already installed") + } +} fun Prov.installYq( version: String = "4.13.2", diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt index b18acfe..8248ea5 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt @@ -1,10 +1,7 @@ package org.domaindrivenarchitecture.provs.desktop.infrastructure import org.domaindrivenarchitecture.provs.framework.core.getResourceAsText -import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.checkFile -import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDir -import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDirs -import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileContainsText +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.* import org.domaindrivenarchitecture.provs.test.defaultTestContainer import org.domaindrivenarchitecture.provs.test.tags.ContainerTest import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest @@ -62,4 +59,17 @@ internal class DevOpsKtTest { assertTrue(res.success) assertTrue(prov.checkFile("/usr/local/bin/kubeconform")) } + + @ContainerTest + fun installGraalVM() { + // given + val prov = defaultTestContainer() + + // when + val res = prov.installGraalVM() + + // then + assertTrue(res.success) + assertTrue(prov.checkFile("/usr/local/bin/native-image")) + } }