refactorings, reformats, minor fixes, update docs
This commit is contained in:
parent
277302d0ee
commit
469f864339
7 changed files with 93 additions and 69 deletions
|
@ -6,7 +6,10 @@
|
||||||
## Purpose
|
## Purpose
|
||||||
|
|
||||||
provs provides cli-based tools for
|
provs provides cli-based tools for
|
||||||
* provisioning a desktop (various kinds)
|
* provisioning desktop software for different desktop types:
|
||||||
|
* basic
|
||||||
|
* office
|
||||||
|
* IDE
|
||||||
* provisioning a k3s server
|
* provisioning a k3s server
|
||||||
* performing system checks
|
* performing system checks
|
||||||
|
|
||||||
|
|
|
@ -18,39 +18,10 @@ fun Prov.installDevOps() = task {
|
||||||
installGraalVM()
|
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|awk 'NR==1 {print $2}").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(
|
fun Prov.installYq(
|
||||||
version: String = "4.13.2",
|
version: String = "4.13.2",
|
||||||
sha256sum: String = "d7c89543d1437bf80fee6237eadc608d1b121c21a7cbbe79057d5086d74f8d79"
|
sha256sum: String = "d7c89543d1437bf80fee6237eadc608d1b121c21a7cbbe79057d5086d74f8d79"
|
||||||
): ProvResult = task {
|
) = task {
|
||||||
val path = "/usr/bin/"
|
val path = "/usr/bin/"
|
||||||
val filename = "yq"
|
val filename = "yq"
|
||||||
if (!checkFile(path + filename)) {
|
if (!checkFile(path + filename)) {
|
||||||
|
@ -67,7 +38,7 @@ fun Prov.installYq(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Prov.installKubectlAndTools(): ProvResult = task {
|
fun Prov.installKubectlAndTools() = task {
|
||||||
|
|
||||||
task("installKubectl") {
|
task("installKubectl") {
|
||||||
if (!checkFile(KUBE_CONFIG_CONTEXT_SCRIPT)) {
|
if (!checkFile(KUBE_CONFIG_CONTEXT_SCRIPT)) {
|
||||||
|
@ -105,7 +76,7 @@ fun Prov.installKubeconform() = task {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Prov.installKubectl(): ProvResult = task {
|
fun Prov.installKubectl() = task {
|
||||||
|
|
||||||
// see https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
|
// see https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
|
||||||
val kubectlVersion = "1.27.4"
|
val kubectlVersion = "1.27.4"
|
||||||
|
@ -126,13 +97,13 @@ fun Prov.installKubectl(): ProvResult = task {
|
||||||
cmd("sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl", dir = tmpDir)
|
cmd("sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl", dir = tmpDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Prov.configureKubectlBashCompletion(): ProvResult = task {
|
fun Prov.configureKubectlBashCompletion() = task {
|
||||||
cmd("kubectl completion bash >> /etc/bash_completion.d/kubernetes", sudo = true)
|
cmd("kubectl completion bash >> /etc/bash_completion.d/kubernetes", sudo = true)
|
||||||
createDir(".bashrc.d")
|
createDir(".bashrc.d")
|
||||||
createFileFromResource(KUBE_CONFIG_CONTEXT_SCRIPT, "kubectl.sh", RESOURCE_PATH)
|
createFileFromResource(KUBE_CONFIG_CONTEXT_SCRIPT, "kubectl.sh", RESOURCE_PATH)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Prov.installDevopsScripts() {
|
fun Prov.installDevopsScripts() = task {
|
||||||
|
|
||||||
task("install ssh helper") {
|
task("install ssh helper") {
|
||||||
createFileFromResource(
|
createFileFromResource(
|
||||||
|
@ -174,7 +145,7 @@ fun Prov.installDevopsScripts() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Prov.installTerraform(): ProvResult = task {
|
fun Prov.installTerraform() = task {
|
||||||
val dir = "/usr/lib/tfenv/"
|
val dir = "/usr/lib/tfenv/"
|
||||||
|
|
||||||
if (!checkDir(dir)) {
|
if (!checkDir(dir)) {
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package org.domaindrivenarchitecture.provs.desktop.infrastructure
|
||||||
|
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL
|
||||||
|
|
||||||
|
const val GRAAL_VM_VERSION = "21.0.2"
|
||||||
|
|
||||||
|
|
||||||
|
fun Prov.installGraalVM() = taskWithResult {
|
||||||
|
val tmpDir = "~/tmp"
|
||||||
|
val filename = "graalvm-community-jdk-"
|
||||||
|
val additionalPartFilename = "_linux-x64_bin"
|
||||||
|
val packedFilename = "$filename$GRAAL_VM_VERSION$additionalPartFilename.tar.gz"
|
||||||
|
val extractedFilenameHunch = "graalvm-community-openjdk-"
|
||||||
|
val installationPath = "/usr/lib/jvm/"
|
||||||
|
|
||||||
|
if ( GRAAL_VM_VERSION != graalVMVersion() || !chk("ls -d $installationPath$extractedFilenameHunch$GRAAL_VM_VERSION*")) {
|
||||||
|
downloadFromURL(
|
||||||
|
"https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-$GRAAL_VM_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-$GRAAL_VM_VERSION").out?.replace("\n", ""))
|
||||||
|
cmd("sudo ln -sf $graalInstPath/lib/svm/bin/native-image /usr/local/bin/native-image")
|
||||||
|
cmd("/usr/local/bin/native-image --version")
|
||||||
|
} else {
|
||||||
|
ProvResult(true, out = "GraalVM $GRAAL_VM_VERSION already installed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Prov.graalVMVersion(): String {
|
||||||
|
return cmdNoEval("/usr/local/bin/native-image --version|awk 'NR==1 {print $2}'").out?.trim() ?: ""
|
||||||
|
}
|
|
@ -80,8 +80,8 @@ open class Prov protected constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A task is the base execution unit in provs. In the results overview it is represented by one line resp. result (of either success or failure).
|
* A task is the fundamental execution unit. In the results overview it is represented by one line with a success or failure result.
|
||||||
* Returns success if no sub-tasks are called or if all subtasks finish with success.
|
* Returns success if all sub-tasks finished with success or if no sub-tasks are called at all.
|
||||||
*/
|
*/
|
||||||
fun task(name: String? = null, taskLambda: Prov.() -> Unit): ProvResult {
|
fun task(name: String? = null, taskLambda: Prov.() -> Unit): ProvResult {
|
||||||
printDeprecationWarningIfLevel0("task")
|
printDeprecationWarningIfLevel0("task")
|
||||||
|
@ -89,8 +89,10 @@ open class Prov protected constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as task but the provided lambda is explicitly required to provide a ProvResult to be returned.
|
* Same as task above but the lambda parameter must have a ProvResult as return type.
|
||||||
* The returned result is included in the evaluation.
|
* The returned ProvResult is included in the success resp. failure evaluation,
|
||||||
|
* i.e. if the returned ProvResult from the lambda fails, the returned ProvResult from
|
||||||
|
* taskWithResult also fails, else success depends on potentially called sub-tasks.
|
||||||
*/
|
*/
|
||||||
fun taskWithResult(name: String? = null, taskLambda: Prov.() -> ProvResult): ProvResult {
|
fun taskWithResult(name: String? = null, taskLambda: Prov.() -> ProvResult): ProvResult {
|
||||||
printDeprecationWarningIfLevel0("taskWithResult")
|
printDeprecationWarningIfLevel0("taskWithResult")
|
||||||
|
@ -98,27 +100,27 @@ open class Prov protected constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* defines a task, which returns the returned result, the results of sub-tasks are not considered
|
* defines a task, which returns the returned result from the lambda, the results of sub-tasks are not considered
|
||||||
*/
|
*/
|
||||||
fun requireLast(name: String? = null, a: Prov.() -> ProvResult): ProvResult {
|
fun requireLast(name: String? = null, taskLambda: Prov.() -> ProvResult): ProvResult {
|
||||||
printDeprecationWarningIfLevel0("requireLast")
|
printDeprecationWarningIfLevel0("requireLast")
|
||||||
return evaluate(ResultMode.LAST, name) { a() }
|
return evaluate(ResultMode.LAST, name) { taskLambda() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* defines a task, which always returns success
|
* Defines a task, which always returns success.
|
||||||
*/
|
*/
|
||||||
fun optional(name: String? = null, a: Prov.() -> ProvResult): ProvResult {
|
fun optional(name: String? = null, taskLambda: Prov.() -> ProvResult): ProvResult {
|
||||||
printDeprecationWarningIfLevel0("optional")
|
printDeprecationWarningIfLevel0("optional")
|
||||||
return evaluate(ResultMode.OPTIONAL, name) { a() }
|
return evaluate(ResultMode.OPTIONAL, name) { taskLambda() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* defines a task, which exits the overall execution on failure
|
* Defines a task, which exits the overall execution on failure result of the taskLambda.
|
||||||
*/
|
*/
|
||||||
fun exitOnFailure(a: Prov.() -> ProvResult): ProvResult {
|
fun exitOnFailure(taskLambda: Prov.() -> ProvResult): ProvResult {
|
||||||
printDeprecationWarningIfLevel0("exitOnFailure")
|
printDeprecationWarningIfLevel0("exitOnFailure")
|
||||||
return evaluate(ResultMode.FAILEXIT) { a() }
|
return evaluate(ResultMode.FAILEXIT) { taskLambda() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.infrastructure
|
package org.domaindrivenarchitecture.provs.server.infrastructure
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.*
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.*
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL
|
||||||
|
|
||||||
|
@ -12,10 +11,8 @@ const val K9S_VERSION = "v0.32.5"
|
||||||
// ----------------------------------- public functions --------------------------------
|
// ----------------------------------- public functions --------------------------------
|
||||||
|
|
||||||
|
|
||||||
fun Prov.installK9s(): ProvResult {
|
fun Prov.installK9s() = task {
|
||||||
return taskWithResult {
|
|
||||||
createDir("/tmp", sudo = true)
|
createDir("/tmp", sudo = true)
|
||||||
downloadFromURL( "https://github.com/derailed/k9s/releases/download/" + K9S_VERSION + "/k9s_linux_amd64.deb", "k9s_linux_amd64.deb", "/tmp")
|
downloadFromURL("https://github.com/derailed/k9s/releases/download/" + K9S_VERSION + "/k9s_linux_amd64.deb", "k9s_linux_amd64.deb", "/tmp")
|
||||||
cmd("sudo dpkg -i k9s_linux_amd64.deb", "/tmp")
|
cmd("sudo dpkg -i k9s_linux_amd64.deb", "/tmp")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,17 +59,4 @@ internal class DevOpsKtTest {
|
||||||
assertTrue(res.success)
|
assertTrue(res.success)
|
||||||
assertTrue(prov.checkFile("/usr/local/bin/kubeconform"))
|
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"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.domaindrivenarchitecture.provs.desktop.infrastructure
|
||||||
|
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.checkFile
|
||||||
|
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
||||||
|
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions.*
|
||||||
|
|
||||||
|
class GraalVMKtTest {
|
||||||
|
|
||||||
|
@ContainerTest
|
||||||
|
fun installGraalVM() {
|
||||||
|
// given
|
||||||
|
val prov = defaultTestContainer()
|
||||||
|
|
||||||
|
// when
|
||||||
|
val res = prov.installGraalVM()
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertTrue(res.success)
|
||||||
|
assertTrue(GRAAL_VM_VERSION == prov.graalVMVersion())
|
||||||
|
assertTrue(prov.checkFile("/usr/local/bin/native-image"))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue