diff --git a/build.gradle.kts b/build.gradle.kts index 8974f2a..89e6fc6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -82,6 +82,7 @@ subprojects { set("dockerRegistry", it.getOrDefault("DOCKER_REGISTRY", project.properties["docker.registry"])) set("octopusGithubDockerRegistry", it.getOrDefault("OCTOPUS_GITHUB_DOCKER_REGISTRY", project.properties["octopus.github.docker.registry"])) set("bitbucketLicense", it.getOrDefault("BITBUCKET_LICENSE", project.properties["bitbucket.license"])) + set("platform", it.getOrDefault("PLATFORM", project.properties["platform"])) } } diff --git a/ft/build.gradle.kts b/ft/build.gradle.kts index 5798e31..f7af4d7 100644 --- a/ft/build.gradle.kts +++ b/ft/build.gradle.kts @@ -1,5 +1,8 @@ +import java.util.concurrent.TimeUnit + plugins { id("com.avast.gradle.docker-compose") + base } fun String.getExt() = project.ext[this] as? String @@ -44,10 +47,37 @@ val ft by tasks.creating(Test::class) { testClassesDirs = sourceSets["ft"].output.classesDirs classpath = sourceSets["ft"].runtimeClasspath systemProperties["test.profile"] = "testProfile".getExt() + systemProperties["platform"] = "platform".getExt() + var propertyName = "bitbucket.host" + if (project.hasProperty(propertyName)) { + systemProperties[propertyName] = project.property(propertyName) as String + } + propertyName = "bitbucketHost" + if (project.hasProperty(propertyName)) { + systemProperties[propertyName] = project.property(propertyName) as String + } + propertyName = "gitlabHost" + if (project.hasProperty(propertyName)) { + systemProperties[propertyName] = project.property(propertyName) as String + } + propertyName = "giteaUrl" + if (project.hasProperty(propertyName)) { + systemProperties[propertyName] = project.property(propertyName) as String + } + propertyName = "bitbucketUrl" + if (project.hasProperty(propertyName)) { + systemProperties[propertyName] = project.property(propertyName) as String + } + propertyName = "gitlabUrl" + if (project.hasProperty(propertyName)) { + systemProperties[propertyName] = project.property(propertyName) as String + } + propertyName = "helmRelase" + if (project.hasProperty(propertyName)) { + systemProperties[propertyName] = project.property(propertyName) as String + } } -dockerCompose.isRequiredBy(ft) - tasks["composeUp"].doLast { if ("testProfile".getExt() == "gitea") { logger.info("Create test-admin in Gitea") @@ -65,10 +95,6 @@ tasks["composeUp"].doLast { } } -tasks.named("composeUp") { - dependsOn(":vcs-facade:dockerBuildImage") -} - idea.module { scopes["PROVIDED"]?.get("plus")?.add(configurations["ftImplementation"]) } @@ -80,3 +106,71 @@ dependencies { ftImplementation("org.junit.jupiter:junit-jupiter-engine") ftImplementation("org.junit.jupiter:junit-jupiter-params") } + +tasks.register("uninstallHelm") { + doLast { + val result = exec { + commandLine("helm", "uninstall", "vcs-facade", "--namespace", "test-env") + } + if (result.exitValue != 0) { + throw GradleException("Helm uninstall failed with exit code ${result.exitValue}") + } + } +} + +val helmNamespace: String? by project +val helmRelease: String? by project +val clusterDomain: String? by project +val localDomain: String? by project + +tasks.register("deployHelm") { + + if (helmRelease == null) { + throw GradleException("Helm release name is not set") + } + if (helmNamespace == null) { + throw GradleException("Helm namespace is not set") + } + if (clusterDomain == null) { + throw GradleException("Cluster domain is not set") + } + if (localDomain == null) { + throw GradleException("Local domain is not set") + } + + val bitbucketLicense: String by project + val vcsHost: String by project + + setWorkingDir("./deploy") + commandLine("helm", "upgrade", "--wait" + , "--install", helmRelease, "chart" + , "--namespace", helmNamespace + , "--set", "bitbucket.license=$bitbucketLicense" + , "--set", "vcs-facade.image.tag=${project.version}" + , "--set", "bitbucket.host=${vcsHost}" + , "--set", "clusterDomain=${clusterDomain}" + , "--set", "localDomain=${localDomain}" + ) + doLast { + val execResult = executionResult.get() + if (execResult.exitValue != 0) { + val errorOutput = standardOutput.toString() + throw GradleException("Helm deploy failed with exit code ${execResult.exitValue} and the following error:\\n$errorOutput") + } + } +} + +println("Profile: " + "testProfile".getExt()) + +if ("platform".getExt() == "okd") { + println("Platform is OKD") + tasks.named("ft") { + dependsOn("deployHelm") + finalizedBy("uninstallHelm") + } +} else { + dockerCompose.isRequiredBy(ft) + tasks.named("composeUp") { + dependsOn(":vcs-facade:dockerBuildImage") + } +}