From 5951597d50f7df8b976c0b520f792058bbdf2796 Mon Sep 17 00:00:00 2001 From: Matthew B <106352182+artntek@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:21:15 -0700 Subject: [PATCH 1/2] new nginx conf, plus tidying up config.js and adding hash for auto-restart on config changes --- helm/config/nginx-custom.conf | 30 +++++++++++++++++++++++++ helm/templates/config-js-configmap.yaml | 11 +++++++++ helm/templates/configmap.yaml | 6 ++--- helm/templates/deployment.yaml | 15 ++++++++++--- 4 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 helm/config/nginx-custom.conf create mode 100644 helm/templates/config-js-configmap.yaml diff --git a/helm/config/nginx-custom.conf b/helm/config/nginx-custom.conf new file mode 100644 index 000000000..a06f56de4 --- /dev/null +++ b/helm/config/nginx-custom.conf @@ -0,0 +1,30 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + + location {{ include "metacatui.clean.root" . }}/ { + root /usr/share/nginx/html; + index index.html index.htm; + + # See https://nceas.github.io/metacatui/install/apache + # + # + # 1. Serve index.html instead of a 404 error in the MetacatUI directory. + # Equivalent to Apache directive: FallbackResource /metacatui/index.html + # + try_files $uri $uri/ {{ include "metacatui.clean.root" . }}/index.html; + + # 2. Allow encoded slashes in URLs so encoded identifiers can be sent in MetacatUI URLs. + # Equivalent to Apache directive: AllowEncodedSlashes On + # (Apache allows encoded slashes to be used, and automatically decodes them) + # ** No config required; This is how NGINX behaves by default ** + } + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/helm/templates/config-js-configmap.yaml b/helm/templates/config-js-configmap.yaml new file mode 100644 index 000000000..69713440c --- /dev/null +++ b/helm/templates/config-js-configmap.yaml @@ -0,0 +1,11 @@ +{{- if .Values.appConfig.enabled }} +# Load only the "config/config.js" file into a ConfigMap +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-metacatui-config-js + labels: + {{- include "metacatui.labels" . | nindent 4 }} +data: + {{- (tpl (.Files.Glob "config/config.js").AsConfig . ) | nindent 2 }} +{{- end }} diff --git a/helm/templates/configmap.yaml b/helm/templates/configmap.yaml index 1ec251b47..efb2b31fa 100644 --- a/helm/templates/configmap.yaml +++ b/helm/templates/configmap.yaml @@ -1,11 +1,9 @@ -{{- if .Values.appConfig.enabled }} # Load all files in the "config" directory into a ConfigMap apiVersion: v1 kind: ConfigMap metadata: - name: {{ .Release.Name }}-metacatui-config-js + name: {{ .Release.Name }}-metacatui-config-all labels: {{- include "metacatui.labels" . | nindent 4 }} data: - {{- (tpl (.Files.Glob "config/config.js").AsConfig . ) | nindent 2 }} -{{- end }} + {{- (tpl (.Files.Glob "config/*").AsConfig . ) | nindent 2 }} diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index b9736c9e5..ef8b0bac6 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -13,10 +13,12 @@ spec: {{- include "metacatui.selectorLabels" . | nindent 6 }} template: metadata: - {{- with .Values.podAnnotations }} annotations: - {{- toYaml . | nindent 8 }} - {{- end }} + {{- $configfiles := (.Files.Glob "config/*").AsConfig }} + checksum/config: {{ printf "%s" $configfiles | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} labels: {{- include "metacatui.labels" . | nindent 8 }} {{- with .Values.podLabels }} @@ -136,11 +138,18 @@ spec: - name: {{ .Release.Name }}-mcui-config-js mountPath: {{ include "metacatui.root.mountpath" . }}/config/config.js subPath: config.js + - name: {{ .Release.Name }}-mcui-config-all + mountPath: /etc/nginx/conf.d/default.conf + subPath: nginx-custom.conf volumes: - name: {{ .Release.Name }}-mcui-config-js configMap: name: {{ .Release.Name }}-metacatui-config-js defaultMode: 0644 + - name: {{ .Release.Name }}-mcui-config-all + configMap: + name: {{ .Release.Name }}-metacatui-config-all + defaultMode: 0644 - name: {{ .Release.Name }}-mcui-source-files {{- if eq $source "pvc" }} persistentVolumeClaim: From 38a1d8c36fbff1d236202cbab2def4715ae5d120 Mon Sep 17 00:00:00 2001 From: Matthew B <106352182+artntek@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:02:08 -0700 Subject: [PATCH 2/2] clean up and add default_server annotation --- helm/config/nginx-custom.conf | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/helm/config/nginx-custom.conf b/helm/config/nginx-custom.conf index a06f56de4..a7a6de260 100644 --- a/helm/config/nginx-custom.conf +++ b/helm/config/nginx-custom.conf @@ -1,7 +1,11 @@ +## This file contains custom configuration for nginx +## See https://nginx.org/en/docs/http/request_processing.html +## It will override any existing, matching config in /etc/nginx/nginx.conf +## server { - listen 80; + listen 80 default_server; listen [::]:80; - server_name localhost; + server_name _; location {{ include "metacatui.clean.root" . }}/ { root /usr/share/nginx/html; @@ -13,18 +17,11 @@ server { # 1. Serve index.html instead of a 404 error in the MetacatUI directory. # Equivalent to Apache directive: FallbackResource /metacatui/index.html # - try_files $uri $uri/ {{ include "metacatui.clean.root" . }}/index.html; + try_files $uri $uri/ {{ include "metacatui.clean.root" . }}/index.html; # 2. Allow encoded slashes in URLs so encoded identifiers can be sent in MetacatUI URLs. # Equivalent to Apache directive: AllowEncodedSlashes On # (Apache allows encoded slashes to be used, and automatically decodes them) # ** No config required; This is how NGINX behaves by default ** } - - # redirect server error pages to the static page /50x.html - # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } }