Skip to content

Commit

Permalink
Add a task to run helm
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonophore committed May 27, 2024
1 parent ad5c505 commit ac90e44
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 6 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
}
}

Expand Down
106 changes: 100 additions & 6 deletions ft/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -65,10 +95,6 @@ tasks["composeUp"].doLast {
}
}

tasks.named("composeUp") {
dependsOn(":vcs-facade:dockerBuildImage")
}

idea.module {
scopes["PROVIDED"]?.get("plus")?.add(configurations["ftImplementation"])
}
Expand All @@ -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<Exec>("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")
}
}

0 comments on commit ac90e44

Please sign in to comment.