Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonophore committed Jun 9, 2024
1 parent a05208f commit 0a54e9e
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 95 deletions.
13 changes: 11 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,17 @@ 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"]))
set("helmRelease", sanitizeHelmReleaseName(it.getOrDefault("HELM_RELEASE", project.properties["helmRelease"]) as String?))

val platform = it.getOrDefault("PLATFORM", project.properties["platform"])
set("platform", platform)
val helmRelease = sanitizeHelmReleaseName(it.getOrDefault("HELM_RELEASE", project.properties["helmRelease"]) as String?)
set("helmRelease", helmRelease)
val helmNamespace = it.getOrDefault("HELM_NAMESPACE", project.properties["helmNamespace"])
set("helmNamespace", helmNamespace)
val clusterDomain = it.getOrDefault("CLUSTER_DOMAIN", project.properties["clusterDomain"])
set( "clusterDomain", clusterDomain)
set("localDomain", it.getOrDefault("LOCAL_DOMAIN", project.properties["localDomain"]))
set("bitbucketHost", "$helmRelease-bitbucket-route-$helmNamespace.$clusterDomain")
}
}

Expand Down
File renamed without changes.
69 changes: 69 additions & 0 deletions deploy/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
val testProfile: String? = project.ext["testProfile"] as String?
val platform: String? = project.ext["platform"] as String?
val helmNamespace: String? = project.ext["helmNamespace"] as String?
val helmRelease: String? = project.ext["helmRelease"] as String?
val clusterDomain: String? = project.ext["clusterDomain"] as String?
val localDomain: String? = project.ext["localDomain"] as String?
var bitbucketHost: String? = project.ext["bitbucketHost"] as String?
val dockerRegistry: String? = project.ext["dockerRegistry"] as String?

tasks.register("uninstallHelm") {
doLast {
if (helmRelease == null) {
throw GradleException("Helm release name is not set")
}
if (helmNamespace == null) {
throw GradleException("Helm namespace is not set")
}
val result = exec {
commandLine("helm", "uninstall", helmRelease, "--namespace", helmNamespace)
}
if (result.exitValue != 0) {
throw GradleException("Helm uninstall failed with exit code ${result.exitValue}")
}
}
}

println("Profile: " + testProfile)
println("Platform: " + if (platform == "okd") "OKD" else "DOCKER-COMPOSE")

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")
}

println("Release: $helmRelease")

val bitbucketLicense: String by project

//setWorkingDir("./deploy")
println("helm upgrade --wait --install $helmRelease chart --namespace $helmNamespace --set bitbucket.license=$bitbucketLicense --set vcs-facade.image.tag=${project.version} --set bitbucket.host=${bitbucketHost} --set clusterDomain=${clusterDomain} --set localDomain=${localDomain} --set dockerRegistry=$dockerRegistry --set platform=okd")
commandLine("helm", "upgrade", "--wait"
, "--install", helmRelease, "chart"
, "--namespace", helmNamespace
, "--set", "bitbucket.license=$bitbucketLicense"
, "--set", "vcs-facade.image.tag=${project.version}"
, "--set", "bitbucket.host=${bitbucketHost}"
, "--set", "clusterDomain=${clusterDomain}"
, "--set", "localDomain=${localDomain}"
, "--set", "dockerRegistry=$dockerRegistry"
, "--set", "platform=openshift"
)
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")
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@ spec:
mountPath: /var/atlassian/application-data/bitbucket
volumes:
- name: {{ .Release.Namespace }}-bitbucket-volume
{{- if eq .Values.platform "podman" }}
hostPath:
path: {{ .Values.bitbucket.path }}
type: Directory
{{ else }}
persistentVolumeClaim:
claimName: {{ .Release.Namespace }}-bitbucket-volume
{{- end }}
---
kind: PersistentVolumeClaim
apiVersion: v1
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,38 @@ spec:
{{- end }}
resources: {}
volumeMounts:
- name: application-config
{{- if eq .Values.platform "podman" }}
- name: {{ .Release.Namespace }}-application-bitbucket-config
mountPath: /app/config/application-bitbucket.yml
readOnly: true
- name: {{ .Release.Namespace }}-application-ft-config
mountPath: /app/config/application-ft.yml
readOnly: true
- name: {{ .Release.Namespace }}-bootstrap-ft-config
mountPath: /app/config/bootstrap-ft.yml
readOnly: true
{{ else }}
- name: {{ .Release.Namespace }}-application-config
mountPath: /app/config
readOnly: true
{{- if eq .Values.platform "podman" }}
{{- end }}
volumes:
{{- if eq .Values.platform "podman" }}
- hostPath:
path: {{ .Values.vcsFacade.configFile.applicationBitbucket.path }}
type: File
name: application-bitbucket-config
name: {{ .Release.Namespace }}-application-bitbucket-config
- hostPath:
path: {{ .Values.vcsFacade.configFile.applicationFt.path }}
type: File
name: application-ft-config
name: {{ .Release.Namespace }}-application-ft-config
- hostPath:
path: {{ .Values.vcsFacade.configFile.bootstrapFt.path }}
type: File
name: bootstrap-ft-config
{{- end }}
{{- if eq .Values.platform "openshift" }}
volumes:
- name: application-config
name: {{ .Release.Namespace }}-bootstrap-ft-config
{{ else }}
- name: {{ .Release.Namespace }}-application-config
configMap:
name: {{ include "vcsFacade.fullname" . }}-conf
defaultMode: 420
{{- end }}
{{- end }}
7 changes: 4 additions & 3 deletions ft/deploy/chart/values.yaml → deploy/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bitbucket:
type: ClusterIP
port: 7990
targetPort: 7990
path: /Users/ozonophore/Projects/octopus-vcs-facade/ft/deploy/bitbucket

bitbucketDb:
fullnameOverride: bitbucket-db
Expand Down Expand Up @@ -68,9 +69,9 @@ vcsFacade:
targetPort: 8080
configFile:
applicationBitbucket:
path: ../../files/application-bitbucket.yml
path: /Users/ozonophore/Projects/octopus-vcs-facade/ft/deploy/chart/files/application-bitbucket.yml
applicationFt:
path: ../../files/application-ft.yml
path: /Users/ozonophore/Projects/octopus-vcs-facade/ft/deploy/chart/files/application-ft.yml
bootstrapFt:
path: ../../files/bootstrap-ft.yml
path: /Users/ozonophore/Projects/octopus-vcs-facade/ft/deploy/chart/files/bootstrap-ft.yml

87 changes: 9 additions & 78 deletions ft/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
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 @@ -41,14 +38,12 @@ ftImplementation.isCanBeResolved = true

configurations["ftRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get())

val helmNamespace: String? by project
val helmNamespace = "helmNamespace".getExt()
val helmRelease = "helmRelease".getExt()
val clusterDomain: String? by project
val localDomain: String? by project
var bitbucketHost: String? = null
if ("platform".getExt() == "okd") {
bitbucketHost = "$helmRelease-bitbucket-route-$helmNamespace.$clusterDomain"
}
val clusterDomain = "clusterDomain".getExt()
val localDomain = "localDomain".getExt()
val bitbucketHost = "bitbucketHost".getExt()
val platform = "platform".getExt()

val ft by tasks.creating(Test::class) {
group = "verification"
Expand All @@ -57,9 +52,7 @@ val ft by tasks.creating(Test::class) {
classpath = sourceSets["ft"].runtimeClasspath
systemProperties["test.profile"] = "testProfile".getExt()
systemProperties["platform"] = "platform".getExt()
if ("platform".getExt() == "okd") {

extensions.extraProperties["bitbucketHost"] = bitbucketHost
if (platform == "okd") {
systemProperties["bitbucketHost"] = bitbucketHost
systemProperties["bitbucketUrl"] = "http://$bitbucketHost"
systemProperties["vcs-facade.vcs.bitbucket.host"] = "http://$bitbucketHost"
Expand Down Expand Up @@ -97,72 +90,10 @@ dependencies {
ftImplementation("org.junit.jupiter:junit-jupiter-params")
}

tasks.register("uninstallHelm") {
doLast {
if (helmRelease == null) {
throw GradleException("Helm release name is not set")
}
if (helmNamespace == null) {
throw GradleException("Helm namespace is not set")
}
val result = exec {
commandLine("helm", "uninstall", helmRelease, "--namespace", helmNamespace)
}
if (result.exitValue != 0) {
throw GradleException("Helm uninstall failed with exit code ${result.exitValue}")
}
}
}

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")
}

println("Release: $helmRelease")

val bitbucketLicense: 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=${bitbucketHost}"
, "--set", "clusterDomain=${clusterDomain}"
, "--set", "localDomain=${localDomain}"
, "--set", "dockerRegistry=${"dockerRegistry".getExt()}"
, "--set", "platform=okd"
)
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())
println("Platform: " + "platform".getExt())

if ("platform".getExt() == "okd") {
println("Platform is OKD")

if (platform == "okd") {
tasks.named("ft") {
dependsOn("deployHelm")
finalizedBy("uninstallHelm")
dependsOn(":deploy:deployHelm")
finalizedBy(":deploy:uninstallHelm")
}
} else {
dockerCompose.isRequiredBy(ft)
Expand Down
4 changes: 2 additions & 2 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ if ("platform".getExt() == "okd") {
println("Platform is OKD")

tasks.named("test") {
dependsOn(":ft:deployHelm")
finalizedBy(":ft:uninstallHelm")
dependsOn(":deploy:deployHelm")
finalizedBy(":deploy:uninstallHelm")
}
} else {
dockerCompose.isRequiredBy(tasks["test"])
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ include(":test-common")
include(":server")
findProject(":server")?.name = "vcs-facade"
include(":ft")
include(":deploy")

0 comments on commit 0a54e9e

Please sign in to comment.