From 8c629e9a4164100de2cdf12b8cec55ae37394112 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maik=20Scha=CC=88fer?= <maik.schaefer@open-xchange.com>
Date: Tue, 11 Apr 2023 11:55:01 +0200
Subject: [PATCH] [CI] Add preview deployment

---
 .gitlab/autodeploy/values.yaml                |  37 ----
 .gitlab/preview/.helmignore                   |  23 +++
 .gitlab/preview/Chart.lock                    |   9 +
 .gitlab/preview/Chart.yaml                    |  36 ++++
 .gitlab/preview/templates/NOTES.txt           |   7 +
 .../templates}/kubernetes-resources.yaml      |  34 +++-
 .gitlab/preview/values-template.yaml          |  28 +++
 .gitlab/preview/values.yaml                   | 161 ++++++++++++++++++
 8 files changed, 295 insertions(+), 40 deletions(-)
 delete mode 100644 .gitlab/autodeploy/values.yaml
 create mode 100644 .gitlab/preview/.helmignore
 create mode 100644 .gitlab/preview/Chart.lock
 create mode 100644 .gitlab/preview/Chart.yaml
 create mode 100644 .gitlab/preview/templates/NOTES.txt
 rename .gitlab/{autodeploy => preview/templates}/kubernetes-resources.yaml (82%)
 create mode 100644 .gitlab/preview/values-template.yaml
 create mode 100644 .gitlab/preview/values.yaml

diff --git a/.gitlab/autodeploy/values.yaml b/.gitlab/autodeploy/values.yaml
deleted file mode 100644
index 7521805..0000000
--- a/.gitlab/autodeploy/values.yaml
+++ /dev/null
@@ -1,37 +0,0 @@
-replicaCount: 1
-
-containerPort: 8080
-
-baseUrls:
-  - http://main-core-ui.main-e2e-stack.svc.cluster.local
-
-redis:
-  enabled: true
-  host: main-redis-master.main-e2e-stack.svc.cluster.local
-  prefix: ${CI_COMMIT_REF_SLUG}-${OX_COMPONENT}
-
-ingress:
-  enabled: false
-
-defaultRegistry: ""
-
-image:
-  registry: ""
-  repository: ${CI_REGISTRY_IMAGE}
-  pullPolicy: Always
-  tag: ${TAG_NAME}
-
-imagePullSecrets:
-  - name: gitlab-registry-credentials
-
-extras:
-  monitoring:
-    enabled: true
-
-resources:
-  limits:
-    cpu: 1
-    memory: 196Mi
-  requests:
-    cpu: 100m
-    memory: 196Mi
diff --git a/.gitlab/preview/.helmignore b/.gitlab/preview/.helmignore
new file mode 100644
index 0000000..0e8a0eb
--- /dev/null
+++ b/.gitlab/preview/.helmignore
@@ -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/
diff --git a/.gitlab/preview/Chart.lock b/.gitlab/preview/Chart.lock
new file mode 100644
index 0000000..54f20f7
--- /dev/null
+++ b/.gitlab/preview/Chart.lock
@@ -0,0 +1,9 @@
+dependencies:
+- name: appsuite
+  repository: oci://registry.open-xchange.com/appsuite-core-internal/charts
+  version: 8.13.203
+- name: core-ui
+  repository: file://../../helm/core-ui
+  version: 2.12.1
+digest: sha256:5bfe47d7c20c9570fa20f61941f0a5c162bbb4c5da666f7c1d3e178d5fe15e29
+generated: "2023-03-22T14:19:50.405478+01:00"
diff --git a/.gitlab/preview/Chart.yaml b/.gitlab/preview/Chart.yaml
new file mode 100644
index 0000000..286a220
--- /dev/null
+++ b/.gitlab/preview/Chart.yaml
@@ -0,0 +1,36 @@
+apiVersion: v2
+name: preview
+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: "1.16.0"
+
+dependencies:
+  - name: appsuite
+    version: ~8.13.0
+    repository: "oci://registry.open-xchange.com/appsuite-core-internal/charts"
+  - name: core-ui-middleware
+    version: ">=1.0.0-0"
+    repository: "file://../../helm/core-ui-middleware"
+  - name: redis
+    version: ^17.9.0
+    repository: https://charts.bitnami.com/bitnami
+    condition: redis.enabled, global.redis.enabled
diff --git a/.gitlab/preview/templates/NOTES.txt b/.gitlab/preview/templates/NOTES.txt
new file mode 100644
index 0000000..f549c71
--- /dev/null
+++ b/.gitlab/preview/templates/NOTES.txt
@@ -0,0 +1,7 @@
+Thank you for trävelling with CI Building Blocks!
+
++=========================================={{ regexReplaceAll "." .Values.host "=" }}=+
+|                                          {{ regexReplaceAll "." .Values.host " " }} |
+| Your preview app is now ready at https://{{ .Values.host }} |
+|                                  ~~~~~~~~­{{ regexReplaceAll "." .Values.host "~" }} |
++=========================================={{ regexReplaceAll "." .Values.host "=" }}=+
diff --git a/.gitlab/autodeploy/kubernetes-resources.yaml b/.gitlab/preview/templates/kubernetes-resources.yaml
similarity index 82%
rename from .gitlab/autodeploy/kubernetes-resources.yaml
rename to .gitlab/preview/templates/kubernetes-resources.yaml
index 74f8ea4..503ebd2 100644
--- a/.gitlab/autodeploy/kubernetes-resources.yaml
+++ b/.gitlab/preview/templates/kubernetes-resources.yaml
@@ -18,8 +18,26 @@ spec:
     - mesh
     - istio-system/default-gateway
   hosts:
-    - "${PREVIEW_APP_NAME}.dev.oxui.de"
+    - "{{ .Values.host }}"
   http:
+    - match:
+        - uri:
+            prefix: /help-documents
+      name: office-user-guide
+      route:
+        - destination:
+            host: preview-app-office-user-guide
+            port:
+              number: 80
+    - match:
+        - uri:
+            prefix: /help
+      name: user-guide
+      route:
+        - destination:
+            host: preview-app-core-user-guide
+            port:
+              number: 80
     - match:
         - uri:
             prefix: /api/oxguard/
@@ -135,7 +153,7 @@ spec:
         uri: /
       route:
         - destination:
-            host: ${OX_COMPONENT}
+            host: preview-app-core-ui-middleware
             port:
               number: 80
     - match:
@@ -144,10 +162,20 @@ spec:
       name: ui-middleware
       route:
         - destination:
-            host: ${OX_COMPONENT}
+            host: preview-app-core-ui-middleware
             port:
               number: 80
 ---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: preview-core-ui-middleware
+data:
+  config.yaml: |
+    baseUrls:
+      - http://preview-app-core-ui
+      - http://preview-app-office-web
+---
 apiVersion: monitoring.coreos.com/v1
 kind: ServiceMonitor
 metadata:
diff --git a/.gitlab/preview/values-template.yaml b/.gitlab/preview/values-template.yaml
new file mode 100644
index 0000000..673e369
--- /dev/null
+++ b/.gitlab/preview/values-template.yaml
@@ -0,0 +1,28 @@
+core-ui-middleware:
+  image:
+    repository: ${CI_REGISTRY_IMAGE}
+    tag: ${TAG_NAME}
+  redis:
+    enabled: true
+    host: preview-app-redis-master.${PREVIEW_APP_NAME}.svc.cluster.local
+    prefix: ${CI_COMMIT_REF_SLUG}-${OX_COMPONENT}
+host: ${PREVIEW_APP_NAME}.dev.oxui.de
+
+appsuite:
+  core-ui:
+    podAnnotations:
+      commit-ref: "${CI_COMMIT_SHORT_SHA}"
+    deploymentAnnotations:
+      commit-ref: "${CI_COMMIT_SHORT_SHA}"
+    redis:
+      prefix: ${CI_COMMIT_REF_SLUG}-${OX_COMPONENT}
+  core-guidedtours:
+    podAnnotations:
+      commit-ref: "${CI_COMMIT_SHORT_SHA}"
+    deploymentAnnotations:
+      commit-ref: "${CI_COMMIT_SHORT_SHA}"
+  office-web:
+    podAnnotations:
+      commit-ref: "${CI_COMMIT_SHORT_SHA}"
+    deploymentAnnotations:
+      commit-ref: "${CI_COMMIT_SHORT_SHA}"
diff --git a/.gitlab/preview/values.yaml b/.gitlab/preview/values.yaml
new file mode 100644
index 0000000..628d8ec
--- /dev/null
+++ b/.gitlab/preview/values.yaml
@@ -0,0 +1,161 @@
+global:
+  appsuite:
+    appRoot: "/"
+
+core-ui-middleware:
+  replicaCount: 1
+  existingConfigMap: preview-core-ui-middleware
+  containerPort: 8080
+
+  ingress:
+    enabled: false
+
+  defaultRegistry: ""
+
+  image:
+    registry: ""
+    pullPolicy: Always
+
+  imagePullSecrets:
+    - name: gitlab-registry-credentials
+
+  extras:
+    monitoring:
+      enabled: true
+
+  resources:
+    limits:
+      cpu: 1
+      memory: 196Mi
+    requests:
+      cpu: 100m
+      memory: 196Mi
+
+redis:
+  enabled: true
+  architecture: standalone
+  auth:
+    enabled: false
+  master:
+    persistence:
+      enabled: false
+  replica:
+    persistence:
+      enabled: false
+  metrics:
+    enabled: true
+  resources:
+    requests:
+      memory: 128Mi
+      cpu: 100m
+    limits:
+      memory: 256Mi
+      cpu: 250m
+
+appsuite:
+  core-ui-middleware:
+    enabled: false
+  core-ui:
+    image:
+      registry: registry.gitlab.open-xchange.com
+      repository: frontend/ui
+      tag: latest
+      pullPolicy: Always
+  core-user-guide:
+    image:
+        registry: registry.gitlab.open-xchange.com
+        repository: frontend/user-guide
+        tag: latest
+        pullPolicy: Always
+
+    ingress:
+      enabled: false
+    podAnnotations:
+      sidecar.istio.io/inject: "false"
+      sidecar.istio.io/proxyCPU: "100m"
+      sidecar.istio.io/proxyCPULimit: "200m"
+      sidecar.istio.io/proxyMemory: "128Mi"
+      sidecar.istio.io/proxyMemoryLimit: "128Mi"
+    resources:
+      requests:
+        cpu: "5m"
+        memory: "32Mi"
+      limits:
+        memory: "32Mi"
+
+  office-web:
+    enabled: true
+    image:
+      registry: registry.dev.oxui.de
+      repository: appsuite-core/office-web
+      tag: latest
+      pullPolicy: Always
+    ingress:
+      enabled: false
+    podAnnotations:
+      sidecar.istio.io/inject: "false"
+      sidecar.istio.io/proxyCPU: "100m"
+      sidecar.istio.io/proxyCPULimit: "200m"
+      sidecar.istio.io/proxyMemory: "128Mi"
+      sidecar.istio.io/proxyMemoryLimit: "128Mi"
+    resources:
+      requests:
+        cpu: "5m"
+        memory: "32Mi"
+      limits:
+        memory: "32Mi"
+
+  office-user-guide:
+    enabled: true
+    image:
+      registry: registry.gitlab.open-xchange.com
+      repository: documents/user-guide
+      tag: latest
+      pullPolicy: Always
+    ingress:
+      enabled: false
+    podAnnotations:
+      sidecar.istio.io/inject: "false"
+      sidecar.istio.io/proxyCPU: "100m"
+      sidecar.istio.io/proxyCPULimit: "200m"
+      sidecar.istio.io/proxyMemory: "128Mi"
+      sidecar.istio.io/proxyMemoryLimit: "128Mi"
+    resources:
+      requests:
+        cpu: "5m"
+        memory: "32Mi"
+      limits:
+        memory: "32Mi"
+
+  core-guidedtours:
+    enabled: false
+
+  guard-ui:
+    enabled: false
+
+  core-documents-collaboration:
+    enabled: false
+
+  core-documentconverter:
+    enabled: false
+
+  core-imageconverter:
+    enabled: false
+
+  core-spellcheck:
+    enabled: false
+
+  core-mw:
+    enabled: false
+
+  plugins-ui:
+    enabled: false
+
+  cloud-plugins-ui:
+    enabled: false
+
+  core-drive-help:
+    enabled: false
+
+  drive-client-windows-ox:
+    enabled: false
-- 
GitLab