[skip ci] Go installation by provs, Test successful
This commit is contained in:
parent
e990478faa
commit
95c35a007e
2 changed files with 76 additions and 0 deletions
src
main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure
test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure
|
@ -0,0 +1,54 @@
|
|||
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.filesystem.base.*
|
||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackageInstalledCheckCommand
|
||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL
|
||||
|
||||
fun Prov.installGo(
|
||||
//from https://go.dev/dl/
|
||||
version: String = "1.23.5",
|
||||
enforceVersion: Boolean = false,
|
||||
sha256sum: String = "cbcad4a6482107c7c7926df1608106c189417163428200ce357695cc7e01d091"
|
||||
) = taskWithResult {
|
||||
if (isPackageInstalledCheckCommand("go") && !enforceVersion) {
|
||||
return@taskWithResult ProvResult(true)
|
||||
}
|
||||
|
||||
if (checkGoVersion(version)) {
|
||||
return@taskWithResult ProvResult(true, out = "Version $version of go is already installed.")
|
||||
}
|
||||
|
||||
val downloadUrl = "https://go.dev/dl/go$version.linux-amd64.tar.gz"
|
||||
val filename = "go$version.linux-amd64.tar.gz"
|
||||
val target = "${userHome()}tmp"
|
||||
val result = downloadFromURL(
|
||||
downloadUrl,
|
||||
filename,
|
||||
target,
|
||||
sha256sum = sha256sum
|
||||
)
|
||||
|
||||
if (result.success) {
|
||||
cmd("tar -C /usr/local -xzf $target/go1.23.5.linux-amd64.tar.gz", sudo = true)
|
||||
configureBashForUser()
|
||||
createFile("~/.bashrc.d/go.sh", "export PATH=\$PATH:/usr/local/go/bin\n")
|
||||
//cmd(". /usr/local/go/bin/go && go version")
|
||||
// Cross-check if installation was successful
|
||||
deleteFile("$target/$filename")
|
||||
return@taskWithResult ProvResult(checkGoVersion(version))
|
||||
} else {
|
||||
return@taskWithResult ProvResult(false, err = "Go $version could not be installed. " + result.err)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Prov.checkGoVersion(version: String): Boolean {
|
||||
val installedGoVersion = goVersion()
|
||||
return installedGoVersion != null && installedGoVersion.startsWith("go version go" + version)
|
||||
}
|
||||
|
||||
internal fun Prov.goVersion(): String? {
|
||||
val result = cmdNoEval("/usr/local/go/bin/go version")
|
||||
return if (!result.success) null else result.out
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.domaindrivenarchitecture.provs.desktop.infrastructure
|
||||
|
||||
import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerStartMode
|
||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall
|
||||
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
||||
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
|
||||
class GoKtTest {
|
||||
|
||||
@ContainerTest
|
||||
fun installGo() {
|
||||
// given
|
||||
val container = defaultTestContainer()
|
||||
// when
|
||||
val res01 = container.installGo()
|
||||
val res02 = container.installGo()
|
||||
// then
|
||||
assertTrue(res01.success)
|
||||
assertTrue(res02.success)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue