Skip to content

Commit

Permalink
#88 [FEATURE] Dify - support changing STORAGE_TYPE env value (#89)
Browse files Browse the repository at this point in the history
* chore: 🙈 ignore vscode files

* feat: ✨ allow change STORAGE_TYPE

* refactor: ♻️ format, add types

* fix: 🐛 storageType as global env

fix potential breaking change

* chore: 🔖 bump chart & app

* docs: 📝 fix readme about storage type

* chore: 🔖 bump app version
  • Loading branch information
deoomen authored Jun 17, 2024
1 parent 164332b commit 69c84f8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Helm chart automated files
/charts/*/charts
.idea
.vscode
4 changes: 2 additions & 2 deletions charts/dify/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.3.6
version: 0.4.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.6.9"
appVersion: "0.6.11"

dependencies:
- name: redis
Expand Down
62 changes: 47 additions & 15 deletions charts/dify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,55 @@ minio:
embedded: true
```
```
```sh
# install it
helm repo add douban https://douban.github.io/charts/
helm upgrade dify douban/dify -f values.yaml --install --debug
```

**Must** run db migration after installation, or the instance would not work.
```

```sh
# run migration
kubectl exec -it dify-pod-name -- flask db upgrade
```

## Upgrade

To upgrade app, change the value of `global.image.tag` to the desired version
```

```yaml
global:
image:
tag: "0.6.3"
```
Then upgrade the app with helm command
```
Then upgrade the app with helm command
```sh
helm upgrade dify douban/dify -f values.yaml --debug
```

**Must** run db migration after upgrade.
```

```sh
# run migration
kubectl exec -it dify-pod-name -- flask db upgrade
```

## Production use checklist

The minimal configure provided above is sufficient for experiment but **without any persistance**, all your data would be lost if you restarted the postgresql pod or minio pod!!

You **must do** the following extra work before put it into production!!


### Protect Sensitive info with secret

Environment variable like `SECRET_KEY` could be harmful if leaked, it is adviced to protect them using secret or csi volume.

The example of using secret is like
```
The example of using secret is like

```yaml
global:
extraBackendEnvs:
- name: SECRET_KEY
Expand All @@ -84,14 +92,14 @@ global:
key: SECRET_KEY
```
Read more: https://kubernetes.io/docs/concepts/security/secrets-good-practices/
Read more: <https://kubernetes.io/docs/concepts/security/secrets-good-practices/>
### External postgresql
1. set the `postgresql.embedded` to `false`
2. inject connection info with `global.extraBackendEnvs`

```
```yaml
global:
extraBackendEnvs:
- name: DB_USERNAME
Expand All @@ -111,9 +119,11 @@ global:
```

### External redis

1. set the `redis.embedded` to `false`
2. inject connection info with `global.extraBackendEnvs`
```

```yaml
global:
extraBackendEnvs:
- name: REDIS_HOST
Expand All @@ -135,12 +145,16 @@ global:
key: CELERY_BROKER_URL
```

### External s3 bucket
### External bucket

#### Amazon S3

1. set the `minio.embedded` to `false`
2. inject connection info with `global.extraBackendEnvs`

```
```yaml
global:
storageType: "s3"
extraBackendEnvs:
- name: S3_ENDPOINT
value: "https://my-endpoint.s3.com"
Expand All @@ -159,11 +173,29 @@ global:
key: S3_SECRET_KEY
```

#### Google Cloud Storage

1. set the `minio.embedded` to `false`
2. inject connection info with `global.extraBackendEnvs`

```yaml
global:
storageType: "google-storage"
extraBackendEnvs:
- name: GOOGLE_STORAGE_BUCKET_NAME
value: "bucket-name"
- name: GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64
valueFrom:
secretKeyRef:
name: dify-secret
key: GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64
```

### Setup vector db

due to the complexity of vector db, this component is not included, you have to use external vector db, likewise , you can inject environment variable to use it

```
```yaml
global:
extraBackendEnvs:
- name: VECTOR_STORE
Expand Down
6 changes: 3 additions & 3 deletions charts/dify/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Create the name of the service account to use
{{/*
dify environments
commonEnvs are for all containers
commonBackendEnvs are for api and worker containers
commonBackendEnvs are for api and worker containers
*/}}
{{- define "dify.commonEnvs" -}}
- name: EDITION
Expand All @@ -81,6 +81,8 @@ commonBackendEnvs are for api and worker containers


{{- define "dify.commonBackendEnvs" -}}
- name: STORAGE_TYPE
value: {{ .Values.global.storageType }}
{{- if .Values.redis.embedded }}
- name: CELERY_BROKER_URL
value: redis://:{{ .Values.redis.auth.password }}@{{ include "dify.fullname" . }}-redis-master:6379/1
Expand All @@ -103,8 +105,6 @@ commonBackendEnvs are for api and worker containers
- name: DB_DATABASE
value: {{ .Values.postgresql.auth.database }}
{{- end }}
- name: STORAGE_TYPE
value: "s3"

{{- if .Values.minio.embedded }}
- name: S3_ENDPOINT
Expand Down
1 change: 1 addition & 0 deletions charts/dify/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ global:
image:
tag: ""
edition: "SELF_HOSTED"
storageType: "s3"
# the following extra configs would be injected into:
# * frontend
# * api
Expand Down

0 comments on commit 69c84f8

Please sign in to comment.