From edda8943614874f39d224a2ed2eb8817aba253b2 Mon Sep 17 00:00:00 2001 From: Matthew B <106352182+artntek@users.noreply.github.com> Date: Mon, 3 Jun 2024 15:25:08 -0700 Subject: [PATCH] add configmap for config.js; git checkout static content --- helm/config/config.js | 28 ++++++++++++ helm/templates/configmap.yaml | 9 ++++ helm/templates/deployment.yaml | 52 +++++++++++++++++----- helm/values.yaml | 80 +++++++++++++++++++++++++++++----- 4 files changed, 147 insertions(+), 22 deletions(-) create mode 100644 helm/config/config.js create mode 100644 helm/templates/configmap.yaml diff --git a/helm/config/config.js b/helm/config/config.js new file mode 100644 index 000000000..19ba4ed47 --- /dev/null +++ b/helm/config/config.js @@ -0,0 +1,28 @@ +MetacatUI.AppConfig = { + root: {{ .Values.appConfig.root | quote }}, + theme: {{ .Values.appConfig.theme | quote }}, + baseUrl: {{ .Values.appConfig.baseUrl | quote }} + {{- $optionalStringValues := list + "d1CNBaseUrl" + "mapKey" + "mdqBaseUrl" + "dataoneSearchUrl" + "googleAnalyticsKey" + "bioportalAPIKey" + "cesiumToken" + -}} + {{- $optionalIntValues := list + "portalLimit" + -}} + {{- range $key, $value := .Values.appConfig }} + {{- if has $key $optionalStringValues }} + {{- (printf ",") }} + {{- (printf "%s: \"%s\"" $key (toString $value)) | nindent 6 }} + {{- else }} + {{- if has $key $optionalIntValues }} + {{- (printf ",") }} + {{- (printf "%s: %s" $key (toString $value)) | nindent 6 }} + {{- end }} + {{- end }} + {{- end }} +} diff --git a/helm/templates/configmap.yaml b/helm/templates/configmap.yaml new file mode 100644 index 000000000..55948e4d0 --- /dev/null +++ b/helm/templates/configmap.yaml @@ -0,0 +1,9 @@ +# Load all files in the "config" directory into a ConfigMap +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-metacatui-configjs + labels: + {{- include "metacatui.labels" . | nindent 4 }} +data: +{{ (tpl (.Files.Glob "config/*").AsConfig . ) | nindent 4 }} diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index 3154d3292..8002a4c4f 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -30,6 +30,19 @@ spec: serviceAccountName: {{ include "metacatui.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- if .Values.git.enabled }} + initContainers: + - name: git-clone + image: alpine/git + command: + - sh + - -c + - > + git clone -b {{ .Values.git.revision }} --depth 1 {{ .Values.git.repoUrl }} /metacatui + volumeMounts: + - name: {{ .Release.Name }}-mcui-static-files + mountPath: /metacatui + {{- end }} containers: - name: {{ .Chart.Name }} securityContext: @@ -40,24 +53,43 @@ spec: - name: http containerPort: {{ .Values.service.port }} protocol: TCP + {{- with .Values.livenessProbe }} livenessProbe: - httpGet: - path: / - port: http + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.readinessProbe }} readinessProbe: - httpGet: - path: / - port: http + {{- toYaml . | nindent 12 }} + {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.volumeMounts }} volumeMounts: + {{- if .Values.appConfig.enabled }} + - name: {{ .Release.Name }}-mcui-config-vol + mountPath: /usr/share/nginx/html/config/config.js + subPath: config.js + {{- end }} + - name: {{ .Release.Name }}-mcui-static-files + mountPath: "/usr/share/nginx/html" + subPath: "src" + {{- with .Values.volumeMounts }} {{- toYaml . | nindent 12 }} {{- end }} - {{- with .Values.volumes }} volumes: - {{- toYaml . | nindent 8 }} - {{- end }} + {{- if .Values.appConfig.enabled }} + - name: {{ .Release.Name }}-mcui-config-vol + configMap: + name: {{ .Release.Name }}-metacatui-configjs + defaultMode: 0644 + {{- end }} + {{- if .Values.git.enabled }} + - name: {{ .Release.Name }}-mcui-static-files + emptyDir: {} + {{- else }} + {{- with .Values.volumes }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- end }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/helm/values.yaml b/helm/values.yaml index 47ad6fce8..c005ab75c 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -4,6 +4,65 @@ replicaCount: 1 +## appConfig contains the MetacatUI.AppConfig settings that can be overridden. Uses a configMap to +## define MetacatUI.AppConfig, replacing the version of config/config.js found on the mounted drive. +## Note that changes to the configMap will not be read unless the pod is restarted, and changes to +## these values will not be reflected in the configMap unless you do a 'helm upgrade'. +## +appConfig: + ## appConfig.enabled Use a configMap to define MetacatUI.AppConfig, replacing the on-disk version + ## Typical use is "false" for development purposes, and "true" for more-permanent deployments + ## + enabled: true + + ## appConfig.root (required) The url root to be appended after the appConfig.baseUrl, below + ## + root: "/" + + ## appConfig.theme (required) Corresponds to the name of one of the directories in src/js/themes/ + ## + theme: "default" + + ## appConfig.baseUrl (required) the base url (typically defined by the ingress) + ## + baseUrl: "http://localhost:8080/" + + ## Optional configuration -- leave commented to use metacatui default values + ## +# d1CNBaseUrl: "https://cn-sandbox.test.dataone.org/cn" +# mapKey: "your-map-key-here" +# mdqBaseUrl: "https://localhost:8080:30443/quality" +# dataoneSearchUrl: "https://search-stage.test.dataone.org" +# portalLimit: 100 +# googleAnalyticsKey: "your-google-analytics-key-here" +# bioportalAPIKey: "your-bio-portal-api-key-here" +# cesiumToken: "your-cesium-token-here" + + +git: + ## git.enabled set 'true' to create an initContainer and do a git checkout of the metacatui files + ## NOTE: If you set git.enabled: 'false', then you will need to provide values for 'volumes' + ## that + enabled: true + + ## git.repoUrl the https url of the repo to be cloned + repoUrl: "https://github.com/NCEAS/metacatui.git" + + ## git.revision can be any string that makes sense after the command `git checkout`... - for + ## example: + ## git checkout tags/2.29.0 => revision: "tags/2.29.0" + ## git checkout develop => revision: "develop" + ## + revision: "main" + +## volumes Uncomment and provide values if you want to use a pre-configured PVC instead of doing a +## git checkout +#volumes: +# ## volumes.name substitute your own release name, but do NOT change the '-mcui-static-files' part +# - name: -mcui-static-files +# persistentVolumeClaim: +# claimName: + image: repository: nginx pullPolicy: IfNotPresent @@ -14,6 +73,15 @@ imagePullSecrets: [] nameOverride: "" fullnameOverride: "" +#livenessProbe: +# httpGet: +# path: / +# port: http +#readinessProbe: +# httpGet: +# path: / +# port: http + serviceAccount: # Specifies whether a service account should be created create: false @@ -85,18 +153,6 @@ autoscaling: targetCPUUtilizationPercentage: 80 # targetMemoryUtilizationPercentage: 80 -# Additional volumes on the output Deployment definition. -volumes: - - name: metacatui-pvc - persistentVolumeClaim: - claimName: metacatui-pvc - -# Additional volumeMounts on the output Deployment definition. -volumeMounts: - - name: metacatui-pvc - mountPath: "/usr/share/nginx/html" - readOnly: true - nodeSelector: {} tolerations: []