Skip to content

Commit

Permalink
Add gitea
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonophore committed Jun 21, 2024
1 parent 54f65ea commit b1793f2
Show file tree
Hide file tree
Showing 29 changed files with 453 additions and 129 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
Binary file added deploy/.DS_Store
Binary file not shown.
54 changes: 53 additions & 1 deletion deploy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -27,8 +28,52 @@ tasks.register("uninstallHelm") {
println("Profile: " + testProfile)
println("Platform: " + if (platform == "okd") "OKD" else "DOCKER-COMPOSE")

tasks.register<Exec>("deployHelm") {
tasks.register<Exec>("deployHelmFt") {
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")
}
if (testProfile == null) {
throw GradleException("Test profile is not set")
}

println("Profile: $testProfile")
println("Release: $helmRelease")

val bitbucketLicense: String by project

commandLine("helm", "upgrade", "--wait"
, "--install", helmRelease, "chart"
, "--namespace", helmNamespace
, "--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"
, "--set", "mode=ft"
)
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")
}
}
}

tasks.register<Exec>("deployHelmTest") {
if (helmRelease == null) {
throw GradleException("Helm release name is not set")
}
Expand All @@ -41,7 +86,11 @@ tasks.register<Exec>("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
Expand All @@ -52,10 +101,13 @@ tasks.register<Exec>("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"
, "--set", "mode=ut"
)
doLast {
val execResult = executionResult.get()
Expand Down
31 changes: 31 additions & 0 deletions deploy/chart/files/application-gitea.yml
Original file line number Diff line number Diff line change
@@ -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
61 changes: 7 additions & 54 deletions deploy/chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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 }}
7 changes: 3 additions & 4 deletions deploy/chart/templates/bitbucket-db/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if eq .Values.profile "bitbucket" }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -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 }}
Expand Down Expand Up @@ -55,4 +53,5 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storage: 5Gi
{{- end }}
2 changes: 2 additions & 0 deletions deploy/chart/templates/bitbucket-db/service.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if eq .Values.profile "bitbucket" }}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -14,3 +15,4 @@ spec:
name: http
selector:
app.kubernetes.io/name: {{ include "bitbucketDb.fullname" . }}
{{- end }}
18 changes: 4 additions & 14 deletions deploy/chart/templates/bitbucket/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if eq .Values.profile "bitbucket" }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -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 }}
Expand Down Expand Up @@ -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
Expand All @@ -95,4 +84,5 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storage: 5Gi
{{- end }}
4 changes: 3 additions & 1 deletion deploy/chart/templates/bitbucket/route.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if eq .Values.profile "bitbucket" }}
apiVersion: route.openshift.io/v1
kind: Route
metadata:
Expand All @@ -7,4 +8,5 @@ spec:
targetPort: 7990
to:
kind: Service
name: {{ template "bitbucket.fullname" . }}
name: {{ template "bitbucket.fullname" . }}
{{- end }}
4 changes: 3 additions & 1 deletion deploy/chart/templates/bitbucket/secret.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
token: {{ .Values.bitbucket.license | b64enc | quote }}
{{- end }}
2 changes: 2 additions & 0 deletions deploy/chart/templates/bitbucket/service.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if eq .Values.profile "bitbucket" }}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -18,3 +19,4 @@ spec:
name: http
selector:
app.kubernetes.io/name: {{ include "bitbucket.fullname" . }}
{{- end }}
12 changes: 12 additions & 0 deletions deploy/chart/templates/gitea/configmap.yaml
Original file line number Diff line number Diff line change
@@ -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 protected] --admin=true
{{- end }}
Loading

0 comments on commit b1793f2

Please sign in to comment.