diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/Application.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/Application.kt index fd387b8..dac3677 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/Application.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/Application.kt @@ -1,7 +1,9 @@ package org.domaindrivenarchitecture.provs.server.application import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance -import org.domaindrivenarchitecture.provs.server.domain.provisionServer +import org.domaindrivenarchitecture.provs.server.domain.ServerType +import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand +import org.domaindrivenarchitecture.provs.server.domain.k3s.provisionK3s import kotlin.system.exitProcess @@ -21,6 +23,7 @@ fun main(args: Array) { exitProcess(1) } val prov = createProvInstance(cmd.target) - provisionServer(prov, cmd) - + when(cmd.serverType) { + ServerType.K3S -> prov.provisionK3s(cmd as K3sCliCommand) + } } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt index 716fb10..429f3da 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt @@ -7,6 +7,8 @@ import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand import org.domaindrivenarchitecture.provs.server.domain.ServerType +import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName +import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand class CliArgumentsParser(name: String) : CliTargetParser(name) { @@ -21,19 +23,32 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) { val module = modules.first { it.parsed } - return ServerCliCommand( - ServerType.valueOf(module.name.uppercase()), - TargetCliCommand( - target, - passwordInteractive - ), - module.configFileName - ) + val serverType = ServerType.valueOf(module.name.uppercase()) + when(serverType) { + ServerType.K3S -> return K3sCliCommand( + ServerType.valueOf(module.name.uppercase()), + TargetCliCommand( + target, + passwordInteractive + ), + module.configFileName, + module.applicationFileName + ) + else -> return ServerCliCommand( + ServerType.valueOf(module.name.uppercase()), + TargetCliCommand( + target, + passwordInteractive + ), + module.configFileName + ) + } } abstract class ServerSubcommand(name: String, description: String) : Subcommand(name, description) { var parsed: Boolean = false var configFileName: ConfigFileName? = null + var applicationFileName: ApplicationFileName? = null } class K3s : ServerSubcommand("k3s", "the k3s module") { @@ -43,9 +58,16 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) { "c", "the filename containing the yaml config for k3s" ) + val cliApplicationFileName by option( + ArgType.String, + "application-file", + "a", + "the filename containing the yaml a application deployment" + ) override fun execute() { super.configFileName = cliConfigFileName?.let { ConfigFileName(it) } + super.applicationFileName = cliApplicationFileName?.let { ApplicationFileName(it) } super.parsed = true } } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerCliCommand.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerCliCommand.kt index 8463c70..a02ea3f 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerCliCommand.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerCliCommand.kt @@ -7,7 +7,7 @@ enum class ServerType { K3D, K3S } -class ServerCliCommand( +open class ServerCliCommand( val serverType: ServerType, val target: TargetCliCommand, val configFileName: ConfigFileName?,) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerService.kt deleted file mode 100644 index a87f98e..0000000 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerService.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.domaindrivenarchitecture.provs.server.domain - -import org.domaindrivenarchitecture.provs.framework.core.Prov -import org.domaindrivenarchitecture.provs.server.domain.k3s.provisionK3s - -fun provisionServer(prov: Prov, cmd: ServerCliCommand) { - when(cmd.serverType) { - ServerType.K3S -> prov.provisionK3s(cmd.configFileName) - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/ApplicationFileName.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/ApplicationFileName.kt new file mode 100644 index 0000000..2b89348 --- /dev/null +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/ApplicationFileName.kt @@ -0,0 +1,9 @@ +package org.domaindrivenarchitecture.provs.server.domain.k3s + +import java.io.File + +data class ApplicationFileName(val fileName: String) { + fun fullqualified() : String { + return File(fileName).absoluteFile.absolutePath + } +} diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sCliCommand.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sCliCommand.kt new file mode 100644 index 0000000..9d78d86 --- /dev/null +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sCliCommand.kt @@ -0,0 +1,14 @@ +package org.domaindrivenarchitecture.provs.server.domain.k3s + +import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName +import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand +import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand +import org.domaindrivenarchitecture.provs.server.domain.ServerType + +class K3sCliCommand ( + serverType: ServerType, + target: TargetCliCommand, + configFileName: ConfigFileName?, + val applicationFileName: ApplicationFileName?) : + ServerCliCommand(serverType, target, configFileName) { +} \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt index 1ed4b7c..054a3be 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt @@ -9,8 +9,8 @@ import org.domaindrivenarchitecture.provs.server.infrastructure.k3s.getK3sConfig /** * Installs a k3s server. */ -fun Prov.provisionK3s(configFileName: ConfigFileName?) = task { - val k3sConfig: K3sConfig = getK3sConfig(configFileName) +fun Prov.provisionK3s(cli: K3sCliCommand) = task { + val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName) provisionNetwork(k3sConfig) if (k3sConfig.reprovision && testConfigExists()) { @@ -25,5 +25,8 @@ fun Prov.provisionK3s(configFileName: ConfigFileName?) = task { if (k3sConfig.echo == true) { provisionK3sEcho(k3sConfig.fqdn, k3sConfig.certmanager?.letsencryptEndpoint) } + if (cli.applicationFileName != null) { + provisionK3sApplication(cli.applicationFileName) + } ProvResult(true) } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt index 0224696..9ef43b2 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt @@ -5,6 +5,7 @@ import org.domaindrivenarchitecture.provs.framework.core.ProvResult import org.domaindrivenarchitecture.provs.framework.core.repeatTaskUntilSuccess import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.* import org.domaindrivenarchitecture.provs.server.domain.CertmanagerEndpoint +import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName import org.domaindrivenarchitecture.provs.server.domain.k3s.Certmanager import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sConfig @@ -174,3 +175,13 @@ fun Prov.provisionK3sEcho(fqdn: String, endpoint: CertmanagerEndpoint? = null) = ) cmd("kubectl apply -f $k3sEcho", sudo = true) } + +fun Prov.provisionK3sApplication(applicationFileName: ApplicationFileName) = task { + copyFileFromLocal( + fullyQualifiedLocalFilename = applicationFileName.fullqualified(), + fullyQualifiedFilename = k3sManualManifestsDir + "application.yaml", + posixFilePermission = "644", + sudo = true + ) + cmd("kubectl apply -f ${k3sManualManifestsDir}application.yaml", sudo = true) +}