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 d485fd6..cee8b10 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt @@ -49,9 +49,33 @@ fun Prov.installKubectlAndTools(): ProvResult = task { } } + task("installKubeconform") { + + installKubeconform() + } installDevopsScripts() } +fun Prov.installKubeconform() = task { + // check for latest stable release on: https://github.com/yannh/kubeconform/releases + val version = "0.6.4" + val installationPath = "/usr/local/bin/" + val tmpDir = "~/tmp" + val filename = "kubeconform-linux-amd64" + val packedFilename = "$filename.tar.gz" + + if ( !chk("kubeconform -v") || "v$version" != cmd("kubeconform -v").out?.trim() ) { + downloadFromURL( + "https://github.com/yannh/kubeconform/releases/download/v$version/$packedFilename", + path = tmpDir, + sha256sum = "2b4ebeaa4d5ac4843cf8f7b7e66a8874252b6b71bc7cbfc4ef1cbf85acec7c07" + ) + cmd("sudo tar -xzf $packedFilename -C $installationPath", tmpDir) + } else { + ProvResult(true, out = "Kubeconform $version already installed") + } +} + fun Prov.installKubectl(): ProvResult = task { // see https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/ diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Kubeconform.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Kubeconform.kt deleted file mode 100644 index 1810e3a..0000000 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Kubeconform.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.domaindrivenarchitecture.provs.desktop.infrastructure - -import org.domaindrivenarchitecture.provs.framework.core.Prov -import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDirs -import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL - - -fun Prov.installKubeconform() = task { - // check for latest stable release on: https://github.com/yannh/kubeconform/releases - val version = "0.6.4" - val installationPath = "~/bin/" - val filename = "kubeconform-linux-amd64" - val packedFilename = "$filename.tar.gz" - - createDirs(installationPath) - - downloadFromURL( - "https://github.com/yannh/kubeconform/releases/download/v$version/$packedFilename", - path = installationPath, - sha256sum = "2b4ebeaa4d5ac4843cf8f7b7e66a8874252b6b71bc7cbfc4ef1cbf85acec7c07" - ) - cmd("tar -xvf $packedFilename", installationPath) - cmd("chmod +x kubeconform", installationPath) -} - - 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 12ffb16..b18acfe 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt @@ -6,6 +6,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.creat import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDirs import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileContainsText import org.domaindrivenarchitecture.provs.test.defaultTestContainer +import org.domaindrivenarchitecture.provs.test.tags.ContainerTest import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Disabled @@ -48,4 +49,17 @@ internal class DevOpsKtTest { // then assertTrue(res.success) } + + @ContainerTest + fun installKubeconform() { + // given + val prov = defaultTestContainer() + + // when + val res = prov.installKubeconform() + + // then + assertTrue(res.success) + assertTrue(prov.checkFile("/usr/local/bin/kubeconform")) + } } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/KubeconformKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/KubeconformKtTest.kt deleted file mode 100644 index 9366457..0000000 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/KubeconformKtTest.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 KubeconformKtTest { - - @ContainerTest - fun installKubeconform() { - // given - val prov = defaultTestContainer() - - // when - val res = prov.installKubeconform() - - // then - assertTrue(res.success) - assertTrue(prov.checkFile("bin/kubeconform")) - } -} \ No newline at end of file