Skip to content

Commit

Permalink
Merge pull request #72 from RasaHQ/db_migration_service
Browse files Browse the repository at this point in the history
Add the database migration service
  • Loading branch information
Tomasz Czekajlo authored Nov 3, 2020
2 parents f8e2166 + 3bd7939 commit 0e21dd7
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 4 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ jobs:
--timeout=10m \
-l "app.kubernetes.io/component=rasa-x" deployment
until [[ "$(curl -s http://localhost/api/health | tee /tmp/output_status.txt | jq -r .database_migration.status)" == "completed" ]]
do
cat /tmp/output_status.txt || true
sleep 5
done
- name: Log pod status for debugging
if: failure()
run: |
Expand All @@ -97,4 +104,8 @@ jobs:
- name: Validate that logging in works
run: |
curl --fail --data '{"username": "me", "password": "'${INITIAL_USER_PASSWORD}'"}' "http://localhost/api/auth"
TOKEN=$(curl --fail --data '{"username": "me", "password": "'${INITIAL_USER_PASSWORD}'"}' "http://localhost/api/auth" | jq -r '.access_token')
if [[ -z "${TOKEN}" ]]; then
echo "Access token is empty: ${TOKEN}" && exit 1
fi
echo "Access token: ${TOKEN}"
5 changes: 2 additions & 3 deletions charts/rasa-x/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
apiVersion: v2


version: "1.6.13"
appVersion: "0.30.1"
version: "1.7.0"
appVersion: "0.33.0"

name: rasa-x
description: Rasa X Helm chart for Kubernetes / Openshift
Expand Down
63 changes: 63 additions & 0 deletions charts/rasa-x/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ Include extra env vars for the EventService.
{{- end -}}
{{- end -}}

{{/*
Include extra env vars for the database migration service.
*/}}
{{- define "rasax.db-migration-service.extra.envs" -}}
{{- if .Values.dbMigrationService.extraEnvs -}}
{{ toYaml .Values.dbMigrationService.extraEnvs }}
{{- end -}}
{{- end -}}

{{/*
Return the storage class name which should be used.
*/}}
Expand Down Expand Up @@ -210,3 +219,57 @@ Return 'true' if an enterprise version is run.
{{- print "false" -}}
{{- end -}}
{{- end -}}

{{/*
Return the rasa-x.version value as a default if the dbMigrationService.tag variable is not defined.
*/}}
{{- define "db-migration-service.version" -}}
{{ .Values.dbMigrationService.tag | default (include "rasa-x.version" .) }}
{{- end -}}

{{/*
Return 'true' if required version to run the database migration service is correct.
If version is not valid semantic version then not use the DB migration service.
*/}}
{{- define "db-migration-service.requiredVersion" -}}
{{- if .Values.dbMigrationService.ignoreVersionCheck -}}
{{- print "true" -}}
{{- else -}}
{{- if semverCompare ">= 0.33.0" (include "db-migration-service.version" .) -}}
{{- print "true" -}}
{{- else -}}
{{- print "false" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Returns the database migration service address
*/}}
{{- define "db-migration-service.address" -}}
{{ .Release.Name }}{{- print "-db-migration-service-headless" -}}
{{- end -}}
{{/*
Return an init container for database migration.
*/}}
{{- define "initContainer.dbMigration" -}}
{{ if and (eq "true" (include "db-migration-service.requiredVersion" .)) .Values.separateDBMigrationService }}
initContainers:
- name: init-db
image: {{ .Values.dbMigrationService.initContainer.image }}
command:
- 'sh'
- '-c'
- "apk update --no-cache && \
apk add jq curl && \
until nslookup {{ (include "db-migration-service.address" .) }} 1> /dev/null; do echo Waiting for the database migration service; sleep 2; done && \
until [[ \"$(curl -s http://{{ (include "db-migration-service.address" .) }}:{{ .Values.dbMigrationService.port }} | jq -r .status)\" == \"completed\" ]]; do \
STATUS_JSON=$(curl -s http://{{ (include "db-migration-service.address" .) }}:{{ .Values.dbMigrationService.port }}); \
PROGRESS_IN_PERCENT=$(echo $STATUS_JSON | jq -r .progress_in_percent); \
STATUS=$(echo $STATUS_JSON | jq -r .status); \
echo The database migration status: ${STATUS}...${PROGRESS_IN_PERCENT}%; \
sleep 5; \
done; \
echo The database migration status: completed...100%"
{{- end -}}
{{- end -}}
78 changes: 78 additions & 0 deletions charts/rasa-x/templates/db-migration-service-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{{ if and (eq "true" (include "db-migration-service.requiredVersion" .)) .Values.separateDBMigrationService }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .Release.Name }}-db-migration-service
labels:
{{- include "rasa-x.labels" . | nindent 4 }}
app.kubernetes.io/component: db-migration-service
spec:
serviceName: "default"
replicas: 1
selector:
matchLabels:
{{- include "rasa-x.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: db-migration-service
template:
metadata:
labels:
{{- include "rasa-x.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: db-migration-service
spec:
automountServiceAccountToken: false
{{ include "rasa-x.spec" . }}
{{- if .Values.dbMigrationService.nodeSelector }}
nodeSelector:
{{ toYaml .Values.dbMigrationService.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.dbMigrationService.tolerations }}
tolerations:
{{ toYaml .Values.dbMigrationService.tolerations | indent 6 }}
{{- end }}
containers:
- name: db-migration-service
image: "{{ .Values.dbMigrationService.name }}:{{ include "db-migration-service.version" . }}"
imagePullPolicy: {{ .Values.images.pullPolicy }}
{{- if .Values.dbMigrationService.command }}
command:
{{- toYaml .Values.dbMigrationService.command | nindent 10 }}
{{- end }}
args:
- python
- -m
- rasax.community.services.db_migration_service
{{- if .Values.dbMigrationService.args }}
{{- toYaml .Values.dbMigrationService.args | nindent 10 }}
{{- end }}
ports:
- name: "http"
containerPort: {{ .Values.dbMigrationService.port }}
protocol: "TCP"
livenessProbe:
httpGet:
path: "/health"
port: "http"
readinessProbe:
httpGet:
path: "/health"
port: "http"
{{- if .Values.dbMigrationService.extraVolumeMounts }}
volumeMounts:
{{ toYaml .Values.dbMigrationService.extraVolumeMounts | indent 8 }}
{{- end }}
env:
- name: "SELF_PORT"
value: {{ .Values.dbMigrationService.port | quote }}
- name: "RUN_DATABASE_MIGRATION_AS_SEPARATE_SERVICE"
value: "true"
{{- include "rasa-x.psql.envs" . | nindent 8 }}
{{- include "rasax.db-migration-service.extra.envs" . | nindent 8 }}
{{- with .Values.dbMigrationService.resources }}
resources:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- if .Values.dbMigrationService.extraVolumes }}
volumes:
{{ toYaml .Values.dbMigrationService.extraVolumes | indent 6 }}
{{- end }}
{{end}}
19 changes: 19 additions & 0 deletions charts/rasa-x/templates/db-migration-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{ if and (eq "true" (include "db-migration-service.requiredVersion" .)) .Values.separateDBMigrationService }}
apiVersion: "v1"
kind: "Service"
metadata:
name: {{ include "rasa-x.fullname" . }}-db-migration-service-headless
labels:
{{- include "rasa-x.labels" . | nindent 4 }}
app.kubernetes.io/component: db-migration-service
spec:
clusterIP: "None"
ports:
- port: {{ .Values.dbMigrationService.port }}
targetPort: {{ .Values.dbMigrationService.port }}
protocol: "TCP"
name: "http"
selector:
{{- include "rasa-x.selectorLabels" . | nindent 4 }}
app.kubernetes.io/component: db-migration-service
{{end}}
4 changes: 4 additions & 0 deletions charts/rasa-x/templates/event-service-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ spec:
tolerations:
{{ toYaml .Values.eventService.tolerations | indent 6 }}
{{- end }}
# Use the init-db init container to check if database migration is completed.
# The event service uses a database, to make sure that the database is ready
# to use we use the database migration service to check migration status.
{{- include "initContainer.dbMigration" . | nindent 6 }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.eventService.name }}:{{ .Values.eventService.tag | default (include "rasa-x.version" .) }}"
Expand Down
5 changes: 5 additions & 0 deletions charts/rasa-x/templates/rasa-deployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ spec:
tolerations:
{{ toYaml $.Values.rasa.tolerations | indent 6 }}
{{- end }}
# Use the init-db init container to check if database migration is completed.
# The rasa service depends on the rasa x server, to make sure that the database is ready
# and the rasa x server is fully operational we use the database migration service
# to check migration status.
{{- include "initContainer.dbMigration" $ | nindent 6 }}
containers:
- name: {{ $.Chart.Name }}
image: "{{ $.Values.rasa.name }}:{{ $.Values.rasa.tag }}"
Expand Down
2 changes: 2 additions & 0 deletions charts/rasa-x/templates/rasa-x-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ spec:
secretKeyRef:
name: {{ template "rasa-x.secret" . }}
key: "initialPassword"
- name: "RUN_DATABASE_MIGRATION_AS_SEPARATE_SERVICE"
value: {{ .Values.separateDBMigrationService | quote }}
{{- include "rasa-x.psql.envs" . | nindent 8 }}
{{- include "rasax.extra.envs" . | nindent 8 }}
volumeMounts:
Expand Down
53 changes: 53 additions & 0 deletions charts/rasa-x/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,55 @@ rasa:
# - name: tmpdir
# emptyDir: {}


# dbMigrationService specifies settings for the database migration service
# The database migration service requires Rasa X >= 0.33.0
dbMigrationService:
# initContainer describes settings related to the init-db container used as a init container for deployments
initContainer:
# image is the Docker image which is used by the init container
image: alpine:latest
# command overrides the default command to run in the container
command: []
# args overrides the default arguments to run in the container
args: []
# name is the Docker image name which is used by the migration service
name: "rasa/rasa-x" # gcr.io/rasa-platform/rasa-x-ee
# tag refers to the Rasa X image tag (uses `appVersion` by default)
tag: ""
# ignoreVersionCheck defines if check required minimum Rasa X version that is required to run the service
ignoreVersionCheck: false
# port on which which to run the readiness endpoint
port: 8000

# tolerations can be used to control the pod to node assignment
# https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
tolerations: []
# - key: "nvidia.com/gpu"
# operator: "Exists"

# nodeSelector to specify which node the pods should run on
# https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
nodeSelector: {}
# "beta.kubernetes.io/instance-type": "g3.8xlarge"

# resources which the event service is required / allowed to use
resources: {}
# extraEnvs are environment variables which can be added to the eventService deployment
extraEnvs: []
# - name: SOME_CUSTOM_ENV_VAR
# value: "custom value"

# extraVolumeMounts defines additional volumeMounts to the main container
extraVolumeMounts: []
# - name: tmpdir
# mountPath: /var/lib/mypath

# extraVolumes defines additional volumes to the pod
extraVolumes: []
# - name: tmpdir
# emptyDir: {}

# event-service specific settings
eventService:
# override the default command to run in the container
Expand Down Expand Up @@ -399,6 +448,10 @@ debugMode: false
# high-load setups).
separateEventService: "true"

# separateDBMigrationService value determines whether the dbMigrationService will be run as a separate service.
# If set to 'false', Rasa X will run a database migration service as a subprocess.
separateDBMigrationService: true

# postgresql specific settings (https://hub.helm.sh/charts/bitnami/postgresql/8.6.13)
postgresql:
# Install should be `true` if the postgres subchart should be used
Expand Down

0 comments on commit 0e21dd7

Please sign in to comment.