Skip to content

Commit

Permalink
Merge pull request #17 from esgf2-us/adds-examples
Browse files Browse the repository at this point in the history
Adds examples
  • Loading branch information
jasonb5 authored Nov 15, 2024
2 parents f9269d6 + c915896 commit 8605835
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 42 deletions.
2 changes: 1 addition & 1 deletion chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: metagrid
description: A Helm chart for the Metagrid frontend/backend
type: application
version: 0.1.6
version: 0.1.7
appVersion: "1.2.0"
home: https://github.com/esgf2-us/metagrid-k8s
sources:
Expand Down
30 changes: 25 additions & 5 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ Django base url
Django Url
*/}}
{{- define "metagrid.django.url" -}}
{{- if .Values.react.backendUrl }}
{{- printf "%s" .Values.react.backendUrl }}
{{- else }}
{{- $baseUrl := include "metagrid.django.baseUrl" . }}
{{- printf "%s%s" $baseUrl (printf "/%s" (trimPrefix "/" .Values.django.urlPath)) }}
{{- end }}
{{- end }}

{{/*
Django login url
Expand All @@ -146,23 +150,39 @@ Django logout url
Django login redirect
*/}}
{{- define "metagrid.django.loginRedirect" -}}
{{- $baseUrl := include "metagrid.react.url" . }}
{{- printf "%s/%s" $baseUrl (trimPrefix "/" .Values.django.loginRedirect) }}
{{- $path := "" }}
{{- with .Values.django.loginRedirect }}
{{- $path = printf "/%s" (trimPrefix "/" .) }}
{{- end }}
{{- printf "%s%s" (include "metagrid.react.url" .) $path }}
{{- end }}

{{/*
Django logout redirect
*/}}
{{- define "metagrid.django.logoutRedirect" -}}
{{- $baseUrl := include "metagrid.react.url" . }}
{{- printf "%s/%s" $baseUrl (trimPrefix "/" .Values.django.logoutRedirect) }}
{{- $path := "" }}
{{- with .Values.django.logoutRedirect }}
{{- $path = printf "/%s" (trimPrefix "/" .) }}
{{- end }}
{{- printf "%s%s" (include "metagrid.react.url" .) $path }}
{{- end }}

{{/*
Django ALLOWED_HOSTS
*/}}
{{- define "metagrid.djangoAllowedHosts" -}}
{{- join "," (list "127.0.0.1" "localhost" (printf "%s-django" (include "metagrid.fullname" .)) .Values.ingress.react.host ) -}}
{{- $allowed_hosts := list "127.0.0.1" "localhost" (printf "%s-django" (include "metagrid.fullname" .)) }}

{{- if and .Values.ingress.enabled .Values.ingress.react.host }}
{{- $allowed_hosts = append $allowed_hosts .Values.ingress.react.host }}
{{- end }}

{{- if .Values.baseUrl }}
{{- $allowed_hosts = append $allowed_hosts (last (regexSplit "/" .Values.baseUrl -1)) }}
{{- end }}

{{- join "," $allowed_hosts -}}
{{- end }}

{{/*
Expand Down
24 changes: 12 additions & 12 deletions chart/templates/django/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ metadata:
{{- include "metagrid.labels" . | nindent 4 }}
app.kubernetes.io/component: django
data:
PYTHONBUFFERED: "1"
{{- with .Values.django.gunicornCmdArgs }}
GUNICORN_CMD_ARGS: {{ . | quote }}
{{- end }}
PYTHONBUFFERED: "1"
DOMAIN_NAME: {{ default "127.0.0.1" .Values.ingress.django.host }}
DOMAIN_SUBDIRECTORY: {{ trimPrefix "/" .Values.django.urlPath }}
DJANGO_DEBUG: {{ .Values.django.debug | quote }}
DJANGO_SETTINGS_MODULE: config.settings.production
DJANGO_SECRET_KEY: {{ default (randAlphaNum 32) .Values.django.secretKey }}
DJANGO_ADMIN_URL: {{ .Values.django.adminUrl }}
DJANGO_ALLOWED_HOSTS: {{ include "metagrid.djangoAllowedHosts" . | quote }}
DJANGO_SECURE_SSL_REDIRECT: "False"
DJANGO_SETTINGS_MODULE: config.settings.production
DJANGO_LOGIN_REDIRECT_URL: {{ include "metagrid.django.loginRedirect" . | quote }}
DJANGO_LOGOUT_REDIRECT_URL: {{ include "metagrid.django.logoutRedirect" . | quote }}
GLOBUS_CLIENT_KEY: {{ .Values.globus.clientID }}
DOMAIN_NAME: {{ default "127.0.0.1" .Values.ingress.django.host }}
DOMAIN_SUBDIRECTORY: {{ trimPrefix "/" .Values.django.urlPath }}
CORS_ALLOWED_ORIGINS: {{ include "metagrid.django.corsOriginWhitelist" . }}
# CORS_ORIGIN_WHITELIST: {{ include "metagrid.django.corsOriginWhitelist" . }}
{{- if eq .Values.authType "globus" }}
KEYCLOAK_URL: {{ .Values.keyCloak.url }}
KEYCLOAK_REALM: {{ .Values.keyCloak.realm }}
KEYCLOAK_CLIENT_ID: {{ .Values.keyCloak.clientID }}
DJANGO_LOGIN_REDIRECT_URL: {{ include "metagrid.django.loginRedirect" . | quote }}
DJANGO_LOGOUT_REDIRECT_URL: {{ include "metagrid.django.logoutRedirect" . | quote }}
GLOBUS_CLIENT_KEY: {{ .Values.globus.backend.clientID }}
{{- end }}
KEYCLOAK_URL: {{ default "" .Values.keyCloak.url }}
KEYCLOAK_REALM: {{ default "" .Values.keyCloak.realm }}
KEYCLOAK_CLIENT_ID: {{ default "" .Values.keyCloak.clientID }}
GLOBUS_CLIENT_SECRET: {{ .Values.globus.backend.clientSecret }}
# Required by api_proxy
REACT_APP_WGET_API_URL: {{ .Values.wgetApiUrl }}
REACT_APP_SEARCH_URL: {{ .Values.searchUrl }}
REACT_APP_ESGF_NODE_STATUS_URL: {{ .Values.esgfNodeStatusUrl }}
Expand Down
16 changes: 8 additions & 8 deletions chart/templates/django/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ metadata:
{{- with .Values.django.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.django.annotations }}
annotations:
{{- $configmap := include (print $.Template.BasePath "/django/configmap.yaml") . }}
{{- $secret := include (print $.Template.BasePath "/django/secret.yaml") . }}
checksum/config: {{ print $configmap $secret | sha256sum }}
{{- with .Values.django.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
spec:
{{- if not .Values.django.autoscaling.enabled }}
replicas: {{ .Values.django.replicaCount }}
Expand All @@ -25,10 +22,13 @@ spec:
app.kubernetes.io/component: django
template:
metadata:
{{- with .Values.django.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- $configmap := include (print $.Template.BasePath "/django/configmap.yaml") . }}
{{- $secret := include (print $.Template.BasePath "/django/secret.yaml") . }}
checksum/config: {{ print $configmap $secret | sha256sum }}
{{- with .Values.django.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "metagrid.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: django
Expand Down
13 changes: 9 additions & 4 deletions chart/templates/react/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ metadata:
data:
RELEASE: production
PUBLIC_URL: {{ .Values.react.urlPath }}
REACT_APP_METAGRID_API_URL: {{ include "metagrid.django.url" . }}
REACT_APP_PREVIOUS_URL: {{ default "" .Values.react.previousUrlPath }}
REACT_APP_METAGRID_API_URL: {{ include "metagrid.django.url" . }}
REACT_APP_AUTHENTICATION_METHOD: {{ .Values.authType }}
{{- if eq .Values.authType "globus" }}
REACT_APP_GLOBUS_REDIRECT: {{ .Values.globus.frontend.redirect }}
REACT_APP_CLIENT_ID: {{ .Values.globus.frontend.clientID }}
Expand All @@ -23,18 +24,22 @@ data:
REACT_APP_KEYCLOAK_URL: {{ .url }}
REACT_APP_KEYCLOAK_CLIENT_ID: {{ .clientID }}
{{- end }}
REACT_APP_DJANGO_LOGIN_URL: {{ include "metagrid.django.loginUrl" . }}
REACT_APP_DJANGO_LOGOUT_URL: {{ include "metagrid.django.logoutUrl" . }}
{{- with .Values.react.hotjar }}
REACT_APP_HOTJAR_ID: {{ .id | quote }}
REACT_APP_HOTJAR_SV: {{ .sv | quote }}
{{- end }}
REACT_APP_DJANGO_LOGIN_URL: {{ include "metagrid.django.loginUrl" . }}
REACT_APP_DJANGO_LOGOUT_URL: {{ include "metagrid.django.logoutUrl" . }}
REACT_APP_AUTHENTICATION_METHOD: {{ .Values.authType }}
REACT_APP_GOOGLE_ANALYTICS_TRACKING_ID: {{ default "" .Values.react.googleAnalyticsID }}
# TODO default metagrid nginx adds location for PREVIOUS_URL and breaks reverse proxy
default.conf: |
server {
listen {{ .Values.react.service.port }};
location / {
return 301 /metagrid;
}
location ^~ {{ printf "/%s" (trimPrefix "/" .Values.react.urlPath) }} {
alias /usr/share/nginx/html/;
index index.html index.htm;
Expand Down
8 changes: 4 additions & 4 deletions chart/templates/react/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ metadata:
{{- with .Values.react.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.react.annotations }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/react/configmap.yaml") . | sha256sum }}
{{- with .Values.react.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
spec:
{{- if not .Values.react.autoscaling.enabled }}
replicas: {{ .Values.react.replicaCount }}
Expand All @@ -23,8 +22,9 @@ spec:
app.kubernetes.io/component: react
template:
metadata:
{{- with .Values.react.podAnnotations }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/react/configmap.yaml") . | sha256sum }}
{{- with .Values.react.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
Expand Down
14 changes: 7 additions & 7 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ globus:
redirect: https://localhost:3000/cart/items
# -- Client ID for a globus thick client, the redirect will need to be the url of the frontend e.g. https://metagrid.io/metagrid
frontend:
clientID:
clientID: client_id
# -- Client ID/Secret for globus portal, the redirect will need to be the url of the backend e.g. https://metagrid.io/metagrid-backend/complete/globus/
backend:
clientID:
clientSecret:
clientID: client_id
clientSecret: client_secret
nodes:
- aims3.llnl.gov
- esgf-data1.llnl.gov
- esgf-data2.llnl.gov

keyCloak:
# -- Keycloak service url
url:
url: http://127.0.0.1:8080
# -- Client realm
realm:
realm: metagrid
# -- Client ID
clientID:
clientID: client_id

# -- ESGF wget service url
wgetApiUrl: https://esgf-node.llnl.gov/esg-search/wget
Expand Down Expand Up @@ -69,7 +69,7 @@ react:
googleAnalyticsID:

# -- Custom url for external metagrid backend
backendUrl: http://127.0.0.1:5000
backendUrl:

# -- Frontend path prefix
urlPath: /metagrid
Expand Down
1 change: 1 addition & 0 deletions examples/ingress-nginx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
overrides.yaml
13 changes: 13 additions & 0 deletions examples/ingress-nginx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: deploy
deploy:
MINIKUBE_IP=$(shell minikube ip) envsubst '$$MINIKUBE_IP' < overrides.yaml.tpl > overrides.yaml
helm upgrade --install -f overrides.yaml test ../../chart

.PHONY: delete
delete:
helm delete test

.PHONY: open
open:
@echo "Run:\n\techo '$(shell minikube ip) metagrid.minikube.io' >> /etc/hosts"
@echo "Visit:\n\t https://metagrid.minikube.io/metagrid/"
11 changes: 11 additions & 0 deletions examples/ingress-nginx/overrides.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ingress:
enabled: true

react:
host: metagrid.minikube.io

django:
host: metagrid.minikube.io

tls:
enabled: true
13 changes: 13 additions & 0 deletions examples/port-forward/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: deploy
deploy:
helm upgrade --install test ../../chart

.PHONY: delete
delete:
helm delete test

.PHONY: open
open:
@echo "Visit:\n\thttp://127.0.0.1:3000/metagrid/"
minikube kubectl -- port-forward $(shell minikube kubectl -- get pods --selector app.kubernetes.io/component=django -oname) 5000 & \
minikube kubectl -- port-forward $(shell minikube kubectl -- get pods --selector app.kubernetes.io/component=react -oname) 3000
2 changes: 1 addition & 1 deletion tbump.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github_url = "https://github.com/esgf2-us/metagrid-k8s/"

[version]
current = "0.1.6"
current = "0.1.7"

regex = '''
(?P<major>\d+)
Expand Down

0 comments on commit 8605835

Please sign in to comment.