diff --git a/build.gradle.kts b/build.gradle.kts index e6da829..80e1a79 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -134,6 +134,7 @@ subprojects { set( "clusterDomain", clusterDomain) set("localDomain", it.getOrDefault("LOCAL_DOMAIN", project.properties["localDomain"])) set("bitbucketHost", "$helmRelease-bitbucket-route-$helmNamespace.$clusterDomain") + set("giteaHost", "$helmRelease-gitea-route-$helmNamespace.$clusterDomain") } } diff --git a/deploy/.DS_Store b/deploy/.DS_Store new file mode 100644 index 0000000..d532c9a Binary files /dev/null and b/deploy/.DS_Store differ diff --git a/deploy/build.gradle.kts b/deploy/build.gradle.kts index c3dadd1..0f7b6b5 100644 --- a/deploy/build.gradle.kts +++ b/deploy/build.gradle.kts @@ -5,6 +5,7 @@ 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? +var giteaHost: String? = project.ext["giteaHost"] as String? val dockerRegistry: String? = project.ext["dockerRegistry"] as String? tasks.register("uninstallHelm") { @@ -41,7 +42,11 @@ tasks.register("deployHelm") { if (localDomain == null) { throw GradleException("Local domain is not set") } + if (testProfile == null) { + throw GradleException("Test profile is not set") + } + println("Profile: $testProfile") println("Release: $helmRelease") val bitbucketLicense: String by project @@ -52,10 +57,12 @@ tasks.register("deployHelm") { , "--set", "bitbucket.license=$bitbucketLicense" , "--set", "vcsFacade.image.version=${project.version}" , "--set", "bitbucket.host=${bitbucketHost}" + , "--set", "gitea.host=${giteaHost}" , "--set", "clusterDomain=${clusterDomain}" , "--set", "localDomain=${localDomain}" , "--set", "dockerRegistry=$dockerRegistry" , "--set", "platform=openshift" + , "--set", "profile=$testProfile" ) doLast { val execResult = executionResult.get() diff --git a/deploy/chart/files/application-gitea.yml b/deploy/chart/files/application-gitea.yml new file mode 100644 index 0000000..2173172 --- /dev/null +++ b/deploy/chart/files/application-gitea.yml @@ -0,0 +1,31 @@ +vcs-facade: + vcs: + bitbucket: + enabled: false + gitea: + host: http://{{ .Values.gitea.host | default "gitea:3000" }} + username: test-admin + password: test-admin + health-check: + repo: ssh://git@gitea:3000:test-data/vcs-facade-healthcheck.git + root-commit: 9320183f5d5f5868fdb82b36e3abd6f9d1424114 + last-release: 321d4908aef10bafa1488f9b053270acc29f3d78 + expected-commits: 9320183f5d5f5868fdb82b36e3abd6f9d1424114,00cc61dd4c3eca64d12e6beceff1a40a436962f5 + index: + webhook-secret: b59dd966-2445-4c84-b631-49502427477e + scan: + delay: 5000 + gitlab: + enabled: false + opensearch: + host: {{ template "opensearch.fullname" . }}-service.{{ .Release.Namespace }}.{{ .Values.localDomain }} + ssl: false + username: admin + password: admin + index: + suffix: ft + +logging: + level: + org.opensearch: DEBUG + org.octopusden.octopus.vcsfacade: TRACE diff --git a/deploy/chart/templates/_helpers.tpl b/deploy/chart/templates/_helpers.tpl index 5b9e94b..2b538ce 100644 --- a/deploy/chart/templates/_helpers.tpl +++ b/deploy/chart/templates/_helpers.tpl @@ -69,62 +69,9 @@ Create the name of the service account to use {{- end }} {{- end }} -{{/* -Create a test-component fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "test-component.fullname" -}} -{{- if .Values.vcsFacade.fullnameOverride }} -{{- .Values.vcsFacade.fullnameOverride | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- $name := default .Chart.Name .Values.vcsFacade.nameOverride }} -{{- if contains $name .Release.Name }} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- printf "test-component-%s" .Release.Name | trunc 63 | trimSuffix "-" }} -{{- end }} -{{- end }} -{{- end }} - -{{/* -Create a components-registry fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "components-registry.fullname" -}} -{{- if .Values.componentsRegisty.fullnameOverride }} -{{- .Values.componentsRegisty.fullnameOverride | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- $name := default .Chart.Name .Values.componentsRegisty.nameOverride }} -{{- if contains $name .Release.Name }} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- printf "components-registy-%s" .Release.Name | trunc 63 | trimSuffix "-" }} -{{- end }} -{{- end }} -{{- end }} - - -{{/* -Components-registry labels -*/}} -{{- define "components-registry.labels" -}} -helm.sh/chart: {{ include "chart-test.chart" . }} -{{ include "chart-test.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} - {{- define "gitea.fullname" -}} {{- if .Values.gitea.fullnameOverride }} -{{- .Values.gitea.fullnameOverride | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- $name := default .Chart.Name .Values.gitea.nameOverride }} -{{- if contains $name .Release.Name }} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- printf "gitea-%s" .Release.Name | trunc 63 | trimSuffix "-" }} -{{- end }} +{{- printf "%s-%s" .Release.Name .Values.gitea.fullnameOverride }} {{- end }} {{- end }} @@ -145,3 +92,9 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{- printf "%s-%s" .Release.Name .Values.vcsFacade.fullnameOverride }} {{- end }} {{- end }} + +{{- define "opensearch.fullname" -}} +{{- if .Values.opensearch.fullnameOverride }} +{{- printf "%s-%s" .Release.Name .Values.opensearch.fullnameOverride }} +{{- end }} +{{- end }} diff --git a/deploy/chart/templates/bitbucket-db/deployment.yaml b/deploy/chart/templates/bitbucket-db/deployment.yaml index 6b2c7f4..4fbd2c5 100644 --- a/deploy/chart/templates/bitbucket-db/deployment.yaml +++ b/deploy/chart/templates/bitbucket-db/deployment.yaml @@ -1,3 +1,4 @@ +{{- if eq .Values.profile "bitbucket" }} apiVersion: apps/v1 kind: Deployment metadata: @@ -21,9 +22,6 @@ spec: ports: - name: http containerPort: 5432 - {{- if eq .Values.platform "podman" }} - hostPort: 5432 - {{- end }} protocol: TCP env: {{- range $key, $value := .Values.bitbucketDb.environment }} @@ -55,4 +53,5 @@ spec: - ReadWriteOnce resources: requests: - storage: 5Gi \ No newline at end of file + storage: 5Gi +{{- end }} diff --git a/deploy/chart/templates/bitbucket-db/service.yaml b/deploy/chart/templates/bitbucket-db/service.yaml index ae6f80c..43f8554 100644 --- a/deploy/chart/templates/bitbucket-db/service.yaml +++ b/deploy/chart/templates/bitbucket-db/service.yaml @@ -1,3 +1,4 @@ +{{- if eq .Values.profile "bitbucket" }} apiVersion: v1 kind: Service metadata: @@ -14,3 +15,4 @@ spec: name: http selector: app.kubernetes.io/name: {{ include "bitbucketDb.fullname" . }} +{{- end }} diff --git a/deploy/chart/templates/bitbucket/deployment.yaml b/deploy/chart/templates/bitbucket/deployment.yaml index dca9b3a..7c0f04a 100644 --- a/deploy/chart/templates/bitbucket/deployment.yaml +++ b/deploy/chart/templates/bitbucket/deployment.yaml @@ -1,3 +1,4 @@ +{{- if eq .Values.profile "bitbucket" }} apiVersion: apps/v1 kind: Deployment metadata: @@ -14,22 +15,16 @@ spec: app.kubernetes.io/name: {{ include "bitbucket.fullname" . }} spec: containers: - - name: vcs-facade-ft-bitbucket + - name: {{ include "bitbucket.fullname" . }} securityContext: {} image: {{ .Values.dockerRegistry }}/atlassian/bitbucket-server:{{ .Values.bitbucket.image.version }} imagePullPolicy: IfNotPresent ports: - name: ssh containerPort: 7999 - {{- if eq .Values.platform "podman" }} - hostPort: 7999 - {{- end }} protocol: TCP - name: http containerPort: 7990 - {{- if eq .Values.platform "podman" }} - hostPort: 7990 - {{- end }} protocol: TCP env: {{- range $key, $value := .Values.bitbucket.environment }} @@ -77,14 +72,8 @@ spec: mountPath: /var/atlassian/application-data/bitbucket volumes: - name: {{ .Release.Name }}-bitbucket-volume - {{- if eq .Values.platform "podman" }} - hostPath: - path: {{ .Values.bitbucket.path }} - type: Directory - {{ else }} persistentVolumeClaim: claimName: {{ .Release.Name }}-bitbucket-volume - {{- end }} --- kind: PersistentVolumeClaim apiVersion: v1 @@ -95,4 +84,5 @@ spec: - ReadWriteOnce resources: requests: - storage: 5Gi \ No newline at end of file + storage: 5Gi +{{- end }} \ No newline at end of file diff --git a/deploy/chart/templates/bitbucket/route.yaml b/deploy/chart/templates/bitbucket/route.yaml index e337ed4..9465ca1 100644 --- a/deploy/chart/templates/bitbucket/route.yaml +++ b/deploy/chart/templates/bitbucket/route.yaml @@ -1,3 +1,4 @@ +{{- if eq .Values.profile "bitbucket" }} apiVersion: route.openshift.io/v1 kind: Route metadata: @@ -7,4 +8,5 @@ spec: targetPort: 7990 to: kind: Service - name: {{ template "bitbucket.fullname" . }} \ No newline at end of file + name: {{ template "bitbucket.fullname" . }} +{{- end }} \ No newline at end of file diff --git a/deploy/chart/templates/bitbucket/secret.yaml b/deploy/chart/templates/bitbucket/secret.yaml index dce6630..ed73caf 100644 --- a/deploy/chart/templates/bitbucket/secret.yaml +++ b/deploy/chart/templates/bitbucket/secret.yaml @@ -1,7 +1,9 @@ +{{- if eq .Values.profile "bitbucket" }} apiVersion: v1 kind: Secret metadata: name: {{ template "bitbucket.fullname" . }}-bitbucket-license-secret type: Opaque data: - token: {{ .Values.bitbucket.license | b64enc | quote }} \ No newline at end of file + token: {{ .Values.bitbucket.license | b64enc | quote }} +{{- end }} \ No newline at end of file diff --git a/deploy/chart/templates/bitbucket/service.yaml b/deploy/chart/templates/bitbucket/service.yaml index c745e93..3c4ebdd 100644 --- a/deploy/chart/templates/bitbucket/service.yaml +++ b/deploy/chart/templates/bitbucket/service.yaml @@ -1,3 +1,4 @@ +{{- if eq .Values.profile "bitbucket" }} apiVersion: v1 kind: Service metadata: @@ -18,3 +19,4 @@ spec: name: http selector: app.kubernetes.io/name: {{ include "bitbucket.fullname" . }} +{{- end }} diff --git a/deploy/chart/templates/gitea/configmap.yaml b/deploy/chart/templates/gitea/configmap.yaml new file mode 100644 index 0000000..fa43deb --- /dev/null +++ b/deploy/chart/templates/gitea/configmap.yaml @@ -0,0 +1,12 @@ +{{- if eq .Values.profile "gitea" }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "gitea.fullname" . }}-config + namespace: {{ .Release.Namespace | quote }} +data: + add_admin.sh: | + #!/bin/bash + until gitea admin user list &> /dev/null; do sleep 5; done + gitea admin user create --username=test-admin --password=test-admin --email=admin@example.com --admin=true +{{- end }} diff --git a/deploy/chart/templates/gitea/deployment.yaml b/deploy/chart/templates/gitea/deployment.yaml new file mode 100644 index 0000000..bab6f7a --- /dev/null +++ b/deploy/chart/templates/gitea/deployment.yaml @@ -0,0 +1,91 @@ +{{- if eq .Values.profile "gitea" }} +############################### +# Gitea PVC +############################### +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "gitea.fullname" . }}-pvc + namespace: {{ .Release.Namespace | quote }} +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + +############################### +# Deplyoment Gitea +############################### +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "gitea.fullname" . }} + namespace: {{ .Release.Namespace | quote }} + labels: + app: {{ include "gitea.fullname" . }} +spec: + replicas: 1 + template: + metadata: + name: gitea + labels: + app: gitea + app.kubernetes.io/name: {{ include "gitea.fullname" . }} + spec: + containers: + - name: gitea + image: {{ .Values.dockerRegistry }}/gitea/gitea:{{ .Values.gitea.image.version }} + imagePullPolicy: Always + lifecycle: + postStart: + exec: + command: ["/bin/sh", "/conf/add_admin.sh"] + env: + - name: GITEA__ADMIN_USER + value: test-admin + - name: GITEA__ADMIN_PASSWORD + value: test-admin + - name: GITEA__security__INSTALL_LOCK + value: "true" + - name: GITEA__webhook__ALLOWED_HOST_LIST + value: "*" + volumeMounts: + - mountPath: "/etc/gitea" + name: gitea-data + subPath: var-etc-gitea + - mountPath: "/var/lib/gitea" + name: gitea-data + subPath: var-lib-gitea + - name: gitea-conf-add-script + mountPath: /conf + ports: + - containerPort: 22 + name: ssh + protocol: TCP + - containerPort: 3000 + name: http + protocol: TCP + readinessProbe: + httpGet: + path: /user/login + port: 3000 + scheme: HTTP + imagePullSecrets: + - name: artifactory-okd-puller + restartPolicy: Always + volumes: + - name: gitea-data + persistentVolumeClaim: + claimName: {{ include "gitea.fullname" . }}-pvc + - name: gitea-conf-add-script + configMap: + name: {{ include "gitea.fullname" . }}-config + items: + - key: add_admin.sh + path: add_admin.sh + selector: + matchLabels: + app: gitea +{{- end }} diff --git a/deploy/chart/templates/gitea/route.yaml b/deploy/chart/templates/gitea/route.yaml new file mode 100644 index 0000000..cb54683 --- /dev/null +++ b/deploy/chart/templates/gitea/route.yaml @@ -0,0 +1,15 @@ +{{- if eq .Values.profile "gitea" }} +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: {{ include "gitea.fullname" . }}-route + namespace: {{ .Release.Namespace | quote }} + labels: + app: {{ include "gitea.fullname" . }}-route +spec: + port: + targetPort: 3000 + to: + kind: Service + name: {{ include "gitea.fullname" . }}-service +{{- end }} \ No newline at end of file diff --git a/deploy/chart/templates/gitea/service.yaml b/deploy/chart/templates/gitea/service.yaml new file mode 100644 index 0000000..49ca84e --- /dev/null +++ b/deploy/chart/templates/gitea/service.yaml @@ -0,0 +1,32 @@ +{{- if eq .Values.profile "gitea" }} +apiVersion: v1 +kind: Service +metadata: + name: {{ include "gitea.fullname" . }}-service + namespace: {{ .Release.Namespace | quote }} +spec: + selector: + app.kubernetes.io/name: {{ include "gitea.fullname" . }} + ports: + - name: {{ include "gitea.fullname" . }}-http + port: 3000 + targetPort: 3000 + +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ include "gitea.fullname" . }}-ssh + namespace: {{ .Release.Namespace | quote }} + labels: + app: {{ include "gitea.fullname" . }}-ssh +spec: + selector: + app: {{ include "gitea.fullname" . }} + ports: + - name: {{ include "gitea.fullname" . }}-ssh + port: 22 + targetPort: 22 + nodePort: 30022 + type: NodePort +{{- end }} \ No newline at end of file diff --git a/deploy/chart/templates/opensearch/deployment.yaml b/deploy/chart/templates/opensearch/deployment.yaml new file mode 100644 index 0000000..5173f97 --- /dev/null +++ b/deploy/chart/templates/opensearch/deployment.yaml @@ -0,0 +1,49 @@ +{{- if eq .Values.profile "gitea" }} +kind: Deployment +apiVersion: apps/v1 +metadata: + name: {{ include "opensearch.fullname" . }} + namespace: {{ .Release.Namespace | quote }} + labels: + app: opensearch + app.kubernetes.io/component: opensearch + app.kubernetes.io/instance: opensearch + app.kubernetes.io/name: {{ include "opensearch.fullname" . }} +spec: + replicas: 1 + selector: + matchLabels: + app: {{ include "opensearch.fullname" . }} + template: + metadata: + labels: + app: {{ include "opensearch.fullname" . }} + app.kubernetes.io/name: {{ include "opensearch.fullname" . }} + spec: + containers: + - name: {{ include "opensearch.fullname" . }} + ports: + - name: http2 + containerPort: 9600 + protocol: TCP + - name: http + containerPort: 9200 + protocol: TCP + readinessProbe: + httpGet: + path: / + port: 9200 + initialDelaySeconds: 10 + periodSeconds: 10 + env: + - name: LOGGING_LEVEL_ORG_OPENSEARCH + value: DEBUG + - name: OPENSEARCH_PASSWORD + value: "admin" + - name: discovery.type + value: "single-node" + - name: plugins.security.disabled + value: "true" + image: >- + {{ .Values.dockerRegistry }}/bitnami/opensearch:{{ .Values.opensearch.image.version }} +{{- end }} \ No newline at end of file diff --git a/deploy/chart/templates/opensearch/route.yaml b/deploy/chart/templates/opensearch/route.yaml new file mode 100644 index 0000000..ad21785 --- /dev/null +++ b/deploy/chart/templates/opensearch/route.yaml @@ -0,0 +1,15 @@ +{{- if eq .Values.profile "gitea" }} +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: {{ include "opensearch.fullname" . }}-route + namespace: {{ .Release.Namespace | quote }} + labels: + app: {{ include "opensearch.fullname" . }}-route +spec: + port: + targetPort: 9200 + to: + kind: Service + name: {{ include "opensearch.fullname" . }}-service +{{- end }} \ No newline at end of file diff --git a/deploy/chart/templates/opensearch/service.yaml b/deploy/chart/templates/opensearch/service.yaml new file mode 100644 index 0000000..e50a290 --- /dev/null +++ b/deploy/chart/templates/opensearch/service.yaml @@ -0,0 +1,18 @@ +{{- if eq .Values.profile "gitea" }} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "opensearch.fullname" . }}-service + namespace: {{ .Release.Namespace | quote }} + labels: + {{- include "chart-test.labels" . | nindent 4 }} +spec: + type: {{ .Values.opensearch.service.type }} + ports: + - port: 9200 + targetPort: 9200 + protocol: TCP + name: http + selector: + app.kubernetes.io/name: {{ include "opensearch.fullname" . }} +{{- end }} diff --git a/deploy/chart/templates/vcs-facade/configmap.yaml b/deploy/chart/templates/vcs-facade/configmap.yaml index 927c437..f79d9d2 100644 --- a/deploy/chart/templates/vcs-facade/configmap.yaml +++ b/deploy/chart/templates/vcs-facade/configmap.yaml @@ -1,4 +1,3 @@ -{{- if eq .Values.platform "openshift" }} apiVersion: v1 kind: ConfigMap metadata: @@ -7,8 +6,12 @@ metadata: data: bootstrap-ft.yml: | {{ tpl (.Files.Get "files/bootstrap-ft.yml") . | indent 4 }} +{{- if eq .Values.profile "bitbucket" }} application-bitbucket.yml: | {{ tpl (.Files.Get "files/application-bitbucket.yml") . | indent 4 }} +{{ else }} + application-gitea.yml: | +{{ tpl (.Files.Get "files/application-gitea.yml") . | indent 4 }} +{{- end }} application-ft.yml: | {{ tpl (.Files.Get "files/application-ft.yml") . | indent 4 }} -{{- end }} diff --git a/deploy/chart/templates/vcs-facade/deployment.yaml b/deploy/chart/templates/vcs-facade/deployment.yaml index ed4c853..b783915 100644 --- a/deploy/chart/templates/vcs-facade/deployment.yaml +++ b/deploy/chart/templates/vcs-facade/deployment.yaml @@ -25,49 +25,32 @@ spec: ports: - name: http containerPort: 8080 - {{- if eq .Values.platform "podman" }} - hostPort: 8080 - {{- end }} protocol: TCP env: + - name: SPRING_PROFILES_ACTIVE + value: ft,{{ .Values.profile }} {{- range $key, $value := .Values.vcsFacade.environment }} - name: {{ $key }} value: {{ $value | quote }} {{- end }} resources: {} + {{- if eq .Values.profile "gitea" }} + readinessProbe: + exec: + command: + - sh + - -c + - > + curl -s -o /dev/null -w "%{http_code}" http://{{ include "gitea.fullname" . }}-route-{{ .Release.Namespace }}.{{ .Values.clusterDomain }}/user/login | grep -q "200" + initialDelaySeconds: 5 + periodSeconds: 10 + {{- end }} volumeMounts: -{{- 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 -{{- end }} volumes: -{{- if eq .Values.platform "podman" }} - - hostPath: - path: {{ .Values.vcsFacade.configFile.applicationBitbucket.path }} - type: File - name: {{ .Release.Namespace }}-application-bitbucket-config - - hostPath: - path: {{ .Values.vcsFacade.configFile.applicationFt.path }} - type: File - name: {{ .Release.Namespace }}-application-ft-config - - hostPath: - path: {{ .Values.vcsFacade.configFile.bootstrapFt.path }} - type: File - name: {{ .Release.Namespace }}-bootstrap-ft-config -{{ else }} - name: {{ .Release.Namespace }}-application-config configMap: name: {{ include "vcsFacade.fullname" . }}-conf defaultMode: 420 -{{- end }} diff --git a/deploy/chart/values.yaml b/deploy/chart/values.yaml index fbb07ac..899fdfc 100644 --- a/deploy/chart/values.yaml +++ b/deploy/chart/values.yaml @@ -2,17 +2,25 @@ # This is a YAML-formatted file. platform: openshift -profile: gitea +profile: bitbucket clusterDomain: localDomain: svc.cluster.local dockerRegistry: docker.io/library +opensearch: + fullnameOverride: opensearch + image: + version: 2.14.0-debian-12-r1 + service: + type: ClusterIP + gitea: - fullnameOverride: vcs-facade-ft-gitea + host: gitea:3000 + fullnameOverride: gitea image: - version: 1.21.10 + version: 1.21.10-rootless bitbucket: host: bitbucket:7990 @@ -62,7 +70,6 @@ vcsFacade: version: 3.0.5 environment: SPRING_CONFIG_ADDITIONAL_LOCATION: /app/config/ - SPRING_PROFILES_ACTIVE: ft,bitbucket JAVA_TOOL_OPTIONS: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" service: type: ClusterIP diff --git a/ft/build.gradle.kts b/ft/build.gradle.kts index 6f9a3fe..4a869e7 100644 --- a/ft/build.gradle.kts +++ b/ft/build.gradle.kts @@ -43,6 +43,7 @@ val helmRelease = "helmRelease".getExt() val clusterDomain = "clusterDomain".getExt() val localDomain = "localDomain".getExt() val bitbucketHost = "bitbucketHost".getExt() +val giteaHost = "giteaHost".getExt() val platform = "platform".getExt() val ft by tasks.creating(Test::class) { @@ -57,6 +58,12 @@ val ft by tasks.creating(Test::class) { systemProperties["bitbucketExternalHost"] = bitbucketHost systemProperties["bitbucketUrl"] = "http://$bitbucketHost" systemProperties["vcs-facade.vcs.bitbucket.host"] = "http://$bitbucketHost" + + systemProperties["giteaHost"] = giteaHost + systemProperties["giteaExternalHost"] = giteaHost + systemProperties["giteaUrl"] = "http://$giteaHost" + systemProperties["vcs-facade.vcs.gitea.host"] = "http://$giteaHost" + systemProperties["vcsFacadeUrl"] = "http://$helmRelease-vcs-facade-route-$helmNamespace.$clusterDomain" } } diff --git a/ft/src/ft/kotlin/org/octopusden/octopus/vcsfacade/VcsFacadeFunctionalTestGitea.kt b/ft/src/ft/kotlin/org/octopusden/octopus/vcsfacade/VcsFacadeFunctionalTestGitea.kt index 07a8c66..4ba88e3 100644 --- a/ft/src/ft/kotlin/org/octopusden/octopus/vcsfacade/VcsFacadeFunctionalTestGitea.kt +++ b/ft/src/ft/kotlin/org/octopusden/octopus/vcsfacade/VcsFacadeFunctionalTestGitea.kt @@ -23,6 +23,10 @@ class VcsFacadeFunctionalTestGitea : BaseVcsFacadeFunctionalTest( Configuration.model.gitea.externalHost ) ) { + + protected val variables = mapOf( + "url" to Configuration.model.vcsFacadeUrl, + ) @BeforeAll fun beforeAllVcsFacadeFunctionalTestGitea() { val url = URI("http://${Configuration.model.gitea.host}/api/v1/repos/$GROUP/$REPOSITORY_2/hooks").toURL() @@ -36,7 +40,7 @@ class VcsFacadeFunctionalTestGitea : BaseVcsFacadeFunctionalTest( setRequestProperty("Accept", "application/json") setDoOutput(true) outputStream.use { - it.write(WEBHOOK_CREATION_REQUEST.toByteArray()) + it.write(FileTemplateProcessor(WEBHOOK_CREATION_REQUEST.toByteArray()).processTemplate(variables).toByteArray()) } if (getResponseCode() / 100 != 2) { throw RuntimeException("Unable to create webhook for '$GROUP:$REPOSITORY_2'") @@ -81,7 +85,7 @@ class VcsFacadeFunctionalTestGitea : BaseVcsFacadeFunctionalTest( "branch_filter": "*", "config": { "content_type": "json", - "url": "http://vcs-facade:8080/rest/api/1/indexer/gitea/webhook", + "url": "{{url}}/rest/api/1/indexer/gitea/webhook", "secret": "b59dd966-2445-4c84-b631-49502427477e" }, "events": [ diff --git a/test-common/src/main/resources/test-properties.yaml b/ft/src/ft/resources/test-properties.yaml similarity index 100% rename from test-common/src/main/resources/test-properties.yaml rename to ft/src/ft/resources/test-properties.yaml diff --git a/server/build.gradle.kts b/server/build.gradle.kts index eefdfa5..d1bdc4a 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -88,23 +88,28 @@ docker { } } -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 giteaHost = "giteaHost".getExt() +val platform = "platform".getExt() tasks.withType { systemProperties["spring.profiles.active"] = "ut,${"testProfile".getExt()}" - if ("platform".getExt() == "okd") { + if (platform == "okd") { extensions.extraProperties["bitbucketHost"] = bitbucketHost systemProperties["bitbucketHost"] = bitbucketHost systemProperties["bitbucketUrl"] = "http://$bitbucketHost" systemProperties["vcs-facade.vcs.bitbucket.host"] = "http://$bitbucketHost" + systemProperties["vcsFacadeUrl"] = "http://$helmRelease-vcs-facade-route-$helmNamespace.$clusterDomain" + + systemProperties["giteaHost"] = giteaHost + systemProperties["giteaExternalHost"] = giteaHost + systemProperties["giteaUrl"] = "http://$giteaHost" + systemProperties["vcs-facade.vcs.gitea.host"] = "http://$giteaHost" } else { dependsOn("composeUp") } @@ -139,7 +144,7 @@ configurations.all { exclude("commons-logging", "commons-logging") } -if ("platform".getExt() == "okd") { +if (platform == "okd") { println("Platform is OKD") tasks.named("test") { diff --git a/test-common/src/main/kotlin/org/octopusden/octopus/vcsfacade/FileTemplateProcessor.kt b/test-common/src/main/kotlin/org/octopusden/octopus/vcsfacade/FileTemplateProcessor.kt index c7f6270..c2c3d72 100644 --- a/test-common/src/main/kotlin/org/octopusden/octopus/vcsfacade/FileTemplateProcessor.kt +++ b/test-common/src/main/kotlin/org/octopusden/octopus/vcsfacade/FileTemplateProcessor.kt @@ -1,6 +1,7 @@ package org.octopusden.octopus.vcsfacade import java.io.BufferedReader +import java.io.ByteArrayInputStream import java.io.IOException import java.io.InputStreamReader @@ -10,16 +11,27 @@ import java.io.InputStreamReader * * @property fileName The name of the template file in the resources folder. */ -class FileTemplateProcessor(private val fileName: String) { +class FileTemplateProcessor { + + private val content: String + + constructor(fileName: String) { + this.content = readFile(fileName) + } + + constructor(byteArray: ByteArray) { + this.content = readByteArray(byteArray) + } /** * Reads the content of the file from the resources folder. * + * @param fileName The name of the file to read. * @return The content of the file as a String. * @throws IOException If an I/O error occurs reading from the file or a malformed or unmappable byte sequence is read. */ @Throws(IOException::class) - private fun readFile(): String { + private fun readFile(fileName: String): String { val inputStream = javaClass.classLoader.getResourceAsStream(fileName) ?: throw IOException("File not found: $fileName") @@ -28,6 +40,22 @@ class FileTemplateProcessor(private val fileName: String) { } } + /** + * Reads the content from a byte array. + * + * @param byteArray The byte array to read. + * @return The content of the byte array as a String. + * @throws IOException If an I/O error occurs reading from the byte array. + */ + @Throws(IOException::class) + private fun readByteArray(byteArray: ByteArray): String { + ByteArrayInputStream(byteArray).use { inputStream -> + BufferedReader(InputStreamReader(inputStream)).use { reader -> + return reader.readText() + } + } + } + /** * Replaces variables in the content with specified values. * @@ -52,7 +80,6 @@ class FileTemplateProcessor(private val fileName: String) { */ @Throws(IOException::class) fun processTemplate(variables: Map): String { - val content = readFile() return bindVariables(content, variables) }