Skip to content

Commit

Permalink
Extract paramaters from the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonophore committed Jun 12, 2024
1 parent a1aa45a commit 54f65ea
Show file tree
Hide file tree
Showing 110 changed files with 4,652 additions and 3,526 deletions.
52 changes: 52 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,47 @@ nexusPublishing {
}
}

/**
* Sanitizes a Helm release name to ensure it adheres to Helm's naming conventions.
*
* Helm release names must:
* - Be no longer than 53 characters.
* - Contain only lowercase letters (`a-z`), digits (`0-9`), and hyphens (`-`).
* - Start with a letter.
* - End with a letter or digit.
*
* @param name The original release name to be sanitized.
* @return A sanitized release name that conforms to Helm's naming conventions.
*/
fun sanitizeHelmReleaseName(name: String?): String? {
if (name == null) {
return null
}

var sanitized = name.toLowerCase().replace(Regex("[^a-z0-9-]"), "-")

if (!sanitized.first().isLetter()) {
sanitized = "a$sanitized"
}

if (!sanitized.last().isLetterOrDigit()) {
sanitized = sanitized.dropLastWhile { !it.isLetterOrDigit() }
if (sanitized.isEmpty()) {
sanitized = "default-release"
}
}

if (sanitized.length > 53) {
sanitized = sanitized.take(53)
}

if (!sanitized.last().isLetterOrDigit()) {
sanitized = sanitized.dropLastWhile { !it.isLetterOrDigit() }
}

return sanitized
}

subprojects {
apply(plugin = "java")
apply(plugin = "idea")
Expand Down Expand Up @@ -82,6 +123,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"]))

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
91 changes: 91 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
### Required enveraments

- Helm
- OC (Openshift Client)

### OC login

```shell
oc login --token=<token> --server=<cluster-host>
```

### To show deployments

To view templates generated by Helm with the Bitbucket profile:

```shell
helm template chart --set bitbucket.license=<license> --set vcsFacade.image.version=<version>
```

To install the application in the <project> namespace:

```shell
helm upgrade --wait --install <helm_release> chart --namespace <project> --set bitbucket.license=<license> --set vcs-facade.image.tag=<version> --set clusterDomain=<cluster_domain> --set localDomain=<local_host> --set dockerRegistry=<dockerRegistry> --set platform=okd
```

To uninstall the application:

```shell
helm uninstall <helm_release> --namespace <project>
```

#### Parameters

- helm_release - Helm release name(This release is a specific deployment of that chart with a unique configuration, and it includes all the Kubernetes resources specified in the chart templates, such as deployments, services, and config maps. Helm releases allow you to manage, upgrade, and roll back your applications easily)
- project - Project namespace
- bitbucket.license - license token for BitBucket server
- dockerRegistry - Docker registry with images.
- cluster_domain - Cluster domain(the root domain used for all internal addresses within the cluster. It ensures predictable DNS names for inter-service communication.)
- local_host - Local host(typically refers to the default local domain suffix used for internal network addresses)

### To run from gradle

```shell
./gradlew deployHelm -Pdocker.registry=<docker_registry> -Pplatform=okd -PhelmRelease=<release_name> -PhelmNamespace=<project> -PlocalDomain=<local_domain> -PclusterDomain=<cluster_domain> -Ptest.profile=bitbucket -Pversion=<version> -Pbitbucket.license=<license>
```

```shell
./gradlew uninstallHelm -PhelmRelease=<release_name> -PhelmNamespace=<project>
```

### Create a project in OKD

1. To create a new project, you need to click the **Create Project** button in the dropdown menu, as shown in the image below.

![img1.png](img/img1.png)

2. Next, you need to create a **ServiceAccount** for access to the project. To do this, click the **Create ServiceAccount** button as shown in the image below.

![img2.png](img/img2.png)

3. In the ServiceAccount parameters, you need to specify a unique arbitrary name and the project name, as shown below.

```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: <service_account_name>
namespace: <project_name>
```

4. The created ServiceAccount will automatically create two sections in the Secrets section. One of them should have the type service-account-token, as shown in the picture. By entering this section, you will find a permanent token in the token field, which can be used to access OKD.

![img3.png](img/img3.png)

5. To assign roles, in the Project Access section, you need to add new access. In the Name field, specify the name of the ServiceAccount, and in the Role field, specify the role that will be assigned to this ServiceAccount.

![img4.png](img/img4.png)

#### Debugging

Get pod name:

```shell
oc get pods -n <project>
```

Then, forward the port:

```shell
oc port-forward <pod-name> 5005:5005
```
67 changes: 67 additions & 0 deletions deploy/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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

commandLine("helm", "upgrade", "--wait"
, "--install", helmRelease, "chart"
, "--namespace", helmNamespace
, "--set", "bitbucket.license=$bitbucketLicense"
, "--set", "vcsFacade.image.version=${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")
}
}
}
23 changes: 23 additions & 0 deletions deploy/chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions deploy/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: vcs-facade
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.0.1"
17 changes: 17 additions & 0 deletions deploy/chart/files/application-bitbucket.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
vcs-facade:
vcs:
bitbucket:
host: http://{{ .Values.bitbucket.host | default "bitbucket:7990" }}
username: admin
password: admin
health-check:
repo: ssh://git@bitbucket:7990/test-data/vcs-facade-healthcheck.git
root-commit: 9320183f5d5f5868fdb82b36e3abd6f9d1424114
last-release: 321d4908aef10bafa1488f9b053270acc29f3d78
expected-commits: 9320183f5d5f5868fdb82b36e3abd6f9d1424114,00cc61dd4c3eca64d12e6beceff1a40a436962f5
gitea:
enabled: false
gitlab:
enabled: false
opensearch:
enabled: false
4 changes: 4 additions & 0 deletions deploy/chart/files/application-ft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vcs-facade:
job:
fast-work-timout-secs: 0
retry-interval-secs: 1
4 changes: 4 additions & 0 deletions deploy/chart/files/bootstrap-ft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring:
cloud:
config:
enabled: false
Loading

0 comments on commit 54f65ea

Please sign in to comment.