Skip to content

Commit

Permalink
Ability to add env var to chart deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet committed Aug 4, 2022
1 parent 4438c6a commit e220ae0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
4 changes: 3 additions & 1 deletion bert_e/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 5 additions & 17 deletions bert_e/server/reverse_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions charts/bert-e/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down
15 changes: 15 additions & 0 deletions charts/bert-e/templates/env.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 3 additions & 0 deletions charts/bert-e/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e220ae0

Please sign in to comment.