diff --git a/bert_e/server/__init__.py b/bert_e/server/__init__.py index f26f54b8..3b71a6cf 100644 --- a/bert_e/server/__init__.py +++ b/bert_e/server/__init__.py @@ -78,7 +78,9 @@ def setup_server(bert_e): 'WTF_CSRF_SECRET_KEY': secrets.token_hex(24), }) - app.wsgi_app = ReverseProxied(app.wsgi_app) + app_prefix = os.getenv('APP_PREFIX', '/') + + app.wsgi_app = ReverseProxied(app.wsgi_app, app_prefix) app.bert_e = bert_e diff --git a/bert_e/server/reverse_proxy.py b/bert_e/server/reverse_proxy.py index 1a1fa3c5..7e0cab37 100644 --- a/bert_e/server/reverse_proxy.py +++ b/bert_e/server/reverse_proxy.py @@ -23,24 +23,12 @@ class ReverseProxied(object): - app: the WSGI application """ - def __init__(self, app): + def __init__(self, app, prefix=""): self.app = app + self.prefix = prefix def __call__(self, environ, start_response): - script_name = environ.get('HTTP_X_SCRIPT_NAME', None) - if script_name is not None: - environ['SCRIPT_NAME'] = script_name - path_info = environ['PATH_INFO'] - if path_info.startswith(script_name): - path_info = path_info[len(script_name):] - environ['PATH_INFO'] = path_info - - scheme = environ.get('HTTP_X_SCHEME', None) - if scheme is not None: - environ['wsgi_url_scheme'] = scheme - - server = environ.get('HTTP_X_FORWARDED_SERVER', None) - if server: - environ['HTTP_HOST'] = server - + if environ['PATH_INFO'].startswith(self.prefix): + environ['PATH_INFO'] = environ['PATH_INFO'][len(self.prefix):] + environ['SCRIPT_NAME'] = self.prefix return self.app(environ, start_response) diff --git a/charts/bert-e/templates/deployment.yaml b/charts/bert-e/templates/deployment.yaml index 88b70c57..b702e0e0 100644 --- a/charts/bert-e/templates/deployment.yaml +++ b/charts/bert-e/templates/deployment.yaml @@ -22,6 +22,7 @@ spec: annotations: checksum/settings: {{ include (print $.Template.BasePath "/settings.yaml") . | sha256sum }} checksum/secret: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }} + checksum/env: {{ include (print $.Template.BasePath "/env.yaml") . | sha256sum }} spec: {{- if .Values.image.pullSecrets }} imagePullSecrets: @@ -36,6 +37,10 @@ spec: envFrom: - secretRef: name: {{ template "fullname" $ }} + {{- if .Values.deployment.env }} + - configMapRef: + name: {{ template "fullname" $ }}-env + {{- end }} ports: - name: http containerPort: {{ .Values.deployment.servicePort }} diff --git a/charts/bert-e/templates/env.yaml b/charts/bert-e/templates/env.yaml new file mode 100644 index 00000000..647f9acc --- /dev/null +++ b/charts/bert-e/templates/env.yaml @@ -0,0 +1,15 @@ +{{- if .Values.deployment.env }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "fullname" $ }}-env + labels: + app: {{ template "fullname" $ }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +type: Opaque +data: +{{ .Values.deployment.env | toYaml | indent 2 }} +{{- end }} diff --git a/charts/bert-e/values.yaml b/charts/bert-e/values.yaml index 1315fd16..04dfb2bc 100644 --- a/charts/bert-e/values.yaml +++ b/charts/bert-e/values.yaml @@ -313,6 +313,9 @@ image: ## Kubernetes deployment configuration deployment: + # Setup env vars on the deployment + env: {} + # MY_VAR: MY_VALUE ## Configure extra options for liveness and readiness probes livenessProbe: