[PORTALNG] Support readonly file system in portal-ng-ui 93/137893/2
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Tue, 14 May 2024 13:03:54 +0000 (15:03 +0200)
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Tue, 14 May 2024 13:43:25 +0000 (15:43 +0200)
- mount files via configmaps to support readonly filesystems

Issue-ID: PORTALNG-101
Change-Id: Ia399d0230db4cc25f2d8e438a0e64a34f06b921f
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
kubernetes/portal-ng/components/portal-ng-ui/resources/assets/env.js [new file with mode: 0644]
kubernetes/portal-ng/components/portal-ng-ui/resources/assets/version.json [new file with mode: 0644]
kubernetes/portal-ng/components/portal-ng-ui/resources/default.conf [new file with mode: 0644]
kubernetes/portal-ng/components/portal-ng-ui/templates/configmap-env-js.yaml [new file with mode: 0644]
kubernetes/portal-ng/components/portal-ng-ui/templates/configmap-nginx-config.yaml [new file with mode: 0644]
kubernetes/portal-ng/components/portal-ng-ui/templates/configmap-version-json.yaml [new file with mode: 0644]
kubernetes/portal-ng/components/portal-ng-ui/templates/deployment.yaml

diff --git a/kubernetes/portal-ng/components/portal-ng-ui/resources/assets/env.js b/kubernetes/portal-ng/components/portal-ng-ui/resources/assets/env.js
new file mode 100644 (file)
index 0000000..2e21ca5
--- /dev/null
@@ -0,0 +1,11 @@
+(function(window) {
+  window["env"] = window["env"] || {};
+  window["env"]["keycloak"] = window["env"]["keycloak"] || {};
+
+  // Environment variables
+  window["env"]["customStyleEnabled"] = "{{ .Values.env.CUSTOM_STYLE_ENABLED }}";
+  window["env"]["keycloak"]["hostname"] = "{{ .Values.env.KEYCLOAK_HOSTNAME }}";
+  window["env"]["keycloak"]["realm"] = "{{ .Values.env.KEYCLOAK_REALM }}";
+  window['env']['keycloak']['clientId'] = '{{ .Values.env.KEYCLOAK_CLIENT_ID }}';
+  window["env"]["loggingEnabled"]= '{{ .Values.env.LOGGING_ENABLED }}';
+})(this);
diff --git a/kubernetes/portal-ng/components/portal-ng-ui/resources/assets/version.json b/kubernetes/portal-ng/components/portal-ng-ui/resources/assets/version.json
new file mode 100644 (file)
index 0000000..4f56a1f
--- /dev/null
@@ -0,0 +1,3 @@
+{
+    "number": "{{ .Values.image.tag | default .Chart.AppVersion }}"
+}
diff --git a/kubernetes/portal-ng/components/portal-ng-ui/resources/default.conf b/kubernetes/portal-ng/components/portal-ng-ui/resources/default.conf
new file mode 100644 (file)
index 0000000..d448e27
--- /dev/null
@@ -0,0 +1,48 @@
+resolver {{ .Values.env.CLUSTER_NAMESERVER_IP }};
+server {
+    listen       {{ .Values.env.NGINX_PORT }};
+    location / {
+        root /usr/share/nginx/html;
+        index index.html;
+        try_files $uri $uri/ /index.html =404;
+    }
+    location /api/ {
+        set                 $upstream           {{ .Values.env.BFF_URL }};
+        rewrite             /api/(.*) /$1 break;
+        add_header          Access-Control-Allow-Origin *;
+        proxy_pass                              $upstream/$1$is_args$args;
+        proxy_set_header    Host                $host;
+        proxy_set_header    X-Real-IP           $remote_addr;
+        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
+        proxy_set_header    X-Forwarded-Host    $host;
+        proxy_set_header    X-Forwarded-Server  $host;
+        proxy_set_header    X-Forwarded-Port    $server_port;
+        proxy_set_header    X-Forwarded-Proto   $scheme;
+        proxy_http_version 1.1;
+    }
+    location /auth/ {
+            set                 $upstream           {{ .Values.env.KEYCLOAK_INTERNAL_URL }};
+            rewrite             /auth/(.*) /$1 break;
+            add_header          Access-Control-Allow-Origin *;
+            proxy_pass                              $upstream/$1$is_args$args;
+            proxy_http_version                     1.1;
+            proxy_set_header    Host               $host;
+            proxy_set_header    X-Real-IP          $remote_addr;
+            proxy_set_header    X-Forwarded-For    $proxy_add_x_forwarded_for;
+            proxy_set_header    X-Forwarded-Host   $host;
+            proxy_set_header    X-Forwarded-Server $host;
+            proxy_set_header    X-Forwarded-Port   $server_port;
+            proxy_set_header    X-Forwarded-Proto  $scheme;
+    }
+}
+##
+# Gzip Settings
+##
+gzip on;
+gzip_vary on;
+gzip_proxied any;
+gzip_min_length 1100;
+gzip_comp_level 6;
+gzip_buffers 16 8k;
+gzip_http_version 1.1;
+gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
\ No newline at end of file
diff --git a/kubernetes/portal-ng/components/portal-ng-ui/templates/configmap-env-js.yaml b/kubernetes/portal-ng/components/portal-ng-ui/templates/configmap-env-js.yaml
new file mode 100644 (file)
index 0000000..e2244bd
--- /dev/null
@@ -0,0 +1,26 @@
+{{/*
+# Copyright © 2024 Deutsche Telekom
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+*/}}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "common.fullname" . }}-env-js
+  labels:
+    app: {{ include "common.name" . }}
+    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+    release: {{ include "common.release" . }}
+    heritage: {{ .Release.Service }}
+data:
+{{ tpl (.Files.Glob "resources/assets/env.js").AsConfig . | nindent 2 }}
diff --git a/kubernetes/portal-ng/components/portal-ng-ui/templates/configmap-nginx-config.yaml b/kubernetes/portal-ng/components/portal-ng-ui/templates/configmap-nginx-config.yaml
new file mode 100644 (file)
index 0000000..f8e560b
--- /dev/null
@@ -0,0 +1,26 @@
+{{/*
+# Copyright © 2024 Deutsche Telekom
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+*/}}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "common.fullname" . }}-nginx-config
+  labels:
+    app: {{ include "common.name" . }}
+    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+    release: {{ include "common.release" . }}
+    heritage: {{ .Release.Service }}
+data:
+{{ tpl (.Files.Glob "resources/default.conf").AsConfig . | nindent 2 }}
diff --git a/kubernetes/portal-ng/components/portal-ng-ui/templates/configmap-version-json.yaml b/kubernetes/portal-ng/components/portal-ng-ui/templates/configmap-version-json.yaml
new file mode 100644 (file)
index 0000000..79182a4
--- /dev/null
@@ -0,0 +1,26 @@
+{{/*
+# Copyright © 2024 Deutsche Telekom
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+*/}}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "common.fullname" . }}-version-json
+  labels:
+    app: {{ include "common.name" . }}
+    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+    release: {{ include "common.release" . }}
+    heritage: {{ .Release.Service }}
+data:
+{{ tpl (.Files.Glob "resources/assets/version.json").AsConfig . | nindent 2 }}
index 6a16384..4d467e0 100644 (file)
@@ -53,6 +53,22 @@ spec:
             mountPath: {{ .Values.nginx.tilesPath }}
             subPath: tiles.json
             readOnly: true
+          - name: nginx-config
+            mountPath: /etc/nginx/conf.d/default.conf
+            subPath: default.conf
+            readOnly: true
+          - name: env-js
+            mountPath: /usr/share/nginx/html/assets/env.js
+            subPath: env.js
+            readOnly: true
+          - name: version-json
+            mountPath: /usr/share/nginx/html/assets/version.json
+            subPath: version.json
+            readOnly: true
+          - name: tmp-volume
+            mountPath: /tmp
+          - name: nginx-cache-volume
+            mountPath: /var/cache/nginx
           resources: {{ include "common.resources" . | nindent 12 }}
         {{- with .Values.nodeSelector }}
         nodeSelector:
@@ -76,3 +92,15 @@ spec:
             items:
             - key: tiles.json
               path: tiles.json
+        - name: nginx-config
+          configMap:
+            name: {{ include "common.fullname" . }}-nginx-config
+        - name: env-js
+          configMap:
+            name: {{ include "common.fullname" . }}-env-js
+        - name: tmp-volume
+          emptyDir:
+            sizeLimit: 64Mi
+        - name: nginx-cache-volume
+          emptyDir:
+            sizeLimit: 64Mi