diff --git a/.github/helm/affine-cloud/.gitignore b/.github/helm/affine-cloud/.gitignore new file mode 100644 index 0000000000..711a39c541 --- /dev/null +++ b/.github/helm/affine-cloud/.gitignore @@ -0,0 +1 @@ +charts/ \ No newline at end of file diff --git a/.github/helm/affine-cloud/.helmignore b/.github/helm/affine-cloud/.helmignore index 0e8a0eb36f..691fa13d6a 100644 --- a/.github/helm/affine-cloud/.helmignore +++ b/.github/helm/affine-cloud/.helmignore @@ -20,4 +20,4 @@ .project .idea/ *.tmproj -.vscode/ +.vscode/ \ No newline at end of file diff --git a/.github/helm/affine-cloud/charts/postgresql-12.5.8.tgz b/.github/helm/affine-cloud/charts/postgresql-12.5.8.tgz deleted file mode 100644 index 1c2df40510..0000000000 Binary files a/.github/helm/affine-cloud/charts/postgresql-12.5.8.tgz and /dev/null differ diff --git a/.github/helm/affine-cloud/readme.md b/.github/helm/affine-cloud/readme.md new file mode 100644 index 0000000000..0cac15cf57 --- /dev/null +++ b/.github/helm/affine-cloud/readme.md @@ -0,0 +1,30 @@ +# Helm Chart Configuration + +The following table lists the configurable parameters of this Helm chart and their default values. + +## AFFiNE Cloud Server parameters + +| Parameter | Description | Default | +| ------------------------------ | -------------------------------------------------- | ------------------ | +| `affineCloud.tag` | The Docker tag of the AffineCloud image to be used | `'nightly-latest'` | +| `affineCloud.resources.cpu` | The CPU resources allocated for AffineCloud | `'250m'` | +| `affineCloud.resources.memory` | The memory resources allocated for AffineCloud | `'0.5Gi'` | +| `affineCloud.signKey` | The key used to sign the JWT tokens | `'c2VjcmV0'` | +| `affineCloud.service.type` | The type of the Kubernetes service | `'ClusterIP'` | +| `affineCloud.service.port` | The port of the Kubernetes service | `'http'` | +| `affineCloud.mail.account` | The email account used to send emails | `''` | +| `affineCloud.mail.password` | The password of the email account | `''` | + +## PostgreSQL parameters + +| Parameter | Description | Default | +| -------------------------------------------- | ------------------------------------------------------------------------------------- | ------------ | +| `postgresql.auth.username` | Username for the PostgreSQL database | `'affine'` | +| `postgresql.auth.password` | Password for the PostgreSQL database. Please change this for production environments. | `'password'` | +| `postgresql.auth.database` | The name of the default database that will be created on image startup | `'affine'` | +| `postgresql.primary.resources.limits.cpu` | The CPU resources allocated for the PostgreSQL primary node | `'500m'` | +| `postgresql.primary.resources.limits.memory` | The memory resources allocated for the PostgreSQL primary node | `'0.5Gi'` | + +For more postgres parameters, please refer to: https://artifacthub.io/packages/helm/bitnami/postgresql + +Please note that for the `postgresql.auth.password`, you should provide your own password for production environments. The default value is provided only for demonstration purposes. diff --git a/.github/helm/affine-cloud/templates/_helper.tpl b/.github/helm/affine-cloud/templates/_helper.tpl new file mode 100644 index 0000000000..06a02feb84 --- /dev/null +++ b/.github/helm/affine-cloud/templates/_helper.tpl @@ -0,0 +1,51 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "affine-cloud.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "affine-cloud.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "affine-cloud.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "affine-cloud.labels" -}} +helm.sh/chart: {{ include "affine-cloud.chart" . }} +{{ include "affine-cloud.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "affine-cloud.selectorLabels" -}} +app.kubernetes.io/name: {{ include "affine-cloud.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/.github/helm/affine-cloud/templates/deployment.yaml b/.github/helm/affine-cloud/templates/deployment.yaml index 37acfc45fa..842e9ab63c 100644 --- a/.github/helm/affine-cloud/templates/deployment.yaml +++ b/.github/helm/affine-cloud/templates/deployment.yaml @@ -1,7 +1,9 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: affine-cloud + name: "{{ include "affine-cloud.fullname" . }}" + labels: + {{- include "affine-cloud.labels" . | nindent 4 }} spec: replicas: 1 selector: @@ -30,7 +32,7 @@ spec: - name: PG_HOST value: "{{ .Release.Name }}-postgresql" - name: DATABASE_URL - value: "{{ default "postgresql://$(PG_USER):$(PG_PASS)@$(PG_HOST)/$(PG_DATABASE)" .Values.affineCloud.databaseUrl }}" + value: "{{ .Values.affineCloud.databaseUrl | default "postgresql://$(PG_USER):$(PG_PASS)@$(PG_HOST)/$(PG_DATABASE)" }}" envFrom: - secretRef: name: affine-cloud-secret diff --git a/.github/helm/affine-cloud/templates/secret.yaml b/.github/helm/affine-cloud/templates/secret.yaml index 170a5b90d1..f6879af5e8 100644 --- a/.github/helm/affine-cloud/templates/secret.yaml +++ b/.github/helm/affine-cloud/templates/secret.yaml @@ -4,7 +4,6 @@ metadata: name: affine-cloud-secret type: Opaque data: - # only for demo, please modify it at prod env - SIGN_KEY: TUFtdFdzQTJhdGJuem01TA== -# MAIL_ACCOUNT: XXXX -# MAIL_PASSWORD: XXXX + SIGN_KEY: "{{ .Values.affineCloud.signKey }}" + MAIL_ACCOUNT: "{{ .Values.affineCloud.mail.account }}" + MAIL_PASSWORD: "{{ .Values.affineCloud.mail.password }}" diff --git a/.github/helm/affine-cloud/templates/services.yaml b/.github/helm/affine-cloud/templates/services.yaml index ec0b2f8c72..2529d4569d 100644 --- a/.github/helm/affine-cloud/templates/services.yaml +++ b/.github/helm/affine-cloud/templates/services.yaml @@ -1,13 +1,15 @@ apiVersion: v1 kind: Service metadata: - name: affine-cloud + name: "{{ include "affine-cloud.fullname" . }}" + labels: + {{- include "affine-cloud.labels" . | nindent 4 }} spec: - type: ClusterIP - selector: - app: affine-cloud + type: "{{ .Values.affineCloud.service.type }}" ports: - - name: affine-cloud + - name: http protocol: TCP - port: 3000 + port: {{ .Values.affineCloud.service.port }} targetPort: 3000 + selector: + {{- include "affine-cloud.selectorLabels" . | nindent 4 }} diff --git a/.github/helm/affine-cloud/values.yaml b/.github/helm/affine-cloud/values.yaml index e1bad387ea..582dee709a 100644 --- a/.github/helm/affine-cloud/values.yaml +++ b/.github/helm/affine-cloud/values.yaml @@ -1,5 +1,13 @@ affineCloud: tag: 'nightly-latest' + # databaseUrl: 'postgresql://affine:password@affine-cloud-postgresql:5432/affine' + signKey: TUFtdFdzQTJhdGJuem01TA== + mail: + account: '' + password: '' + service: + type: ClusterIP + port: 80 resources: cpu: '250m' memory: 0.5Gi @@ -7,7 +15,7 @@ postgresql: auth: # only for demo, please modify it at prod env username: affine - password: XJYMLnuBJS27a2du + password: password database: affine primary: initdb: diff --git a/.github/workflows/helm_releaser.yml b/.github/workflows/helm-releaser.yml similarity index 90% rename from .github/workflows/helm_releaser.yml rename to .github/workflows/helm-releaser.yml index 890c46f98d..b85972e47d 100644 --- a/.github/workflows/helm_releaser.yml +++ b/.github/workflows/helm-releaser.yml @@ -39,19 +39,23 @@ jobs: - name: Package charts working-directory: .helm-chart-repo run: | - set -ex - git config --local user.name "$GITHUB_ACTOR" - git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" mkdir -p .cr-index - owner=$(cut -d '/' -f 1 <<< '${{ github.repository }}') - repo=helm-charts - git_hash=$(git rev-parse HEAD) - echo $git_hash - helm repo add bitnami https://charts.bitnami.com/bitnami helm repo update + helm dependencies build ../.github/helm/affine-cloud cr package ../.github/helm/affine-cloud + + - name: Package charts + if: github.ref == 'refs/heads/master' + working-directory: .helm-chart-repo + run: | + set -ex + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + owner=$(cut -d '/' -f 1 <<< '${{ github.repository }}') + repo=helm-charts + git_hash=$(git rev-parse HEAD) cr upload --commit "$git_hash" \ --git-repo "$repo" --owner "$owner" \ --token '${{ secrets.HELM_RELEASER_TOKEN }}' \