Skip to content

Commit

Permalink
feat: An option to disable the rasa-worker deployment (#228)
Browse files Browse the repository at this point in the history
* An option to disable the rasa-worker deployment, and an option to define a subpath for Nginx

* Add the RASA_PRODUCTION_URL env
  • Loading branch information
Tomasz Czekajlo authored Aug 25, 2021
1 parent 6e159ab commit b2f6980
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 20 deletions.
7 changes: 3 additions & 4 deletions charts/rasa-x/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
apiVersion: v2


version: "2.3.1"
version: "2.4.0"

appVersion: "0.42.0"

Expand Down Expand Up @@ -42,5 +41,5 @@ dependencies:
annotations:
# See: https://artifacthub.io/docs/topics/annotations/helm/#supported-annotations
artifacthub.io/changes: |
- kind: fixed
description: added @ char to the not allowed chars for the rabbit password in helm chart values
- kind: added
description: An option to disable the rasa-worker deployment, and an option to define a subpath for Nginx.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{/* Return Rasa Bot URL */}}
{{- define "rasa-bot.production.url" -}}
{{/* Return Rasa OSS URL - the production environment */}}
{{- define "rasa.production.url" -}}
{{- if and (not .Values.rasa.versions.rasaProduction.enabled) .Values.rasa.versions.rasaProduction.external.enabled (not (empty .Values.rasa.versions.rasaProduction.external.url)) (not ((index .Values "rasa-bot").subchart)) }}
{{- print .Values.rasa.versions.rasaProduction.external.url }}
{{- else if and (not .Values.rasa.versions.rasaProduction.enabled) (index .Values "rasa-bot").subchart }}
Expand All @@ -8,3 +8,12 @@
{{- printf "%s://%s-%s.%s.svc:%d" .Values.rasa.scheme (include "rasa-x.fullname" .) .Values.rasa.versions.rasaProduction.serviceName .Release.Namespace (.Values.rasa.port | int) }}
{{- end }}
{{- end -}}

{{/* Return Rasa OSS URL - the worker environment */}}
{{- define "rasa.worker.url" -}}
{{- if and (not .Values.rasa.versions.rasaWorker.enabled) .Values.rasa.versions.rasaWorker.external.enabled (not (empty .Values.rasa.versions.rasaWorker.external.url)) (not ((index .Values "rasa-bot").subchart)) }}
{{- print .Values.rasa.versions.rasaWorker.external.url }}
{{- else }}
{{- printf "%s://%s-%s.%s.svc:%d" .Values.rasa.scheme (include "rasa-x.fullname" .) .Values.rasa.versions.rasaWorker.serviceName .Release.Namespace (.Values.rasa.port | int) }}
{{- end }}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- define "rasax.nginx.template" -}}
upstream docker-rasax-api {
server ${RASA_X_HOST} max_fails=0;
}
Expand All @@ -9,40 +10,43 @@ server {
keepalive_timeout 30;
client_max_body_size 800M;
location /robots.txt {
location {{ trimSuffix "/" .Values.nginx.subPath }}/robots.txt {
return 200 "User-agent: *\nDisallow: /\n";
}

location /core/ {
{{- if or .Values.rasa.versions.rasaProduction.enabled .Values.rasa.versions.rasaProduction.external.enabled }}
location {{ trimSuffix "/" .Values.nginx.subPath }}/core/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass {{ include "rasa-bot.production.url" .}};
proxy_pass {{ include "rasa.production.url" .}};
}

# avoid users having to change how they configure
# their credentials URLs between Rasa and Rasa X
location /webhooks/ {
location {{ trimSuffix "/" .Values.nginx.subPath }}/webhooks/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass {{ include "rasa-bot.production.url" .}}/webhooks/;
proxy_pass {{ include "rasa.production.url" .}}/webhooks/;
}

location /socket.io {
location {{ trimSuffix "/" .Values.nginx.subPath }}/socket.io {
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass {{ include "rasa-bot.production.url" .}}/socket.io;
proxy_pass {{ include "rasa.production.url" .}}/socket.io;
}

location /api/ws {
{{- end }}

location {{ trimSuffix "/" .Values.nginx.subPath }}/api/ws {
# following https://www.serverlab.ca/tutorials/linux/web-servers-linux/how-to-configure-nginx-for-websockets/
# This directive converts the incoming connection to HTTP 1.1, which is
# required to support WebSockets. The older HTTP 1.0 spec does not provide support
Expand All @@ -61,7 +65,7 @@ server {
proxy_pass http://docker-rasax-api/api/ws;
}

location / {
location {{ trimSuffix "/" .Values.nginx.subPath }}/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
Expand All @@ -71,7 +75,7 @@ server {

# pass chat message to production service if environment query parameter
# is set to `production`, or that parameter isn't set
location /api/chat$ {
location {{ trimSuffix "/" .Values.nginx.subPath }}/api/chat$ {
if ($arg_environment = "") {
rewrite ^ /core/webhooks/rasa/webhook last;
}
Expand All @@ -81,11 +85,12 @@ server {
proxy_pass http://docker-rasax-api/api/chat;
}

location /nginx_status {
location {{ trimSuffix "/" .Values.nginx.subPath }}/nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
{{- end -}}
3 changes: 2 additions & 1 deletion charts/rasa-x/templates/nginx-conf-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ metadata:
data:
nginx.conf: {{ tpl (.Files.Get "nginx-config-files/nginx.conf") . | quote }}
ssl.conf.template: {{ tpl (.Files.Get "nginx-config-files/ssl.conf.template") . | quote }}
rasax.nginx.template: {{ tpl (.Files.Get "nginx-config-files/rasax.nginx.template") . | quote }}
rasax.nginx.template: |
{{- include "rasax.nginx.template" . | nindent 4 }}
{{- end }}
4 changes: 4 additions & 0 deletions charts/rasa-x/templates/nginx-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ spec:
app.kubernetes.io/component: nginx
template:
metadata:
annotations:
checksum/nginx-config: {{ include (print $.Template.BasePath "/nginx-conf-configmap.yaml") $ | sha256sum }}
labels:
{{- include "rasa-x.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: nginx
Expand Down Expand Up @@ -74,6 +76,8 @@ spec:
env:
- name: "NGINX_ENVSUBST_TEMPLATE_SUFFIX"
value: ".template"
- name: "RASA_PRODUCTION_URL"
value: "{{ include "rasa.production.url" .}}"
- name: "RASA_X_HOST"
value: "{{ include "rasa-x.host" . }}.{{ .Release.Namespace }}.svc:{{ .Values.rasax.port }}"
volumeMounts:
Expand Down
8 changes: 6 additions & 2 deletions charts/rasa-x/templates/rasa-x-config-files-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ metadata:
{{ include "rasa-x.labels" . | nindent 4 }}
data:
environments: |
{{- if or .Values.rasa.versions.rasaProduction.enabled .Values.rasa.versions.rasaProduction.external.enabled }}
rasa:
production:
url: "{{- include "rasa-bot.production.url" .}}"
url: "{{- include "rasa.production.url" .}}"
token: ${RASA_TOKEN}
{{- end }}
{{- if or .Values.rasa.versions.rasaWorker.enabled .Values.rasa.versions.rasaWorker.external.enabled }}
worker:
url: "{{ .Values.rasa.scheme }}://{{ include "rasa-x.fullname" . }}-{{ .Values.rasa.versions.rasaWorker.serviceName }}.{{ .Release.Namespace }}.svc:{{ .Values.rasa.port }}"
url: "{{- include "rasa.worker.url" .}}"
token: ${RASA_TOKEN}
{{- end }}
12 changes: 12 additions & 0 deletions charts/rasa-x/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,17 @@ rasa:
# rasaWorker is the container which does computational heavy tasks such as training
rasaWorker:
# enable the rasa-worker deployment
# You can disable the rasa-worker deployment in order to use external Rasa OSS deployment instead.
enabled: true

# Define if external Rasa OSS should be used.
external:
# enable external Rasa OSS
enabled: false

# host of external Rasa OSS deployment
host: "http://rasa-worker"

# nodeSelector to specify which node the pods should run on
# https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
nodeSelector: {}
Expand Down Expand Up @@ -508,6 +518,8 @@ nginx:
# enabled should be `true` if you want to use nginx
# if you set false, you will need to set up some other method of routing (VirtualService/Ingress controller)
enabled: true
# subPath defines the subpath used by Rasa X (ROOT_URL), e.g /rasa-x
subPath: ""
# override the default command to run in the container
command: []
# override the default arguments to run in the container
Expand Down

0 comments on commit b2f6980

Please sign in to comment.