From 5236c3bd143221f7bab8cf221eaab9bea1963c22 Mon Sep 17 00:00:00 2001 From: AlexGacon Date: Wed, 7 Aug 2024 14:56:18 +0200 Subject: [PATCH 1/4] feat: refactor chart to make it compatible with GeoNode projects --- charts/geonode/templates/_helpers.tpl | 16 +++++++++ .../templates/geonode/geonode-deploy.yaml | 33 ++++++++++--------- .../geonode/geonode-entrypoint-sh-conf.yaml | 2 +- .../templates/geonode/geonode-env.yaml | 4 +-- .../geonode/geonode-uwsgi-ini-conf.yaml | 8 ++--- charts/geonode/values.yaml | 2 ++ 6 files changed, 43 insertions(+), 22 deletions(-) diff --git a/charts/geonode/templates/_helpers.tpl b/charts/geonode/templates/_helpers.tpl index 0a7c316..d2d4908 100644 --- a/charts/geonode/templates/_helpers.tpl +++ b/charts/geonode/templates/_helpers.tpl @@ -138,3 +138,19 @@ amqp://{{ .Values.rabbitmq.auth.username }}:{{ .Values.rabbitmq.auth.password }} {{- define "boolean2str" -}} {{ . | ternary "True" "False" }} {{- end -}} + +{{- define "settings_module" -}} +{{- if (not .Values.geonode.general.settings_module) -}} +{{ .Values.geonode.general.geonode_project }}.settings +{{- else -}} +{{ .Values.geonode.general.settings_module }} +{{- end -}} +{{- end -}} + +{{- define "geonode_root_path" -}} +/usr/src/{{ .Values.geonode.general.geonode_project }} +{{- end -}} + +{{- define "geonode_path" -}} +/usr/src/{{ .Values.geonode.general.geonode_project }}/{{ .Values.geonode.general.geonode_project }} +{{- end -}} diff --git a/charts/geonode/templates/geonode/geonode-deploy.yaml b/charts/geonode/templates/geonode/geonode-deploy.yaml index 59bbe23..6eebc67 100644 --- a/charts/geonode/templates/geonode/geonode-deploy.yaml +++ b/charts/geonode/templates/geonode/geonode-deploy.yaml @@ -71,17 +71,18 @@ spec: cd /usr/src/geonode/ {{ end }} + cd {{ include "geonode_root_path" .}}/ # Add config overrides - cat /usr/src/geonode/geonode/geonode-k8s-settings.py >> /usr/src/geonode/geonode/settings.py - cat /usr/src/geonode/geonode/geonode-k8s-settings-additions.py >> /usr/src/geonode/geonode/settings.py + cat /usr/src/geonode/geonode/geonode-k8s-settings.py >> {{ include "geonode_path" .}}/settings.py + cat /usr/src/geonode/geonode/geonode-k8s-settings-additions.py >> {{ include "geonode_path" .}}/settings.py # Setup - touch /usr/src/geonode/invoke.log - dockerize -stdout /usr/src/geonode/invoke.log /usr/src/geonode/entrypoint.sh + touch {{ include "geonode_root_path" .}}/invoke.log + dockerize -stdout {{ include "geonode_root_path" .}}/invoke.log {{ include "geonode_root_path" .}}/entrypoint.sh # Run web server touch /var/log/geonode.log - dockerize -stdout /var/log/geonode.log /usr/local/bin/uwsgi --ini /usr/src/geonode/uwsgi.ini + dockerize -stdout /var/log/geonode.log /usr/local/bin/uwsgi --ini {{ include "geonode_root_path" .}}/uwsgi.ini ports: - name: http @@ -133,14 +134,14 @@ spec: - name: cache-volume mountPath: /tmp - name: tasks-py - mountPath: "/usr/src/geonode/tasks.py" + mountPath: "{{ include "geonode_root_path" .}}/tasks.py" subPath: tasks.py readOnly: true - name: entrypoint-sh - mountPath: "/usr/src/geonode/entrypoint.sh" + mountPath: "{{ include "geonode_root_path" .}}/entrypoint.sh" subPath: entrypoint.sh - name: uwsgi-ini - mountPath: "/usr/src/geonode/uwsgi.ini" + mountPath: "{{ include "geonode_root_path" .}}/uwsgi.ini" subPath: uwsgi.ini readOnly: true - name: geonode-k8s-settings-py @@ -152,7 +153,7 @@ spec: readOnly: true {{ if .Values.geonodeFixtures }} - name: geonode-fixtures - mountPath: "/usr/src/geonode/geonode/fixtures" + mountPath: "{{ include "geonode_path" .}}/fixtures" readOnly: true {{ end }} @@ -199,16 +200,18 @@ spec: cd /usr/src/geonode/ {{ end }} + cd {{ include "geonode_root_path" .}}/ + {{ if .Values.geonode.sentry.enabled }} pip install sentry-sdk {{ end }} # Add config overrides - cat /usr/src/geonode/geonode/geonode-k8s-settings.py >> /usr/src/geonode/geonode/settings.py - cat /usr/src/geonode/geonode/geonode-k8s-settings-additions.py >> /usr/src/geonode/geonode/settings.py + cat /usr/src/geonode/geonode/geonode-k8s-settings.py >> {{ include "geonode_path" .}}/settings.py + cat /usr/src/geonode/geonode/geonode-k8s-settings-additions.py >> {{ include "geonode_path" .}}/settings.py # Setup touch /var/log/celery.log - dockerize -stdout /var/log/celery.log /usr/src/geonode/entrypoint.sh celery-cmd + dockerize -stdout /var/log/celery.log {{ include "geonode_root_path" .}}/entrypoint.sh celery-cmd envFrom: - configMapRef: @@ -260,10 +263,10 @@ spec: - name: cache-volume mountPath: /tmp - name: entrypoint-sh - mountPath: "/usr/src/geonode/entrypoint.sh" + mountPath: "{{ include "geonode_root_path" .}}/entrypoint.sh" subPath: entrypoint.sh - name: tasks-py - mountPath: "/usr/src/geonode/tasks.py" + mountPath: "{{ include "geonode_root_path" .}}/tasks.py" subPath: tasks.py readOnly: true - name: geonode-k8s-settings-py @@ -275,7 +278,7 @@ spec: readOnly: true {{ if .Values.geonodeFixtures }} - name: geonode-fixtures - mountPath: "/usr/src/geonode/geonode/fixtures" + mountPath: "{{ include "geonode_path" .}}/fixtures" readOnly: true {{ end }} diff --git a/charts/geonode/templates/geonode/geonode-entrypoint-sh-conf.yaml b/charts/geonode/templates/geonode/geonode-entrypoint-sh-conf.yaml index c54575d..94b47ec 100644 --- a/charts/geonode/templates/geonode/geonode-entrypoint-sh-conf.yaml +++ b/charts/geonode/templates/geonode/geonode-entrypoint-sh-conf.yaml @@ -15,7 +15,7 @@ data: then /usr/local/bin/invoke $@ else - /usr/local/bin/invoke $@ > /usr/src/geonode/invoke.log 2>&1 + /usr/local/bin/invoke $@ > {{ include "geonode_root_path" . }}/invoke.log 2>&1 fi echo "$@ tasks done" } diff --git a/charts/geonode/templates/geonode/geonode-env.yaml b/charts/geonode/templates/geonode/geonode-env.yaml index b88846f..c9d19fc 100644 --- a/charts/geonode/templates/geonode/geonode-env.yaml +++ b/charts/geonode/templates/geonode/geonode-env.yaml @@ -44,7 +44,7 @@ data: # General settings FREETEXT_KEYWORDS_READONLY: {{ include "boolean2str" .Values.geonode.general.freetext_keywords_readonly | quote }} - FIXTURE_DIRS: "[ '/usr/src/geonode/geonode/fixtures' ]" + FIXTURE_DIRS: "[ '{{ include "geonode_path" .}}/fixtures' ]" # PUBLISHING RESOURCE_PUBLISHING: {{ include "boolean2str" .Values.geonode.general.publishing.resource_publishing_by_staff | quote }} ADMIN_MODERATE_UPLOADS: {{ include "boolean2str" .Values.geonode.general.publishing.admin_moderate_uploads | quote }} @@ -121,7 +121,7 @@ data: CATALOGUE_ENGINE: geonode.catalogue.backends.pycsw_local {{ end}} - DJANGO_SETTINGS_MODULE: {{ .Values.geonode.general.settings_module }} + DJANGO_SETTINGS_MODULE: {{ include "settings_module" . }} DEFAULT_BACKEND_DATASTORE: datastore DEFAULT_BACKEND_UPLOADER: geonode.importer diff --git a/charts/geonode/templates/geonode/geonode-uwsgi-ini-conf.yaml b/charts/geonode/templates/geonode/geonode-uwsgi-ini-conf.yaml index d0994b7..0945214 100644 --- a/charts/geonode/templates/geonode/geonode-uwsgi-ini-conf.yaml +++ b/charts/geonode/templates/geonode/geonode-uwsgi-ini-conf.yaml @@ -9,8 +9,8 @@ data: http-socket = 0.0.0.0:8001 # pidfile = /tmp/geonode.pid - chdir = /usr/src/geonode/ - module = geonode.wsgi:application + chdir = {{ include "geonode_root_path" . }}/ + module = {{ .Values.geonode.general.geonode_project }}.wsgi:application strict = false master = true @@ -24,7 +24,7 @@ data: # path to where uwsgi logs will be saved logto = /var/log/geonode.log - touch-reload = /usr/src/geonode/geonode/wsgi.py + touch-reload = {{ include "geonode_path" . }}/wsgi.py buffer-size = {{ .Values.geonode.uwsgi.buffer_size }} harakiri = {{ .Values.geonode.uwsgi.harakiri }} @@ -49,4 +49,4 @@ data: cheaper-busyness-backlog-step = {{ .Values.geonode.uwsgi.cheaper_busyness_backlog_step }} # daemonize = /var/log/uwsgi/geonode.log - # cron = -1 -1 -1 -1 -1 /usr/local/bin/python /usr/src/geonode/manage.py collect_metrics -n + # cron = -1 -1 -1 -1 -1 /usr/local/bin/python {{ include "geonode_root_path" . }}/manage.py collect_metrics -n diff --git a/charts/geonode/values.yaml b/charts/geonode/values.yaml index 3722ff8..1407344 100644 --- a/charts/geonode/values.yaml +++ b/charts/geonode/values.yaml @@ -163,6 +163,8 @@ geonode: debug: False # -- enable django static debug debug_static: False + # -- the name of the geonode project used (keep geonode for base image) + geonode_project: geonode # -- the settings module to load settings_module: geonode.settings # -- add additional settings to the settings py. This code will be appended to the end of the geonode settings.py From 285dd1bc9d2f5396095f2b5c269e381932d8331d Mon Sep 17 00:00:00 2001 From: AlexGacon Date: Wed, 7 Aug 2024 16:16:46 +0200 Subject: [PATCH 2/4] fix: the initial data path changes for geonode project --- charts/geonode/templates/_helpers.tpl | 8 ++++++++ .../geonode/templates/geonode/geonode-tasks-py-conf.yaml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/charts/geonode/templates/_helpers.tpl b/charts/geonode/templates/_helpers.tpl index d2d4908..f01961d 100644 --- a/charts/geonode/templates/_helpers.tpl +++ b/charts/geonode/templates/_helpers.tpl @@ -154,3 +154,11 @@ amqp://{{ .Values.rabbitmq.auth.username }}:{{ .Values.rabbitmq.auth.password }} {{- define "geonode_path" -}} /usr/src/{{ .Values.geonode.general.geonode_project }}/{{ .Values.geonode.general.geonode_project }} {{- end -}} + +{{- define "initial_data_path" -}} +{{- if (eq .Values.geonode.general.geonode_project "geonode") -}} +geonode/base/fixtures/initial_data.json +{{- else -}} +initial_data.json +{{- end -}} +{{- end -}} diff --git a/charts/geonode/templates/geonode/geonode-tasks-py-conf.yaml b/charts/geonode/templates/geonode/geonode-tasks-py-conf.yaml index 760ba45..d31cfa5 100644 --- a/charts/geonode/templates/geonode/geonode-tasks-py-conf.yaml +++ b/charts/geonode/templates/geonode/geonode-tasks-py-conf.yaml @@ -353,7 +353,7 @@ data: pty=True, ) ctx.run( - f"python manage.py loaddata geonode/base/fixtures/initial_data.json \ + f"python manage.py loaddata {{ include "initial_data_path" . }} \ --settings={_localsettings()}", pty=True, ) From aeb66af36191e31f916861ff3ffd1927203b09be Mon Sep 17 00:00:00 2001 From: AlexGacon Date: Wed, 7 Aug 2024 16:34:30 +0200 Subject: [PATCH 3/4] fix: case for settings module were inverted --- charts/geonode/templates/_helpers.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/geonode/templates/_helpers.tpl b/charts/geonode/templates/_helpers.tpl index f01961d..a1473d6 100644 --- a/charts/geonode/templates/_helpers.tpl +++ b/charts/geonode/templates/_helpers.tpl @@ -141,9 +141,9 @@ amqp://{{ .Values.rabbitmq.auth.username }}:{{ .Values.rabbitmq.auth.password }} {{- define "settings_module" -}} {{- if (not .Values.geonode.general.settings_module) -}} -{{ .Values.geonode.general.geonode_project }}.settings -{{- else -}} {{ .Values.geonode.general.settings_module }} +{{- else -}} +{{ .Values.geonode.general.geonode_project }}.settings {{- end -}} {{- end -}} From 828760ed18813ba3017e99c2377e10d0953dbdef Mon Sep 17 00:00:00 2001 From: AlexGacon Date: Wed, 7 Aug 2024 17:27:27 +0200 Subject: [PATCH 4/4] Revert "fix: case for settings module were inverted" This reverts commit aeb66af36191e31f916861ff3ffd1927203b09be. --- charts/geonode/templates/_helpers.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/geonode/templates/_helpers.tpl b/charts/geonode/templates/_helpers.tpl index a1473d6..f01961d 100644 --- a/charts/geonode/templates/_helpers.tpl +++ b/charts/geonode/templates/_helpers.tpl @@ -141,9 +141,9 @@ amqp://{{ .Values.rabbitmq.auth.username }}:{{ .Values.rabbitmq.auth.password }} {{- define "settings_module" -}} {{- if (not .Values.geonode.general.settings_module) -}} -{{ .Values.geonode.general.settings_module }} -{{- else -}} {{ .Values.geonode.general.geonode_project }}.settings +{{- else -}} +{{ .Values.geonode.general.settings_module }} {{- end -}} {{- end -}}