From 2180258b545e6e502fdf9bae0df4fe1fa2026b2c Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 26 Oct 2022 10:56:55 +0800
Subject: [PATCH 01/36] chore(database): add init database configure

---
 charts/database/templates/_helper.tpl         | 2 ++
 charts/database/values.yaml                   | 1 +
 rootfs/usr/share/scripts/patroni/post_init.sh | 9 +++++----
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/charts/database/templates/_helper.tpl b/charts/database/templates/_helper.tpl
index 0cf961a..0e64d33 100644
--- a/charts/database/templates/_helper.tpl
+++ b/charts/database/templates/_helper.tpl
@@ -36,6 +36,8 @@ env:
   value: '0.0.0.0:5432'
 - name: PATRONI_RESTAPI_LISTEN
   value: '0.0.0.0:8008'
+- name: "DRYCC_DATABASE_INIT_NAMES"
+  value: "{{.Values.initDatabases}}"
 - name: DRYCC_DATABASE_SUPERUSER
   valueFrom:
     secretKeyRef:
diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index 08cd8cd..cb5d397 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -56,6 +56,7 @@ replicator: "standby"
 replicatorPassword: ""
 user: ""
 password: ""
+initDatabases: "controller,passport"
 
 global:
   # Set the location of Workflow's Object Storage
diff --git a/rootfs/usr/share/scripts/patroni/post_init.sh b/rootfs/usr/share/scripts/patroni/post_init.sh
index 90478b1..d6c88fe 100755
--- a/rootfs/usr/share/scripts/patroni/post_init.sh
+++ b/rootfs/usr/share/scripts/patroni/post_init.sh
@@ -5,10 +5,11 @@ if [[ ( -n "$DRYCC_DATABASE_USER") &&  ( -n "$DRYCC_DATABASE_PASSWORD")]]; then
   echo "Creating user ${DRYCC_DATABASE_USER}"
   psql "$1" -w -c "create user ${DRYCC_DATABASE_USER} WITH LOGIN ENCRYPTED PASSWORD '${DRYCC_DATABASE_PASSWORD}'"
 
-  echo "Creating passport and controller databases"
-  psql "$1" -w -c "CREATE DATABASE passport OWNER ${DRYCC_DATABASE_USER}"
-  psql "$1" -w -c "CREATE DATABASE controller OWNER ${DRYCC_DATABASE_USER}"
-
+  for dbname in ${DRYCC_DATABASE_INIT_NAMES//,/ }
+  do
+    echo "Creating database ${dbname}"
+    psql "$1" -w -c "CREATE DATABASE ${dbname} OWNER ${DRYCC_DATABASE_USER}"
+  done
 else
   echo "Skipping user creation"
   echo "Skipping database creation"

From 13eb7262b91f6c11b40226cac4fc79ac32e5ab65 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 26 Oct 2022 17:03:00 +0800
Subject: [PATCH 02/36] chore(database): use dynamic clusterrole name

---
 charts/database/templates/database-clusterrole.yaml        | 2 +-
 charts/database/templates/database-clusterrolebinding.yaml | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/charts/database/templates/database-clusterrole.yaml b/charts/database/templates/database-clusterrole.yaml
index 11b2f70..7fc3898 100644
--- a/charts/database/templates/database-clusterrole.yaml
+++ b/charts/database/templates/database-clusterrole.yaml
@@ -2,7 +2,7 @@
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRole
 metadata:
-  name: drycc-database
+  name: {{ printf "%s:drycc-database" .Release.Namespace | quote }}
 rules:
 - apiGroups:
   - ""
diff --git a/charts/database/templates/database-clusterrolebinding.yaml b/charts/database/templates/database-clusterrolebinding.yaml
index 11877bc..6db4596 100644
--- a/charts/database/templates/database-clusterrolebinding.yaml
+++ b/charts/database/templates/database-clusterrolebinding.yaml
@@ -2,11 +2,11 @@
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRoleBinding
 metadata:
-  name: drycc-database
+  name: {{ printf "%s:drycc-database" .Release.Namespace | quote }}
 roleRef:
   apiGroup: rbac.authorization.k8s.io
   kind: ClusterRole
-  name: drycc-database
+  name: {{ printf "%s:drycc-database" .Release.Namespace | quote }}
 subjects:
 - kind: ServiceAccount
   name: drycc-database

From 453738106cde52f4fc65fadead424c237902ce68 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Fri, 28 Oct 2022 13:26:06 +0800
Subject: [PATCH 03/36] chore(database): remove minio require

---
 charts/database/templates/_helper.tpl               |  7 -------
 charts/database/templates/database-statefulset.yaml | 12 ------------
 2 files changed, 19 deletions(-)

diff --git a/charts/database/templates/_helper.tpl b/charts/database/templates/_helper.tpl
index 0e64d33..7135587 100644
--- a/charts/database/templates/_helper.tpl
+++ b/charts/database/templates/_helper.tpl
@@ -68,13 +68,6 @@ env:
     secretKeyRef:
       name: database-creds
       key: password
-{{- if eq .Values.global.storageLocation "on-cluster" }}
-- name: "DRYCC_STORAGE_HEALTH"
-  valueFrom:
-    secretKeyRef:
-      name: storage-creds
-      key: health
-{{- end }}
 {{- end }}
 
 {{/* Generate database deployment limits */}}
diff --git a/charts/database/templates/database-statefulset.yaml b/charts/database/templates/database-statefulset.yaml
index 61280d0..f410b15 100644
--- a/charts/database/templates/database-statefulset.yaml
+++ b/charts/database/templates/database-statefulset.yaml
@@ -25,18 +25,6 @@ spec:
         podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset.type "key" .Values.podAntiAffinityPreset.key "values" .Values.podAntiAffinityPreset.values ) | nindent 10 }}
         nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values ) | nindent 10 }}
       serviceAccountName: drycc-database
-      {{- if eq .Values.global.storageLocation "on-cluster" }}
-      initContainers:
-      - name: drycc-database-init
-        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/python-dev:latest
-        imagePullPolicy: {{.Values.imagePullPolicy}}
-        args:
-          - netcat
-          - -v
-          - -g
-          - $(DRYCC_STORAGE_HEALTH)
-        {{- include "database.envs" . | indent 8 }}
-      {{- end }}
       containers:
       - name: drycc-database
         image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/postgres:{{.Values.imageTag}}

From f02551c22c880b3985fe89035570c240075a77bd Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Fri, 10 Feb 2023 14:34:08 +0800
Subject: [PATCH 04/36] chore(database): use woodpecker replace drone

---
 .drone/drone.yml                              | 142 ------------------
 .drone/manifest.tmpl                          |  18 ---
 .woodpecker/build-linux.yml                   |  29 ++++
 .woodpecker/chart.yaml                        |  28 ++++
 .woodpecker/manifest.tmpl                     |  18 +++
 .woodpecker/manifest.yml                      |  38 +++++
 .woodpecker/test-linux.yml                    |  21 +++
 Makefile                                      |   2 +-
 README.md                                     |   2 +-
 charts/database/Chart.yaml                    |   2 +-
 .../templates/database-statefulset.yaml       |   2 +-
 11 files changed, 138 insertions(+), 164 deletions(-)
 delete mode 100644 .drone/drone.yml
 delete mode 100644 .drone/manifest.tmpl
 create mode 100644 .woodpecker/build-linux.yml
 create mode 100644 .woodpecker/chart.yaml
 create mode 100644 .woodpecker/manifest.tmpl
 create mode 100644 .woodpecker/manifest.yml
 create mode 100644 .woodpecker/test-linux.yml

diff --git a/.drone/drone.yml b/.drone/drone.yml
deleted file mode 100644
index aa10b18..0000000
--- a/.drone/drone.yml
+++ /dev/null
@@ -1,142 +0,0 @@
-kind: pipeline
-type: exec
-name: linux-amd64
-
-platform:
-  arch: amd64
-  os: linux
-
-steps:
-- name: test
-  commands:
-  - mkdir -p $HOMEPATH/.docker; echo $IMAGE_PULL_SECRETS > $HOMEPATH/.docker/config.json
-  - make docker-build test
-  environment:
-    VERSION: ${DRONE_TAG:-latest}-linux-amd64
-    DEV_REGISTRY:
-      from_secret: dev_registry
-    DRYCC_REGISTRY:
-      from_secret: drycc_registry
-    IMAGE_PULL_SECRETS:
-      from_secret: container_pull_secrets
-  when:
-    event:
-    - push
-    - tag
-    - pull_request
-
-- name: publish
-  commands:
-  - echo $CONTAINER_PASSWORD | docker login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
-  - make docker-build docker-immutable-push
-  environment:
-    VERSION: ${DRONE_TAG:-latest}-linux-amd64
-    DEV_REGISTRY:
-      from_secret: dev_registry
-    DRYCC_REGISTRY:
-      from_secret: drycc_registry
-    CONTAINER_USERNAME:
-      from_secret: container_username
-    CONTAINER_PASSWORD:
-      from_secret: container_password
-  when:
-    event:
-    - push
-    - tag
-
----
-kind: pipeline
-type: exec
-name: linux-arm64
-
-platform:
-  arch: arm64
-  os: linux
-
-steps:
-- name: publish
-  commands:
-  - echo $CONTAINER_PASSWORD | docker login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
-  - make docker-build docker-immutable-push
-  environment:
-    VERSION: ${DRONE_TAG:-latest}-linux-arm64
-    DEV_REGISTRY:
-      from_secret: dev_registry
-    DRYCC_REGISTRY:
-      from_secret: drycc_registry
-    CONTAINER_USERNAME:
-      from_secret: container_username
-    CONTAINER_PASSWORD:
-      from_secret: container_password
-  when:
-    event:
-    - push
-    - tag
-
----
-kind: pipeline
-type: docker
-name: manifest
-image_pull_secrets:
-- container_pull_secrets
-
-steps:
-
-- name: generate manifest
-  image: registry.drycc.cc/drycc/python-dev
-  pull: always
-  commands:
-  - sed -i "s/registry.drycc.cc/$${DRYCC_REGISTRY}/g" .drone/manifest.tmpl
-  environment:
-    DEV_REGISTRY:
-      from_secret: dev_registry
-    DRYCC_REGISTRY:
-      from_secret: drycc_registry
-
-- name: publish
-  image: plugins/manifest
-  settings:
-    spec: .drone/manifest.tmpl
-    username:
-      from_secret: container_username
-    password:
-      from_secret: container_password
-  environment:
-    DEV_REGISTRY:
-      from_secret: dev_registry
-    DRYCC_REGISTRY:
-      from_secret: drycc_registry
-
-trigger:
-  event:
-  - push
-  - tag
-
-depends_on:
-- linux-amd64
-- linux-arm64
-
----
-kind: pipeline
-type: exec
-name: chart
-
-steps:
-- name: generate chart
-  commands:
-  - IMAGE_TAG=$([ ! -z $DRONE_TAG ] && echo \"${DRONE_TAG:1}\" || echo \"canary\")
-  - sed -i "s/imageTag:\ \"canary\"/imageTag:\ $IMAGE_TAG/g" charts/database/values.yaml
-  - helm package -u charts/database --version $([ -z $DRONE_TAG ] && echo 1.0.0 || echo ${DRONE_TAG#v})
-  - echo $CONTAINER_PASSWORD | helm registry login $DRYCC_REGISTRY -u $CONTAINER_USERNAME --password-stdin
-  - helm push database-$([ -z $DRONE_TAG ] && echo 1.0.0 || echo ${DRONE_TAG#v}).tgz oci://$DRYCC_REGISTRY/$([ -z $DRONE_TAG ] && echo charts-testing || echo charts)
-  environment:
-    DRYCC_REGISTRY:
-      from_secret: drycc_registry
-    CONTAINER_USERNAME:
-      from_secret: container_username
-    CONTAINER_PASSWORD:
-      from_secret: container_password
-  when:
-    event:
-    - push
-    - tag
diff --git a/.drone/manifest.tmpl b/.drone/manifest.tmpl
deleted file mode 100644
index 0182d12..0000000
--- a/.drone/manifest.tmpl
+++ /dev/null
@@ -1,18 +0,0 @@
-image: registry.drycc.cc/drycc/postgres:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}canary{{/if}}
-{{#if build.tags}}
-tags:
-{{#each build.tags}}
-  - {{this}}
-{{/each}}
-{{/if}}
-manifests:
-  -
-    image: registry.drycc.cc/drycc/postgres:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-amd64
-    platform:
-      architecture: amd64
-      os: linux
-  -
-    image: registry.drycc.cc/drycc/postgres:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-arm64
-    platform:
-      architecture: arm64
-      os: linux
diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
new file mode 100644
index 0000000..a345874
--- /dev/null
+++ b/.woodpecker/build-linux.yml
@@ -0,0 +1,29 @@
+matrix:
+  platform:
+    - linux/amd64
+    - linux/arm64
+
+platform: ${platform}
+
+labels:
+  type: exec
+
+pipeline:
+- name: publish-linux
+  image: bash
+  commands:
+  - export VERSION=$([ -z $CI_COMMIT_TAG ] && echo latest || echo $CI_COMMIT_TAG)-$(sed 's#/#-#g' <<< $CI_SYSTEM_ARCH)
+  - echo $CONTAINER_PASSWORD | docker login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
+  - make docker-build docker-immutable-push
+  secrets:
+  - dev_registry
+  - drycc_registry
+  - container_username
+  - container_password
+  when:
+    event:
+    - push
+    - tag
+
+depends_on:
+- test-linux
\ No newline at end of file
diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
new file mode 100644
index 0000000..bfecf10
--- /dev/null
+++ b/.woodpecker/chart.yaml
@@ -0,0 +1,28 @@
+platform: linux/amd64
+
+labels:
+  type: exec
+
+pipeline:
+- name: generate-chart
+  type: local
+  image: bash
+  commands:
+  - export VERSION=$(sed 's#v##' <<< $CI_COMMIT_TAG)
+  - export IMAGE_TAG=$([ ! -z $CI_COMMIT_TAG ] && echo \"$VERSION\" || echo \"canary\")
+  - sed -i "s/imageTag:\ \"canary\"/imageTag:\ $IMAGE_TAG/g" charts/$${CI_REPO_NAME}/values.yaml
+  - helm package -u charts/$${CI_REPO_NAME} --version $([ -z $CI_COMMIT_TAG ] && echo 1.0.0 || echo $VERSION)
+  - echo $CONTAINER_PASSWORD | helm registry login $DRYCC_REGISTRY -u $CONTAINER_USERNAME --password-stdin
+  - helm push $${CI_REPO_NAME}-$([ -z $CI_COMMIT_TAG ] && echo 1.0.0 || echo $VERSION).tgz oci://$DRYCC_REGISTRY/$([ -z $CI_COMMIT_TAG ] && echo charts-testing || echo charts)
+  secrets:
+  - dev_registry
+  - drycc_registry
+  - container_username
+  - container_password
+  when:
+    event:
+    - push
+    - tag
+
+depends_on:
+- manifest
\ No newline at end of file
diff --git a/.woodpecker/manifest.tmpl b/.woodpecker/manifest.tmpl
new file mode 100644
index 0000000..8739535
--- /dev/null
+++ b/.woodpecker/manifest.tmpl
@@ -0,0 +1,18 @@
+image: registry.drycc.cc/drycc/{{project}}:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}canary{{/if}}
+{{#if build.tags}}
+tags:
+{{#each build.tags}}
+  - {{this}}
+{{/each}}
+{{/if}}
+manifests:
+  -
+    image: registry.drycc.cc/drycc/{{project}}:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-amd64
+    platform:
+      architecture: amd64
+      os: linux
+  -
+    image: registry.drycc.cc/drycc/{{project}}:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-arm64
+    platform:
+      architecture: arm64
+      os: linux
diff --git a/.woodpecker/manifest.yml b/.woodpecker/manifest.yml
new file mode 100644
index 0000000..f7023ff
--- /dev/null
+++ b/.woodpecker/manifest.yml
@@ -0,0 +1,38 @@
+platform: linux/amd64
+
+labels:
+  type: exec
+
+pipeline:
+- name: generate-manifest
+  image: bash
+  commands:
+  - sed -i "s/{{project}}/$${CI_REPO_NAME}/g" .woodpecker/manifest.tmpl
+  - sed -i "s/registry.drycc.cc/$${DRYCC_REGISTRY}/g" .woodpecker/manifest.tmpl
+  secrets:
+  - drycc_registry
+  when:
+    event:
+    - tag
+    - push
+
+- name: publish-manifest
+  image: bash
+  commands:
+  - docker run --rm
+    -e PLUGIN_SPEC=.woodpecker/manifest.tmpl
+    -e PLUGIN_USERNAME=$CONTAINER_USERNAME
+    -e PLUGIN_PASSWORD=$CONTAINER_PASSWORD
+    -v $(pwd):$(pwd)
+    -w $(pwd)
+    plugins/manifest
+  secrets:
+  - container_username
+  - container_password
+  when:
+    event:
+    - tag
+    - push
+
+depends_on:
+- build-linux
diff --git a/.woodpecker/test-linux.yml b/.woodpecker/test-linux.yml
new file mode 100644
index 0000000..d736541
--- /dev/null
+++ b/.woodpecker/test-linux.yml
@@ -0,0 +1,21 @@
+matrix:
+  platform:
+  - linux/amd64
+  - linux/arm64
+
+platform: ${platform}
+
+labels:
+  type: exec
+
+pipeline:
+- name: test-linux
+  image: bash
+  commands:
+  - make test
+  secrets:
+  - dev_registry
+  when:
+    event:
+    - push
+    - tag
diff --git a/Makefile b/Makefile
index 5eaa3de..0e70795 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 # Some uses for short name:
 # - Docker image name
 # - Kubernetes service, rc, pod, secret, volume names
-SHORT_NAME := postgres
+SHORT_NAME := database
 DRYCC_REGISTRY ?= ${DEV_REGISTRY}
 IMAGE_PREFIX ?= drycc
 PLATFORM ?= linux/amd64,linux/arm64
diff --git a/README.md b/README.md
index fa2c5a5..4e029b6 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 
 # Drycc Postgres
-[![Build Status](https://drone.drycc.cc/api/badges/drycc/postgres/status.svg)](https://drone.drycc.cc/drycc/postgres)
+[![Build Status](https://woodpecker.drycc.cc/api/badges/drycc/database/status.svg)](https://woodpecker.drycc.cc/drycc/database)
 
 Drycc (pronounced DAY-iss) Workflow is an open source Platform as a Service (PaaS) that adds a developer-friendly layer to any [Kubernetes](http://kubernetes.io) cluster, making it easy to deploy and manage applications on your own servers.
 
diff --git a/charts/database/Chart.yaml b/charts/database/Chart.yaml
index 0ec5901..dca398c 100644
--- a/charts/database/Chart.yaml
+++ b/charts/database/Chart.yaml
@@ -4,7 +4,7 @@ dependencies:
   - name: common
     repository: oci://registry.drycc.cc/charts
     version: ~1.1.1
-home: https://github.com/drycc/postgres
+home: https://github.com/drycc/database
 version: v1.1.0
 description: A PostgreSQL database used by Drycc Workflow.
 keywords:
diff --git a/charts/database/templates/database-statefulset.yaml b/charts/database/templates/database-statefulset.yaml
index f410b15..e36da25 100644
--- a/charts/database/templates/database-statefulset.yaml
+++ b/charts/database/templates/database-statefulset.yaml
@@ -27,7 +27,7 @@ spec:
       serviceAccountName: drycc-database
       containers:
       - name: drycc-database
-        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/postgres:{{.Values.imageTag}}
+        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/database:{{.Values.imageTag}}
         imagePullPolicy: {{.Values.imagePullPolicy}}
         ports:
         - containerPort: 8008

From f896caedd33ff951446922efb1329a3a86765f15 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Fri, 24 Mar 2023 13:52:38 +0800
Subject: [PATCH 05/36] fix(database): manifest error

---
 .woodpecker/manifest.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.woodpecker/manifest.yml b/.woodpecker/manifest.yml
index f7023ff..7f6ec36 100644
--- a/.woodpecker/manifest.yml
+++ b/.woodpecker/manifest.yml
@@ -23,6 +23,7 @@ pipeline:
     -e PLUGIN_SPEC=.woodpecker/manifest.tmpl
     -e PLUGIN_USERNAME=$CONTAINER_USERNAME
     -e PLUGIN_PASSWORD=$CONTAINER_PASSWORD
+    -e DRONE_TAG=$CI_COMMIT_TAG
     -v $(pwd):$(pwd)
     -w $(pwd)
     plugins/manifest

From 04d387cff761b470f82a00878598a9a99d987d9e Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 9 May 2023 14:22:41 +0800
Subject: [PATCH 06/36] fix(database): label conflict error


From 94fefaa3be9c00a22726177a6de35f45a7dae9a3 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 31 May 2023 12:35:40 +0800
Subject: [PATCH 07/36] chore(database): add chart appVersion

---
 .woodpecker/chart.yaml     | 6 ++++--
 charts/database/Chart.yaml | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
index bfecf10..3204cf5 100644
--- a/.woodpecker/chart.yaml
+++ b/.woodpecker/chart.yaml
@@ -10,10 +10,12 @@ pipeline:
   commands:
   - export VERSION=$(sed 's#v##' <<< $CI_COMMIT_TAG)
   - export IMAGE_TAG=$([ ! -z $CI_COMMIT_TAG ] && echo \"$VERSION\" || echo \"canary\")
+  - export APP_VERSION=$([ ! -z $CI_COMMIT_TAG ] && echo $VERSION || echo 1.0.0)
+  - export CHART_VERSION=$([ -z $CI_COMMIT_TAG ] && echo 1.0.0 || echo $VERSION)
   - sed -i "s/imageTag:\ \"canary\"/imageTag:\ $IMAGE_TAG/g" charts/$${CI_REPO_NAME}/values.yaml
-  - helm package -u charts/$${CI_REPO_NAME} --version $([ -z $CI_COMMIT_TAG ] && echo 1.0.0 || echo $VERSION)
+  - helm package -u charts/$${CI_REPO_NAME} --version $CHART_VERSION --app-version $APP_VERSION
   - echo $CONTAINER_PASSWORD | helm registry login $DRYCC_REGISTRY -u $CONTAINER_USERNAME --password-stdin
-  - helm push $${CI_REPO_NAME}-$([ -z $CI_COMMIT_TAG ] && echo 1.0.0 || echo $VERSION).tgz oci://$DRYCC_REGISTRY/$([ -z $CI_COMMIT_TAG ] && echo charts-testing || echo charts)
+  - helm push $${CI_REPO_NAME}-$CHART_VERSION.tgz oci://$DRYCC_REGISTRY/$([ -z $CI_COMMIT_TAG ] && echo charts-testing || echo charts)
   secrets:
   - dev_registry
   - drycc_registry
diff --git a/charts/database/Chart.yaml b/charts/database/Chart.yaml
index dca398c..139f3eb 100644
--- a/charts/database/Chart.yaml
+++ b/charts/database/Chart.yaml
@@ -1,5 +1,6 @@
 name: database
 apiVersion: v2
+appVersion: 1.0.0
 dependencies:
   - name: common
     repository: oci://registry.drycc.cc/charts

From b6783f3cfabfb9732d79554c1c058ae0cd8c8838 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 19 Jun 2023 16:08:56 +0800
Subject: [PATCH 08/36] chore(database): upgrade codename to bookworm

---
 Dockerfile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 60fd030..3301d47 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,10 +1,10 @@
-FROM registry.drycc.cc/drycc/base:bullseye
+FROM registry.drycc.cc/drycc/base:bookworm
 
 COPY rootfs/usr /usr/
 COPY rootfs/entrypoint.sh /entrypoint.sh
-ENV PYTHON_VERSION="3.10.6" \
+ENV PYTHON_VERSION="3.11" \
   PG_MAJOR=14 \
-  POSTGRESQL_VERSION="14.5"
+  POSTGRESQL_VERSION="15.3"
 
 ENV PGDATA /data/${PG_MAJOR}
 

From e2699380e63261e442a4a21cfde035dcb1e1e657 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 20 Jun 2023 15:54:50 +0800
Subject: [PATCH 09/36] chore(database): add codename build-arg

---
 .woodpecker/build-linux.yml | 1 +
 .woodpecker/test-linux.yml  | 1 +
 Dockerfile                  | 3 ++-
 Makefile                    | 4 ++--
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
index a345874..db9ad17 100644
--- a/.woodpecker/build-linux.yml
+++ b/.woodpecker/build-linux.yml
@@ -16,6 +16,7 @@ pipeline:
   - echo $CONTAINER_PASSWORD | docker login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
   - make docker-build docker-immutable-push
   secrets:
+  - codename
   - dev_registry
   - drycc_registry
   - container_username
diff --git a/.woodpecker/test-linux.yml b/.woodpecker/test-linux.yml
index d736541..313179e 100644
--- a/.woodpecker/test-linux.yml
+++ b/.woodpecker/test-linux.yml
@@ -14,6 +14,7 @@ pipeline:
   commands:
   - make test
   secrets:
+  - codename
   - dev_registry
   when:
     event:
diff --git a/Dockerfile b/Dockerfile
index 3301d47..87cac65 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,5 @@
-FROM registry.drycc.cc/drycc/base:bookworm
+ARG CODENAME
+FROM registry.drycc.cc/drycc/base:${CODENAME}
 
 COPY rootfs/usr /usr/
 COPY rootfs/entrypoint.sh /entrypoint.sh
diff --git a/Makefile b/Makefile
index 0e70795..ed4a626 100644
--- a/Makefile
+++ b/Makefile
@@ -23,11 +23,11 @@ all: docker-build docker-push
 # For cases where we're building from local
 # We also alter the RC file to set the image name.
 docker-build:
-	docker build ${DOCKER_BUILD_FLAGS} -t ${IMAGE} .
+	docker build ${DOCKER_BUILD_FLAGS} --build-arg CODENAME=${CODENAME} -t ${IMAGE} .
 	docker tag ${IMAGE} ${MUTABLE_IMAGE}
 
 docker-buildx:
-	docker buildx build --platform ${PLATFORM} -t ${IMAGE} . --push
+	docker buildx build --build-arg CODENAME=${CODENAME} --platform ${PLATFORM} -t ${IMAGE} . --push
 
 test: test-style
 

From eb99ebd03abf30d95e533fbd46b157f6bcae7150 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Sun, 25 Jun 2023 08:53:22 +0800
Subject: [PATCH 10/36] chore(database): add database extension

---
 Dockerfile                                    | 8 ++++----
 charts/database/templates/_helper.tpl         | 2 ++
 charts/database/values.yaml                   | 3 ++-
 rootfs/entrypoint.sh                          | 3 +++
 rootfs/usr/share/scripts/patroni/post_init.sh | 9 ++++++++-
 5 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 87cac65..3daf337 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,15 +3,15 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
 
 COPY rootfs/usr /usr/
 COPY rootfs/entrypoint.sh /entrypoint.sh
-ENV PYTHON_VERSION="3.11" \
-  PG_MAJOR=14 \
-  POSTGRESQL_VERSION="15.3"
+ENV PG_MAJOR=15 \
+  PG_MINOR=3 \
+  PYTHON_VERSION="3.11"
 
 ENV PGDATA /data/${PG_MAJOR}
 
 RUN install-packages gcc \
   && install-stack python $PYTHON_VERSION \
-  && install-stack postgresql $POSTGRESQL_VERSION \
+  && install-stack postgresql $PG_MAJOR.$PG_MINOR \
   && . init-stack \
   && set -eux; pip3 install --disable-pip-version-check --no-cache-dir psycopg[binary] patroni[kubernetes] 2>/dev/null; set +eux \
   && apt-get purge -y --auto-remove gcc \
diff --git a/charts/database/templates/_helper.tpl b/charts/database/templates/_helper.tpl
index 7135587..5a01d6b 100644
--- a/charts/database/templates/_helper.tpl
+++ b/charts/database/templates/_helper.tpl
@@ -38,6 +38,8 @@ env:
   value: '0.0.0.0:8008'
 - name: "DRYCC_DATABASE_INIT_NAMES"
   value: "{{.Values.initDatabases}}"
+- name: "DRYCC_DATABASE_EXTENSIONS"
+  value: "{{.Values.databaseExtensions}}"
 - name: DRYCC_DATABASE_SUPERUSER
   valueFrom:
     secretKeyRef:
diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index cb5d397..90c7398 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -56,7 +56,8 @@ replicator: "standby"
 replicatorPassword: ""
 user: ""
 password: ""
-initDatabases: "controller,passport"
+initDatabases: "controller,passport,monitor"
+databaseExtensions: "postgis,timescaledb"
 
 global:
   # Set the location of Workflow's Object Storage
diff --git a/rootfs/entrypoint.sh b/rootfs/entrypoint.sh
index 40e2ddf..d8baed7 100755
--- a/rootfs/entrypoint.sh
+++ b/rootfs/entrypoint.sh
@@ -26,6 +26,9 @@ restapi:
   connect_address: '${PATRONI_KUBERNETES_POD_IP}:8008'
 postgresql:
   data_dir: '${PGDATA}'
+  parameters:
+    timescaledb.license: 'timescale'
+    shared_preload_libraries: 'auto_explain,timescaledb,pg_stat_statements'
   connect_address: '${PATRONI_KUBERNETES_POD_IP}:5432'
   authentication:
     superuser:
diff --git a/rootfs/usr/share/scripts/patroni/post_init.sh b/rootfs/usr/share/scripts/patroni/post_init.sh
index d6c88fe..338c150 100755
--- a/rootfs/usr/share/scripts/patroni/post_init.sh
+++ b/rootfs/usr/share/scripts/patroni/post_init.sh
@@ -4,11 +4,18 @@ set -Eeu
 if [[ ( -n "$DRYCC_DATABASE_USER") &&  ( -n "$DRYCC_DATABASE_PASSWORD")]]; then
   echo "Creating user ${DRYCC_DATABASE_USER}"
   psql "$1" -w -c "create user ${DRYCC_DATABASE_USER} WITH LOGIN ENCRYPTED PASSWORD '${DRYCC_DATABASE_PASSWORD}'"
-
   for dbname in ${DRYCC_DATABASE_INIT_NAMES//,/ }
   do
     echo "Creating database ${dbname}"
     psql "$1" -w -c "CREATE DATABASE ${dbname} OWNER ${DRYCC_DATABASE_USER}"
+    for extension in ${DRYCC_DATABASE_EXTENSIONS//,/ }
+    do
+      echo "Creating extension ${extension}"
+      psql "$1" -w << EOF
+\c ${dbname};
+create extension ${extension};
+EOF
+    done
   done
 else
   echo "Skipping user creation"

From bb5a8516f2d820cbfbc31ca1a5a0a1ef81f2db53 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 28 Jun 2023 15:55:15 +0800
Subject: [PATCH 11/36] fix(database): link error

---
 CONTRIBUTING.md | 5 ++---
 Dockerfile      | 5 +++--
 MAINTAINERS.md  | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 2e2c6ae..c0c3290 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,5 +1,4 @@
-# How to Contribute
+# Contributing to Drycc
 
 This project is part of Drycc. You can find the latest contribution
-guidelines [at the Drycc project](https://github.com/drycc/drycc/blob/main/CONTRIBUTING.md).
-
+guidelines [in our documentation](https://www.drycc.cc/docs/workflow/contributing/overview/).
diff --git a/Dockerfile b/Dockerfile
index 3daf337..83f4ba0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -7,7 +7,8 @@ ENV PG_MAJOR=15 \
   PG_MINOR=3 \
   PYTHON_VERSION="3.11"
 
-ENV PGDATA /data/${PG_MAJOR}
+ENV HOME /data
+ENV PGDATA $HOME/$PG_MAJOR
 
 RUN install-packages gcc \
   && install-stack python $PYTHON_VERSION \
@@ -33,7 +34,7 @@ RUN install-packages gcc \
   && mkdir -p /usr/share/man/man{1..8} \
   && mkdir -p $PGDATA \
   && groupadd postgres && useradd -g postgres postgres \
-  && chown -R postgres:postgres /data
+  && chown -R postgres:postgres $HOME
 
 USER postgres
 ENTRYPOINT ["init-stack", "/entrypoint.sh"]
diff --git a/MAINTAINERS.md b/MAINTAINERS.md
index 634e415..fc5f4fa 100644
--- a/MAINTAINERS.md
+++ b/MAINTAINERS.md
@@ -1,4 +1,4 @@
 # Drycc Maintainers
 
 This project is part of Drycc. The official maintainers documentation is
-located [in the main project](https://github.com/drycc/drycc/blob/main/MAINTAINERS.md).
+located [in our documentation](http://www.drycc.cc/contributing/maintainers/).

From 4f05056e583e7b14bb37deafba610c0d40439fce Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 15 Aug 2023 10:54:01 +0800
Subject: [PATCH 12/36] chore(database): bump common 1.1.2

---
 charts/database/Chart.yaml                          |  2 +-
 charts/database/templates/database-statefulset.yaml |  6 +++---
 charts/database/values.yaml                         | 10 ++++------
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/charts/database/Chart.yaml b/charts/database/Chart.yaml
index 139f3eb..d12aee8 100644
--- a/charts/database/Chart.yaml
+++ b/charts/database/Chart.yaml
@@ -4,7 +4,7 @@ appVersion: 1.0.0
 dependencies:
   - name: common
     repository: oci://registry.drycc.cc/charts
-    version: ~1.1.1
+    version: ~1.1.2
 home: https://github.com/drycc/database
 version: v1.1.0
 description: A PostgreSQL database used by Drycc Workflow.
diff --git a/charts/database/templates/database-statefulset.yaml b/charts/database/templates/database-statefulset.yaml
index e36da25..e46e2eb 100644
--- a/charts/database/templates/database-statefulset.yaml
+++ b/charts/database/templates/database-statefulset.yaml
@@ -16,13 +16,13 @@ spec:
       cluster-name: drycc-database
   template:
     metadata:
-      labels:
+      labels: {{- include "common.labels.standard" . | nindent 8 }}
         app: drycc-database
         cluster-name: drycc-database
     spec:
       affinity:
-        podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAffinityPreset.type "key" .Values.podAffinityPreset.key "values" .Values.podAffinityPreset.values ) | nindent 10 }}
-        podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset.type "key" .Values.podAntiAffinityPreset.key "values" .Values.podAntiAffinityPreset.values ) | nindent 10 }}
+        podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAffinityPreset.type "component" "" "extraMatchLabels" .Values.podAffinityPreset.extraMatchLabels "topologyKey" "" "context" $) | nindent 10 }}
+        podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset.type "component" "" "extraMatchLabels" .Values.podAntiAffinityPreset.extraMatchLabels "topologyKey" "" "context" $) | nindent 10 }}
         nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values ) | nindent 10 }}
       serviceAccountName: drycc-database
       containers:
diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index 90c7398..850a471 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -16,16 +16,14 @@ nodeAffinityPreset:
   - "true"
 
 podAffinityPreset:
-  key: "security"
   type: ""
-  values:
-  - "drycc-security"
+  extraMatchLabels:
+    security: "drycc-security"
 
 podAntiAffinityPreset:
-  key: "app"
   type: "soft"
-  values:
-  - "drycc-database"
+  extraMatchLabels:
+    app: "drycc-database"
 
 debug: "false"
 timeout: "1200"

From 6c25e1ca6715349957b655419c39f4aba1decaab Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Thu, 28 Sep 2023 10:36:22 +0800
Subject: [PATCH 13/36] chore(database): use podman replace docker

---
 .woodpecker/build-linux.yml |  4 ++--
 .woodpecker/manifest.yml    |  4 ++--
 Makefile                    | 19 ++++++++-----------
 README.md                   | 20 ++++++++------------
 versioning.mk               | 16 ++++++++--------
 5 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
index db9ad17..8cdd984 100644
--- a/.woodpecker/build-linux.yml
+++ b/.woodpecker/build-linux.yml
@@ -13,8 +13,8 @@ pipeline:
   image: bash
   commands:
   - export VERSION=$([ -z $CI_COMMIT_TAG ] && echo latest || echo $CI_COMMIT_TAG)-$(sed 's#/#-#g' <<< $CI_SYSTEM_ARCH)
-  - echo $CONTAINER_PASSWORD | docker login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
-  - make docker-build docker-immutable-push
+  - echo $CONTAINER_PASSWORD | podman login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
+  - make podman-build podman-immutable-push
   secrets:
   - codename
   - dev_registry
diff --git a/.woodpecker/manifest.yml b/.woodpecker/manifest.yml
index 7f6ec36..2d5c4e5 100644
--- a/.woodpecker/manifest.yml
+++ b/.woodpecker/manifest.yml
@@ -19,14 +19,14 @@ pipeline:
 - name: publish-manifest
   image: bash
   commands:
-  - docker run --rm
+  - podman run --rm
     -e PLUGIN_SPEC=.woodpecker/manifest.tmpl
     -e PLUGIN_USERNAME=$CONTAINER_USERNAME
     -e PLUGIN_PASSWORD=$CONTAINER_PASSWORD
     -e DRONE_TAG=$CI_COMMIT_TAG
     -v $(pwd):$(pwd)
     -w $(pwd)
-    plugins/manifest
+    docker.io/plugins/manifest
   secrets:
   - container_username
   - container_password
diff --git a/Makefile b/Makefile
index ed4a626..185c51b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 # Short name: Short name, following [a-zA-Z_], used all over the place.
 # Some uses for short name:
-# - Docker image name
+# - Container image name
 # - Kubernetes service, rc, pod, secret, volume names
 SHORT_NAME := database
 DRYCC_REGISTRY ?= ${DEV_REGISTRY}
@@ -15,23 +15,20 @@ SHELL_SCRIPTS = $(wildcard rootfs/usr/share/scripts/patroni/*)
 # and other build options
 DEV_ENV_IMAGE := ${DEV_REGISTRY}/drycc/go-dev
 DEV_ENV_WORK_DIR := /opt/drycc/go/src/${REPO_PATH}
-DEV_ENV_CMD := docker run --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
-DEV_ENV_CMD_INT := docker run -it --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
+DEV_ENV_CMD := podman run --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
+DEV_ENV_CMD_INT := podman run -it --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
 
-all: docker-build docker-push
+all: podman-build podman-push
 
 # For cases where we're building from local
 # We also alter the RC file to set the image name.
-docker-build:
-	docker build ${DOCKER_BUILD_FLAGS} --build-arg CODENAME=${CODENAME} -t ${IMAGE} .
-	docker tag ${IMAGE} ${MUTABLE_IMAGE}
-
-docker-buildx:
-	docker buildx build --build-arg CODENAME=${CODENAME} --platform ${PLATFORM} -t ${IMAGE} . --push
+podman-build:
+	podman build --build-arg CODENAME=${CODENAME} -t ${IMAGE} .
+	podman tag ${IMAGE} ${MUTABLE_IMAGE}
 
 test: test-style
 
 test-style:
 	${DEV_ENV_CMD} shellcheck $(SHELL_SCRIPTS)
 
-.PHONY: all docker-build docker-push test
+.PHONY: all podman-build podman-push test
diff --git a/README.md b/README.md
index 4e029b6..80225f9 100644
--- a/README.md
+++ b/README.md
@@ -8,10 +8,6 @@ For more information about the Drycc Workflow, please visit the main project pag
 
 We welcome your input! If you have feedback, please submit an [issue][issues]. If you'd like to participate in development, please read the "Development" section below and submit a [pull request][prs].
 
-# About
-
-This component is a PostgreSQL database for use in Kubernetes. It builds on the official [postgres](https://registry.hub.docker.com/_/postgres/) Docker image. While it's intended for use inside of the Drycc Workflow open source [PaaS](https://en.wikipedia.org/wiki/Platform_as_a_service), it's flexible enough to be used as a standalone pod on any Kubernetes cluster or even as a standalone Docker container.
-
 # Development
 
 The Drycc project welcomes contributions from all developers. The high level process for development matches many other open source projects. See below for an outline.
@@ -27,7 +23,7 @@ The Drycc project welcomes contributions from all developers. The high level pro
 In order to develop and test this component in a Drycc cluster, you'll need the following:
 
 * [GNU Make](https://www.gnu.org/software/make/)
-* [Docker](https://www.docker.com/) installed, configured and running
+* [Podman](https://podman.io/) installed, configured and running
 * A working Kubernetes cluster and `kubectl` installed and configured to talk to the cluster
  * If you don't have this setup, please see [the Kubernetes documentation][k8s-docs]
 
@@ -39,27 +35,27 @@ If your feature or bugfix doesn't easily lend itself to unit/integration testing
 
 ### Dogfooding
 
-Finally, we encourage you to [dogfood](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) this component while you're writing code on it. To do so, you'll need to build and push Docker images with your changes.
+Finally, we encourage you to [dogfood](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) this component while you're writing code on it. To do so, you'll need to build and push Container images with your changes.
 
 This project has a [Makefile](https://github.com/drycc/postgres/blob/main/Makefile) that makes these tasks significantly easier. It requires the following environment variables to be set:
 
-* `DRYCC_REGISTRY` - A Docker registry that you have push access to and your Kubernetes cluster can pull from
+* `DRYCC_REGISTRY` - A Container registry that you have push access to and your Kubernetes cluster can pull from
   * If this is [Docker Hub](https://hub.docker.com/), leave this variable empty
   * Otherwise, ensure it has a trailing `/`
-* `IMAGE_PREFIX` - The organization in the Docker repository. This defaults to `drycc`, but if you don't have access to that organization, set this to one you have push access to.
+* `IMAGE_PREFIX` - The organization in the Container repository. This defaults to `drycc`, but if you don't have access to that organization, set this to one you have push access to.
 * `SHORT_NAME` (optional) - The name of the image. This defaults to `postgres`
-* `VERSION` (optional) - The tag of the Docker image. This defaults to the current Git SHA (the output of `git rev-parse --short HEAD`)
+* `VERSION` (optional) - The tag of the Container image. This defaults to the current Git SHA (the output of `git rev-parse --short HEAD`)
 
-Assuming you have these variables set correctly, run `make docker-build` to build the new image, and `make docker-push` to push it. Here is an example command that would push to `example.com/arschles/postgres:devel`:
+Assuming you have these variables set correctly, run `make podman-build` to build the new image, and `make podman-push` to push it. Here is an example command that would push to `example.com/arschles/postgres:devel`:
 
 ```console
 export DRYCC_REGISTRY=example.com/
 export IMAGE_PREFIX=arschles
 export VERSION=devel
-make docker-build docker-push
+make podman-build podman-push
 ```
 
-Note that you'll have to push your image to a Docker repository (`make docker-push`) in order for your Kubernetes cluster to pull the image. This is important for testing in your cluster.
+Note that you'll have to push your image to a Container repository (`make podman-push`) in order for your Kubernetes cluster to pull the image. This is important for testing in your cluster.
 
 
 [issues]: https://github.com/drycc/postgres/issues
diff --git a/versioning.mk b/versioning.mk
index fd4a488..10e3d7b 100644
--- a/versioning.mk
+++ b/versioning.mk
@@ -10,13 +10,13 @@ info:
 	@echo "Immutable tag:   ${IMAGE}"
 	@echo "Mutable tag:     ${MUTABLE_IMAGE}"
 
-.PHONY: docker-push
-docker-push: docker-immutable-push docker-mutable-push
+.PHONY: podman-push
+podman-push: podman-immutable-push podman-mutable-push
 
-.PHONY: docker-immutable-push
-docker-immutable-push:
-	docker push ${IMAGE}
+.PHONY: podman-immutable-push
+podman-immutable-push:
+	podman push ${IMAGE}
 
-.PHONY: docker-mutable-push
-docker-mutable-push:
-	docker push ${MUTABLE_IMAGE}
+.PHONY: podman-mutable-push
+podman-mutable-push:
+	podman push ${MUTABLE_IMAGE}

From 5cf5446f57d60a7cd23d35d1d3958d605584e4b2 Mon Sep 17 00:00:00 2001
From: Eamon <zhang.eamon@hotmail.com>
Date: Wed, 28 Feb 2024 13:23:05 +0800
Subject: [PATCH 14/36] chore(postgres): add patroni and postgres params (#15)

---
 rootfs/entrypoint.sh | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/rootfs/entrypoint.sh b/rootfs/entrypoint.sh
index d8baed7..43e7f9f 100755
--- a/rootfs/entrypoint.sh
+++ b/rootfs/entrypoint.sh
@@ -10,8 +10,14 @@ fi
 cat > /data/patroni.yaml <<__EOF__
 bootstrap:
   dcs:
+    ttl: 30
+    loop_wait: 10
+    retry_timeout: 10
+    maximum_lag_on_failover: 1048576
+    failsafe_mode: true
     postgresql:
       use_pg_rewind: true
+      use_slots: true
   initdb:
   - auth-host: md5
   - auth-local: trust
@@ -29,6 +35,22 @@ postgresql:
   parameters:
     timescaledb.license: 'timescale'
     shared_preload_libraries: 'auto_explain,timescaledb,pg_stat_statements'
+    hot_standby: "on"
+    max_connections: 1005
+    max_worker_processes: 8
+    max_wal_senders: 10
+    max_replication_slots: 10
+    hot_standby_feedback: on
+    max_prepared_transactions: 0
+    max_locks_per_transaction: 64
+    wal_log_hints: "on"
+    track_commit_timestamp: "off"
+    archive_mode: "on"
+    archive_timeout: 300s
+    archive_command: "/bin/true"
+    log_min_duration_statement: 1000
+    log_lock_waits: on
+    log_statement: 'ddl' 
   connect_address: '${PATRONI_KUBERNETES_POD_IP}:5432'
   authentication:
     superuser:

From 2f9ad68c09781ee3396aeb3dfd9fdc19b7c5aa88 Mon Sep 17 00:00:00 2001
From: Eamon <zhang.eamon@hotmail.com>
Date: Wed, 28 Feb 2024 13:47:33 +0800
Subject: [PATCH 15/36] chore(dockerfile): install vi

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 83f4ba0..2edc393 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,7 +10,7 @@ ENV PG_MAJOR=15 \
 ENV HOME /data
 ENV PGDATA $HOME/$PG_MAJOR
 
-RUN install-packages gcc \
+RUN install-packages vi gcc \
   && install-stack python $PYTHON_VERSION \
   && install-stack postgresql $PG_MAJOR.$PG_MINOR \
   && . init-stack \

From ab75e3c402e24aae81b7ea46460ead72dd57025b Mon Sep 17 00:00:00 2001
From: Eamon <zhang.eamon@hotmail.com>
Date: Fri, 1 Mar 2024 09:40:14 +0800
Subject: [PATCH 16/36] chore(dockerfile): install vim instand of vi

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 2edc393..8cc8851 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,7 +10,7 @@ ENV PG_MAJOR=15 \
 ENV HOME /data
 ENV PGDATA $HOME/$PG_MAJOR
 
-RUN install-packages vi gcc \
+RUN install-packages vim gcc \
   && install-stack python $PYTHON_VERSION \
   && install-stack postgresql $PG_MAJOR.$PG_MINOR \
   && . init-stack \

From 729cdc248b4ff4d67a1a2a8e247d0aa8f604d6a0 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 4 Mar 2024 16:56:35 +0800
Subject: [PATCH 17/36] chore(charts): add diagnostic mode

---
 .../database/templates/database-statefulset.yaml  |  6 ++++++
 charts/database/values.yaml                       | 15 +++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/charts/database/templates/database-statefulset.yaml b/charts/database/templates/database-statefulset.yaml
index e46e2eb..d958c29 100644
--- a/charts/database/templates/database-statefulset.yaml
+++ b/charts/database/templates/database-statefulset.yaml
@@ -29,6 +29,10 @@ spec:
       - name: drycc-database
         image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/database:{{.Values.imageTag}}
         imagePullPolicy: {{.Values.imagePullPolicy}}
+        {{- if .Values.diagnosticMode.enabled }}
+        command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 10 }}
+        args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
+        {{- end }}
         ports:
         - containerPort: 8008
           protocol: TCP
@@ -36,6 +40,7 @@ spec:
           protocol: TCP
         {{- include "database.limits" . | indent 8 }}
         {{- include "database.envs" . | indent 8 }}
+        {{- if not .Values.diagnosticMode.enabled }}
         lifecycle:
           preStop:
             exec:
@@ -67,6 +72,7 @@ spec:
           initialDelaySeconds: 10
           timeoutSeconds: 5
           failureThreshold: 3
+        {{- end }}
         volumeMounts:
         - name: database-data
           mountPath: /data
diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index 850a471..d75a5b3 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -9,6 +9,21 @@ imageRegistry: "registry.drycc.cc"
 
 replicas: 3
 
+## Enable diagnostic mode
+##
+diagnosticMode:
+  ## @param diagnosticMode.enabled Enable diagnostic mode (all probes will be disabled and the command will be overridden)
+  ##
+  enabled: false
+  ## @param diagnosticMode.command Command to override all containers
+  ##
+  command:
+    - sleep
+  ## @param diagnosticMode.args Args to override all containers
+  ##
+  args:
+    - infinity
+
 nodeAffinityPreset:
   key: "drycc.cc/node"
   type: "soft"

From c1d5d40e12e4bc798759aa6d321727121fb06d82 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 6 Mar 2024 14:49:51 +0800
Subject: [PATCH 18/36] feat(charts): reuses the value from an existing secret
 and config

---
 .../database/templates/database-secret-creds.yaml  | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/charts/database/templates/database-secret-creds.yaml b/charts/database/templates/database-secret-creds.yaml
index 83424f2..59a8f3e 100644
--- a/charts/database/templates/database-secret-creds.yaml
+++ b/charts/database/templates/database-secret-creds.yaml
@@ -6,13 +6,11 @@ metadata:
   labels:
     app: drycc-database
     heritage: drycc
-  annotations:
-    "helm.sh/hook": pre-install
 data:
-  superuser: {{ if .Values.superuser | default "" | ne "" }}{{ .Values.superuser | lower | b64enc }}{{ else }}{{ randAlpha 32 | lower | b64enc }}{{ end }}
-  superuser-password: {{ if .Values.superuserPassword | default "" | ne "" }}{{ .Values.superuserPassword | b64enc }}{{ else }}{{ randAlphaNum 32 | b64enc }}{{ end }}
-  replicator: {{ if .Values.replicator | default "" | ne "" }}{{ .Values.replicator | lower | b64enc }}{{ else }}{{ randAlpha 32 | lower | b64enc }}{{ end }}
-  replicator-password: {{ if .Values.replicatorPassword | default "" | ne "" }}{{ .Values.replicatorPassword | b64enc }}{{ else }}{{ randAlphaNum 32 | b64enc }}{{ end }}
-  user: {{ if .Values.user | default "" | ne "" }}{{ .Values.user | lower | b64enc }}{{ else }}{{ randAlpha 32 | lower | b64enc }}{{ end }}
-  password: {{ if .Values.password | default "" | ne "" }}{{ .Values.password | b64enc }}{{ else }}{{ randAlphaNum 32 | b64enc }}{{ end }}
+  superuser: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "superuser" "defaultValue" (.Values.superuser | default (randAlpha 32) | lower) "context" $) }}
+  superuser-password: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "superuser-password" "defaultValue" (.Values.superuserPassword | default (randAlphaNum 32)) "context" $) }}
+  replicator: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "replicator" "defaultValue" (.Values.replicator | default (randAlpha 32) | lower) "context" $) }}
+  replicator-password: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "replicator-password" "defaultValue" (.Values.replicatorPassword | default (randAlphaNum 32) | lower) "context" $) }}
+  user: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "user" "defaultValue" (.Values.user | default (randAlpha 32) | lower) "context" $) }}
+  password: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "password" "defaultValue" (.Values.password | default (randAlphaNum 32)) "context" $) }}
 {{- end }}

From caf5881356841b8416b865d527fa21d4a8170fa5 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 18 Mar 2024 16:27:29 +0800
Subject: [PATCH 19/36] chore(woodpecker): migrations woodpecker-ci to 2

---
 .woodpecker/build-linux.yml | 5 ++---
 .woodpecker/chart.yaml      | 6 ++----
 .woodpecker/manifest.yml    | 5 ++---
 .woodpecker/test-linux.yml  | 5 ++---
 4 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
index 8cdd984..f411033 100644
--- a/.woodpecker/build-linux.yml
+++ b/.woodpecker/build-linux.yml
@@ -3,12 +3,11 @@ matrix:
     - linux/amd64
     - linux/arm64
 
-platform: ${platform}
-
 labels:
   type: exec
+  platform: ${platform}
 
-pipeline:
+steps:
 - name: publish-linux
   image: bash
   commands:
diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
index 3204cf5..20f9ea9 100644
--- a/.woodpecker/chart.yaml
+++ b/.woodpecker/chart.yaml
@@ -1,11 +1,9 @@
-platform: linux/amd64
-
 labels:
   type: exec
+  platform: linux/amd64
 
-pipeline:
+steps:
 - name: generate-chart
-  type: local
   image: bash
   commands:
   - export VERSION=$(sed 's#v##' <<< $CI_COMMIT_TAG)
diff --git a/.woodpecker/manifest.yml b/.woodpecker/manifest.yml
index 2d5c4e5..b4735ee 100644
--- a/.woodpecker/manifest.yml
+++ b/.woodpecker/manifest.yml
@@ -1,9 +1,8 @@
-platform: linux/amd64
-
 labels:
   type: exec
+  platform: linux/amd64
 
-pipeline:
+steps:
 - name: generate-manifest
   image: bash
   commands:
diff --git a/.woodpecker/test-linux.yml b/.woodpecker/test-linux.yml
index 313179e..d47ccc5 100644
--- a/.woodpecker/test-linux.yml
+++ b/.woodpecker/test-linux.yml
@@ -3,12 +3,11 @@ matrix:
   - linux/amd64
   - linux/arm64
 
-platform: ${platform}
-
 labels:
   type: exec
+  platform: ${platform}
 
-pipeline:
+steps:
 - name: test-linux
   image: bash
   commands:

From e4352cd8dfb8bf7d9e29be7a1f1e60f1a58e33bc Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 19 Mar 2024 23:12:49 +0800
Subject: [PATCH 20/36] fix(woodpecker): CI_SYSTEM_ARCH env removed

---
 .woodpecker/build-linux.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
index f411033..782d2f5 100644
--- a/.woodpecker/build-linux.yml
+++ b/.woodpecker/build-linux.yml
@@ -11,7 +11,7 @@ steps:
 - name: publish-linux
   image: bash
   commands:
-  - export VERSION=$([ -z $CI_COMMIT_TAG ] && echo latest || echo $CI_COMMIT_TAG)-$(sed 's#/#-#g' <<< $CI_SYSTEM_ARCH)
+  - export VERSION=$([ -z $CI_COMMIT_TAG ] && echo latest || echo $CI_COMMIT_TAG)-$(sed 's#/#-#g' <<< $CI_SYSTEM_PLATFORM)
   - echo $CONTAINER_PASSWORD | podman login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
   - make podman-build podman-immutable-push
   secrets:

From 8f010d87f75e2bfcc5b0337143ea0263f08155d1 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 20 Mar 2024 14:16:51 +0800
Subject: [PATCH 21/36] chore(charts): change canary app version

---
 .woodpecker/chart.yaml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
index 20f9ea9..5aa7eb3 100644
--- a/.woodpecker/chart.yaml
+++ b/.woodpecker/chart.yaml
@@ -8,7 +8,7 @@ steps:
   commands:
   - export VERSION=$(sed 's#v##' <<< $CI_COMMIT_TAG)
   - export IMAGE_TAG=$([ ! -z $CI_COMMIT_TAG ] && echo \"$VERSION\" || echo \"canary\")
-  - export APP_VERSION=$([ ! -z $CI_COMMIT_TAG ] && echo $VERSION || echo 1.0.0)
+  - export APP_VERSION=$([ -z $CI_COMMIT_TAG ] && echo $CI_COMMIT_SHA || echo $VERSION)
   - export CHART_VERSION=$([ -z $CI_COMMIT_TAG ] && echo 1.0.0 || echo $VERSION)
   - sed -i "s/imageTag:\ \"canary\"/imageTag:\ $IMAGE_TAG/g" charts/$${CI_REPO_NAME}/values.yaml
   - helm package -u charts/$${CI_REPO_NAME} --version $CHART_VERSION --app-version $APP_VERSION
@@ -25,4 +25,4 @@ steps:
     - tag
 
 depends_on:
-- manifest
\ No newline at end of file
+- manifest

From c39708983d01f281a965ac6d0e8d40a775df8ade Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Fri, 15 Nov 2024 11:08:49 +0800
Subject: [PATCH 22/36] chore(postgres): bump version 15.8

---
 Dockerfile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 8cc8851..7cb4b59 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,8 +4,8 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
 COPY rootfs/usr /usr/
 COPY rootfs/entrypoint.sh /entrypoint.sh
 ENV PG_MAJOR=15 \
-  PG_MINOR=3 \
-  PYTHON_VERSION="3.11"
+  PG_MINOR=8 \
+  PYTHON_VERSION="3.12"
 
 ENV HOME /data
 ENV PGDATA $HOME/$PG_MAJOR

From 95e270fd8c3f700eccf659a420dbeb54a2181b21 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 26 Nov 2024 17:36:46 +0800
Subject: [PATCH 23/36] chore(database): remove all database extensions

---
 charts/database/values.yaml | 4 ++--
 rootfs/entrypoint.sh        | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index d75a5b3..b060236 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -69,8 +69,8 @@ replicator: "standby"
 replicatorPassword: ""
 user: ""
 password: ""
-initDatabases: "controller,passport,monitor"
-databaseExtensions: "postgis,timescaledb"
+initDatabases: "controller,passport"
+databaseExtensions: ""
 
 global:
   # Set the location of Workflow's Object Storage
diff --git a/rootfs/entrypoint.sh b/rootfs/entrypoint.sh
index 43e7f9f..4f005a8 100755
--- a/rootfs/entrypoint.sh
+++ b/rootfs/entrypoint.sh
@@ -33,8 +33,7 @@ restapi:
 postgresql:
   data_dir: '${PGDATA}'
   parameters:
-    timescaledb.license: 'timescale'
-    shared_preload_libraries: 'auto_explain,timescaledb,pg_stat_statements'
+    shared_preload_libraries: 'auto_explain,pg_stat_statements'
     hot_standby: "on"
     max_connections: 1005
     max_worker_processes: 8

From d34a9bf51999d2da6964f65e41bd867b3b959269 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 23 Dec 2024 13:59:39 +0800
Subject: [PATCH 24/36] fix(wooddpecker): secsets are deprecated

---
 .woodpecker/build-linux.yml | 17 +++++++++++------
 .woodpecker/chart.yaml      | 14 +++++++++-----
 .woodpecker/manifest.yml    |  5 +++--
 .woodpecker/test-linux.yml  |  8 +++++---
 4 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
index 782d2f5..3424a97 100644
--- a/.woodpecker/build-linux.yml
+++ b/.woodpecker/build-linux.yml
@@ -14,12 +14,17 @@ steps:
   - export VERSION=$([ -z $CI_COMMIT_TAG ] && echo latest || echo $CI_COMMIT_TAG)-$(sed 's#/#-#g' <<< $CI_SYSTEM_PLATFORM)
   - echo $CONTAINER_PASSWORD | podman login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
   - make podman-build podman-immutable-push
-  secrets:
-  - codename
-  - dev_registry
-  - drycc_registry
-  - container_username
-  - container_password
+  environment:
+    CODENAME:
+      from_secret: codename
+    DEV_REGISTRY:
+      from_secret: dev_registry
+    DRYCC_REGISTRY:
+      from_secret: drycc_registry
+    CONTAINER_USERNAME:
+      from_secret: container_username
+    CONTAINER_PASSWORD:
+      from_secret: container_password
   when:
     event:
     - push
diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
index 5aa7eb3..40397e0 100644
--- a/.woodpecker/chart.yaml
+++ b/.woodpecker/chart.yaml
@@ -14,11 +14,15 @@ steps:
   - helm package -u charts/$${CI_REPO_NAME} --version $CHART_VERSION --app-version $APP_VERSION
   - echo $CONTAINER_PASSWORD | helm registry login $DRYCC_REGISTRY -u $CONTAINER_USERNAME --password-stdin
   - helm push $${CI_REPO_NAME}-$CHART_VERSION.tgz oci://$DRYCC_REGISTRY/$([ -z $CI_COMMIT_TAG ] && echo charts-testing || echo charts)
-  secrets:
-  - dev_registry
-  - drycc_registry
-  - container_username
-  - container_password
+  environment:
+    DEV_REGISTRY:
+      from_secret: dev_registry
+    DRYCC_REGISTRY:
+      from_secret: drycc_registry
+    CONTAINER_USERNAME:
+      from_secret: container_username
+    CONTAINER_PASSWORD:
+      from_secret: container_password
   when:
     event:
     - push
diff --git a/.woodpecker/manifest.yml b/.woodpecker/manifest.yml
index b4735ee..c842a08 100644
--- a/.woodpecker/manifest.yml
+++ b/.woodpecker/manifest.yml
@@ -8,8 +8,9 @@ steps:
   commands:
   - sed -i "s/{{project}}/$${CI_REPO_NAME}/g" .woodpecker/manifest.tmpl
   - sed -i "s/registry.drycc.cc/$${DRYCC_REGISTRY}/g" .woodpecker/manifest.tmpl
-  secrets:
-  - drycc_registry
+  environment:
+    DRYCC_REGISTRY:
+      from_secret: drycc_registry
   when:
     event:
     - tag
diff --git a/.woodpecker/test-linux.yml b/.woodpecker/test-linux.yml
index d47ccc5..0d5a93f 100644
--- a/.woodpecker/test-linux.yml
+++ b/.woodpecker/test-linux.yml
@@ -12,9 +12,11 @@ steps:
   image: bash
   commands:
   - make test
-  secrets:
-  - codename
-  - dev_registry
+  environment:
+    CODENAME:
+      from_secret: codename
+    DEV_REGISTRY:
+      from_secret: dev_registry
   when:
     event:
     - push

From 3a7743f187977991c12ed8432a7af03b22d38a30 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 2 Apr 2025 11:40:42 +0800
Subject: [PATCH 25/36] chore(woodpecker): add cron event

---
 .woodpecker/build-linux.yml |  1 +
 .woodpecker/chart.yaml      |  1 +
 .woodpecker/manifest.yml    | 10 +++++++---
 .woodpecker/test-linux.yml  |  1 +
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
index 3424a97..ef4ecfd 100644
--- a/.woodpecker/build-linux.yml
+++ b/.woodpecker/build-linux.yml
@@ -29,6 +29,7 @@ steps:
     event:
     - push
     - tag
+    - cron
 
 depends_on:
 - test-linux
\ No newline at end of file
diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
index 40397e0..cfcd3ec 100644
--- a/.woodpecker/chart.yaml
+++ b/.woodpecker/chart.yaml
@@ -27,6 +27,7 @@ steps:
     event:
     - push
     - tag
+    - cron
 
 depends_on:
 - manifest
diff --git a/.woodpecker/manifest.yml b/.woodpecker/manifest.yml
index c842a08..19fc70c 100644
--- a/.woodpecker/manifest.yml
+++ b/.woodpecker/manifest.yml
@@ -15,6 +15,7 @@ steps:
     event:
     - tag
     - push
+    - cron
 
 - name: publish-manifest
   image: bash
@@ -27,13 +28,16 @@ steps:
     -v $(pwd):$(pwd)
     -w $(pwd)
     docker.io/plugins/manifest
-  secrets:
-  - container_username
-  - container_password
+  environment:
+    CONTAINER_USERNAME:
+      from_secret: container_username
+    CONTAINER_PASSWORD:
+      from_secret: container_password
   when:
     event:
     - tag
     - push
+    - cron
 
 depends_on:
 - build-linux
diff --git a/.woodpecker/test-linux.yml b/.woodpecker/test-linux.yml
index 0d5a93f..194832f 100644
--- a/.woodpecker/test-linux.yml
+++ b/.woodpecker/test-linux.yml
@@ -21,3 +21,4 @@ steps:
     event:
     - push
     - tag
+    - cron

From 5ccd2730235b295f62191c01f06cad729a1469a7 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 7 May 2025 18:02:02 +0800
Subject: [PATCH 26/36] chore(charts): use condition

---
 charts/database/templates/_helper.tpl            |  2 --
 .../database/templates/database-clusterrole.yaml |  2 --
 .../templates/database-clusterrolebinding.yaml   |  2 --
 .../templates/database-role-binding.yaml         |  2 --
 charts/database/templates/database-role.yaml     |  2 --
 .../templates/database-secret-creds.yaml         |  2 --
 .../templates/database-service-account.yaml      |  2 --
 .../templates/database-service-replica.yaml      |  2 --
 charts/database/templates/database-service.yaml  |  2 --
 .../database/templates/database-statefulset.yaml |  2 --
 charts/database/values.yaml                      | 16 ----------------
 11 files changed, 36 deletions(-)

diff --git a/charts/database/templates/_helper.tpl b/charts/database/templates/_helper.tpl
index 5a01d6b..2f9278f 100644
--- a/charts/database/templates/_helper.tpl
+++ b/charts/database/templates/_helper.tpl
@@ -1,7 +1,5 @@
 {{- define "database.envs" }}
 env:
-- name: DATABASE_STORAGE
-  value: "{{.Values.global.storage}}"
 {{- if eq .Values.debug "true" }}
 - name: PATRONI_LOG_LEVEL
   value: DEBUG
diff --git a/charts/database/templates/database-clusterrole.yaml b/charts/database/templates/database-clusterrole.yaml
index 7fc3898..066c2e1 100644
--- a/charts/database/templates/database-clusterrole.yaml
+++ b/charts/database/templates/database-clusterrole.yaml
@@ -1,4 +1,3 @@
-{{- if eq .Values.global.databaseLocation "on-cluster" }}
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRole
 metadata:
@@ -12,4 +11,3 @@ rules:
   - kubernetes
   verbs:
   - get
-{{- end }}
diff --git a/charts/database/templates/database-clusterrolebinding.yaml b/charts/database/templates/database-clusterrolebinding.yaml
index 6db4596..24e3fa6 100644
--- a/charts/database/templates/database-clusterrolebinding.yaml
+++ b/charts/database/templates/database-clusterrolebinding.yaml
@@ -1,4 +1,3 @@
-{{- if eq .Values.global.databaseLocation "on-cluster" }}
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRoleBinding
 metadata:
@@ -11,4 +10,3 @@ subjects:
 - kind: ServiceAccount
   name: drycc-database
   namespace: {{ .Release.Namespace }}
-{{- end }}
diff --git a/charts/database/templates/database-role-binding.yaml b/charts/database/templates/database-role-binding.yaml
index bbca50b..e927dab 100644
--- a/charts/database/templates/database-role-binding.yaml
+++ b/charts/database/templates/database-role-binding.yaml
@@ -1,4 +1,3 @@
-{{- if eq .Values.global.databaseLocation "on-cluster" }}
 apiVersion: rbac.authorization.k8s.io/v1
 kind: RoleBinding
 metadata:
@@ -10,4 +9,3 @@ roleRef:
 subjects:
 - kind: ServiceAccount
   name: drycc-database
-{{- end }}
diff --git a/charts/database/templates/database-role.yaml b/charts/database/templates/database-role.yaml
index 5ed547c..8957f9b 100644
--- a/charts/database/templates/database-role.yaml
+++ b/charts/database/templates/database-role.yaml
@@ -1,4 +1,3 @@
-{{- if eq .Values.global.databaseLocation "on-cluster" }}
 apiVersion: rbac.authorization.k8s.io/v1
 kind: Role
 metadata:
@@ -53,4 +52,3 @@ rules:
   - services
   verbs:
   - create
-{{- end }}
diff --git a/charts/database/templates/database-secret-creds.yaml b/charts/database/templates/database-secret-creds.yaml
index 59a8f3e..1f5eddc 100644
--- a/charts/database/templates/database-secret-creds.yaml
+++ b/charts/database/templates/database-secret-creds.yaml
@@ -1,4 +1,3 @@
-{{ if eq .Values.global.databaseLocation "on-cluster"}}
 apiVersion: v1
 kind: Secret
 metadata:
@@ -13,4 +12,3 @@ data:
   replicator-password: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "replicator-password" "defaultValue" (.Values.replicatorPassword | default (randAlphaNum 32) | lower) "context" $) }}
   user: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "user" "defaultValue" (.Values.user | default (randAlpha 32) | lower) "context" $) }}
   password: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "password" "defaultValue" (.Values.password | default (randAlphaNum 32)) "context" $) }}
-{{- end }}
diff --git a/charts/database/templates/database-service-account.yaml b/charts/database/templates/database-service-account.yaml
index 553f18e..d429cfa 100644
--- a/charts/database/templates/database-service-account.yaml
+++ b/charts/database/templates/database-service-account.yaml
@@ -1,8 +1,6 @@
-{{- if eq .Values.global.databaseLocation "on-cluster" }}
 apiVersion: v1
 kind: ServiceAccount
 metadata:
   name: drycc-database
   labels:
     heritage: drycc
-{{- end }}
diff --git a/charts/database/templates/database-service-replica.yaml b/charts/database/templates/database-service-replica.yaml
index 0bc8c00..e168d0d 100644
--- a/charts/database/templates/database-service-replica.yaml
+++ b/charts/database/templates/database-service-replica.yaml
@@ -1,4 +1,3 @@
-{{- if eq .Values.global.databaseLocation "on-cluster" }}
 apiVersion: v1
 kind: Service
 metadata:
@@ -20,4 +19,3 @@ spec:
   selector:
     app: drycc-database
     role: replica
-{{- end }}
diff --git a/charts/database/templates/database-service.yaml b/charts/database/templates/database-service.yaml
index 5aa9fe9..0638885 100644
--- a/charts/database/templates/database-service.yaml
+++ b/charts/database/templates/database-service.yaml
@@ -1,4 +1,3 @@
-{{- if eq .Values.global.databaseLocation "on-cluster" }}
 apiVersion: v1
 kind: Service
 metadata:
@@ -14,4 +13,3 @@ spec:
   ports:
     - port: 5432
       targetPort: 5432
-{{- end }}
diff --git a/charts/database/templates/database-statefulset.yaml b/charts/database/templates/database-statefulset.yaml
index d958c29..66d235b 100644
--- a/charts/database/templates/database-statefulset.yaml
+++ b/charts/database/templates/database-statefulset.yaml
@@ -1,4 +1,3 @@
-{{- if eq .Values.global.databaseLocation "on-cluster" }}
 apiVersion: apps/v1
 kind: StatefulSet
 metadata:
@@ -97,4 +96,3 @@ spec:
       - name: database-data
         emptyDir: {}
   {{- end }}
-{{- end }}
diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index b060236..768ca11 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -71,19 +71,3 @@ user: ""
 password: ""
 initDatabases: "controller,passport"
 databaseExtensions: ""
-
-global:
-  # Set the location of Workflow's Object Storage
-  #
-  # Valid values are:
-  # - on-cluster: Run drycc storage within the Kubernetes cluster
-  # - off-cluster: Run Storage outside the Kubernetes cluster (Compatible with s3 API)
-  storageLocation: "on-cluster"
-  # Set the location of Workflow's PostgreSQL database
-  #
-  # Valid values are:
-  # - on-cluster: Run PostgreSQL within the Kubernetes cluster (credentials are generated
-  #   automatically; backups are sent to object storage
-  #   configured above)
-  # - off-cluster: Run PostgreSQL outside the Kubernetes cluster
-  databaseLocation: "on-cluster"

From cb85e66dc6bb193ae8a453f44202e7866b56b67a Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 12 May 2025 09:32:53 +0800
Subject: [PATCH 27/36] chore(charts): change resources format

---
 charts/database/templates/_helper.tpl         | 20 -------------------
 .../templates/database-statefulset.yaml       |  5 ++++-
 charts/database/values.yaml                   | 12 +++++++----
 3 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/charts/database/templates/_helper.tpl b/charts/database/templates/_helper.tpl
index 2f9278f..38570fb 100644
--- a/charts/database/templates/_helper.tpl
+++ b/charts/database/templates/_helper.tpl
@@ -69,23 +69,3 @@ env:
       name: database-creds
       key: password
 {{- end }}
-
-{{/* Generate database deployment limits */}}
-{{- define "database.limits" -}}
-{{- if or (.Values.limitsCpu) (.Values.limitsMemory)}}
-resources:
-  limits:
-    {{- if (.Values.limitsCpu) }}
-    cpu: {{.Values.limitsCpu}}
-    {{- end }}
-    {{- if (.Values.limitsMemory) }}
-    memory: {{.Values.limitsMemory}}
-    {{- end }}
-    {{- if (.Values.limitsHugepages2Mi) }}
-    hugepages-2Mi: {{.Values.limitsHugepages2Mi}}
-    {{- end }}
-    {{- if (.Values.limitsHugepages1Gi) }}
-    hugepages-1Gi: {{.Values.limitsHugepages1Gi}}
-    {{- end }}
-{{- end }}
-{{- end }}
diff --git a/charts/database/templates/database-statefulset.yaml b/charts/database/templates/database-statefulset.yaml
index 66d235b..3cd2286 100644
--- a/charts/database/templates/database-statefulset.yaml
+++ b/charts/database/templates/database-statefulset.yaml
@@ -37,8 +37,11 @@ spec:
           protocol: TCP
         - containerPort: 5432
           protocol: TCP
-        {{- include "database.limits" . | indent 8 }}
         {{- include "database.envs" . | indent 8 }}
+        {{- with index .Values "resources" }}
+        resources:
+          {{- toYaml . | nindent 10 }}
+        {{- end }}
         {{- if not .Values.diagnosticMode.enabled }}
         lifecycle:
           preStop:
diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index 768ca11..8882548 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -2,10 +2,6 @@ imageOrg: "drycc"
 imagePullPolicy: "Always"
 imageTag: "canary"
 imageRegistry: "registry.drycc.cc"
-# limitsCpu: "100m"
-# limitsMemory: "50Mi"
-# limitsHugepages2Mi: 100Mi
-# limitsHugepages1Gi: 2Gi
 
 replicas: 3
 
@@ -24,6 +20,14 @@ diagnosticMode:
   args:
     - infinity
 
+resources: {}
+  # limits:
+  #   cpu: 200m
+  #   memory: 50Mi
+  # requests:
+  #   cpu: 100m
+  #   memory: 30Mi
+
 nodeAffinityPreset:
   key: "drycc.cc/node"
   type: "soft"

From 990391de57095b94e1c77c67e8ede6406f2d7c32 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 19 May 2025 17:28:29 +0800
Subject: [PATCH 28/36] chore(charts): add init grafana database

---
 charts/database/values.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index 8882548..b6ba3d9 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -73,5 +73,5 @@ replicator: "standby"
 replicatorPassword: ""
 user: ""
 password: ""
-initDatabases: "controller,passport"
+initDatabases: "controller,passport,grafana"
 databaseExtensions: ""

From ef5941c8c5658830005c77c3320be65af67c9f20 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 20 May 2025 11:00:33 +0800
Subject: [PATCH 29/36] chore(database): add postgres_exporter

---
 Dockerfile                                    |  4 +-
 .../templates/database-statefulset.yaml       | 58 +++++++++++++++++++
 rootfs/usr/share/scripts/patroni/post_init.sh |  1 +
 3 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 7cb4b59..e03f5f6 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -5,7 +5,8 @@ COPY rootfs/usr /usr/
 COPY rootfs/entrypoint.sh /entrypoint.sh
 ENV PG_MAJOR=15 \
   PG_MINOR=8 \
-  PYTHON_VERSION="3.12"
+  PYTHON_VERSION="3.12" \
+  POSTGRES_EXPORTER_VERSION="0.17.1"
 
 ENV HOME /data
 ENV PGDATA $HOME/$PG_MAJOR
@@ -13,6 +14,7 @@ ENV PGDATA $HOME/$PG_MAJOR
 RUN install-packages vim gcc \
   && install-stack python $PYTHON_VERSION \
   && install-stack postgresql $PG_MAJOR.$PG_MINOR \
+  && install-stack postgres_exporter $POSTGRES_EXPORTER_VERSION \
   && . init-stack \
   && set -eux; pip3 install --disable-pip-version-check --no-cache-dir psycopg[binary] patroni[kubernetes] 2>/dev/null; set +eux \
   && apt-get purge -y --auto-remove gcc \
diff --git a/charts/database/templates/database-statefulset.yaml b/charts/database/templates/database-statefulset.yaml
index 3cd2286..300bc7b 100644
--- a/charts/database/templates/database-statefulset.yaml
+++ b/charts/database/templates/database-statefulset.yaml
@@ -15,6 +15,10 @@ spec:
       cluster-name: drycc-database
   template:
     metadata:
+      annotations:
+        prometheus.io/path: /metrics
+        prometheus.io/port: "9187"
+        prometheus.io/scrape: "true"
       labels: {{- include "common.labels.standard" . | nindent 8 }}
         app: drycc-database
         cluster-name: drycc-database
@@ -78,6 +82,60 @@ spec:
         volumeMounts:
         - name: database-data
           mountPath: /data
+      - name: drycc-database-metrics
+        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/database:{{.Values.imageTag}}
+        imagePullPolicy: {{.Values.imagePullPolicy}}
+        {{- if .Values.diagnosticMode.enabled }}
+        command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 10 }}
+        args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
+        {{- else }}
+        command:
+        - init-stack
+        args:
+        - postgres_exporter
+        {{- end }}
+        ports:
+        - containerPort: 9187
+          protocol: TCP
+        env:
+        - name: DATA_SOURCE_URI
+          value: "127.0.0.1:5432/postgres?sslmode=disable"
+        - name: DATA_SOURCE_USER
+          valueFrom:
+            secretKeyRef:
+              name: database-creds
+              key: user
+        - name: DATA_SOURCE_PASS
+          valueFrom:
+            secretKeyRef:
+              name: database-creds
+              key: password
+        startupProbe:
+          initialDelaySeconds: 10
+          tcpSocket:
+              port: 9187
+          periodSeconds: 10
+          timeoutSeconds: 1
+          failureThreshold: 15
+          successThreshold: 1
+        livenessProbe:
+          initialDelaySeconds: 5
+          httpGet:
+            path: /
+            port: 9187
+          periodSeconds: 10
+          timeoutSeconds: 5
+          failureThreshold: 6
+          successThreshold: 1
+        readinessProbe:
+          initialDelaySeconds: 5
+          httpGet:
+            path: /
+            port: 9187
+          periodSeconds: 10
+          timeoutSeconds: 5
+          failureThreshold: 6
+          successThreshold: 1
   {{- if .Values.persistence.enabled }}
   volumeClaimTemplates:
   - metadata:
diff --git a/rootfs/usr/share/scripts/patroni/post_init.sh b/rootfs/usr/share/scripts/patroni/post_init.sh
index 338c150..a8f75f5 100755
--- a/rootfs/usr/share/scripts/patroni/post_init.sh
+++ b/rootfs/usr/share/scripts/patroni/post_init.sh
@@ -4,6 +4,7 @@ set -Eeu
 if [[ ( -n "$DRYCC_DATABASE_USER") &&  ( -n "$DRYCC_DATABASE_PASSWORD")]]; then
   echo "Creating user ${DRYCC_DATABASE_USER}"
   psql "$1" -w -c "create user ${DRYCC_DATABASE_USER} WITH LOGIN ENCRYPTED PASSWORD '${DRYCC_DATABASE_PASSWORD}'"
+  psql "$1" -w -c "GRANT pg_monitor TO ${DRYCC_DATABASE_USER}"
   for dbname in ${DRYCC_DATABASE_INIT_NAMES//,/ }
   do
     echo "Creating database ${dbname}"

From d18b382d6b0513b5a3db40d718e60a3e9d97fcea Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 2 Jul 2025 16:23:42 +0800
Subject: [PATCH 30/36] chore(charts): add init quickwit database

---
 charts/database/values.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index b6ba3d9..e407b0a 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -73,5 +73,5 @@ replicator: "standby"
 replicatorPassword: ""
 user: ""
 password: ""
-initDatabases: "controller,passport,grafana"
+initDatabases: "controller,passport,grafana,quickwit"
 databaseExtensions: ""

From e0f6ecd0602b9ae7ae5ed40d243037e2ddce0e93 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Sun, 14 Sep 2025 11:14:55 +0800
Subject: [PATCH 31/36] chore(database): bump new version

---
 Dockerfile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index e03f5f6..0391d0c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,9 +3,9 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
 
 COPY rootfs/usr /usr/
 COPY rootfs/entrypoint.sh /entrypoint.sh
-ENV PG_MAJOR=15 \
-  PG_MINOR=8 \
-  PYTHON_VERSION="3.12" \
+ENV PG_MAJOR=17 \
+  PG_MINOR=6 \
+  PYTHON_VERSION="3.13" \
   POSTGRES_EXPORTER_VERSION="0.17.1"
 
 ENV HOME /data

From 1d6230d9eea73d5c5adc464e03aaca0f2bf4dc57 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Thu, 6 Nov 2025 17:07:41 +0800
Subject: [PATCH 32/36] chore(database): change env to build arg

---
 Dockerfile | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 0391d0c..f59c819 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,12 +3,14 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
 
 COPY rootfs/usr /usr/
 COPY rootfs/entrypoint.sh /entrypoint.sh
-ENV PG_MAJOR=17 \
-  PG_MINOR=6 \
-  PYTHON_VERSION="3.13" \
+
+
+ARG PYTHON_VERSION="3.13" \
   POSTGRES_EXPORTER_VERSION="0.17.1"
 
-ENV HOME /data
+ENV HOME /data \
+  PG_MAJOR=17 \
+  PG_MINOR=6
 ENV PGDATA $HOME/$PG_MAJOR
 
 RUN install-packages vim gcc \

From 32ca19996c3140ccfdd84c726a734da8de936ef3 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Fri, 7 Nov 2025 16:36:54 +0800
Subject: [PATCH 33/36] chore(database): bump postgres to 18.0

---
 Dockerfile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index f59c819..8704907 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -8,9 +8,9 @@ COPY rootfs/entrypoint.sh /entrypoint.sh
 ARG PYTHON_VERSION="3.13" \
   POSTGRES_EXPORTER_VERSION="0.17.1"
 
-ENV HOME /data \
-  PG_MAJOR=17 \
-  PG_MINOR=6
+ENV HOME=/data \
+  PG_MAJOR=18 \
+  PG_MINOR=0
 ENV PGDATA $HOME/$PG_MAJOR
 
 RUN install-packages vim gcc \

From 6dd5ac96dbb416a12622b71576617b563a7660a3 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Thu, 20 Nov 2025 09:49:37 +0800
Subject: [PATCH 34/36] chore(postgresql): bump version to 18.1

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 8704907..952be0d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,7 +10,7 @@ ARG PYTHON_VERSION="3.13" \
 
 ENV HOME=/data \
   PG_MAJOR=18 \
-  PG_MINOR=0
+  PG_MINOR=1
 ENV PGDATA $HOME/$PG_MAJOR
 
 RUN install-packages vim gcc \

From f04b3cf9e8ea5b26b040c640563375a60de3abd7 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Thu, 20 Nov 2025 09:56:34 +0800
Subject: [PATCH 35/36] chore(postgres_exporter): bump version to 0.18.1

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 952be0d..d8c2cb9 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -6,7 +6,7 @@ COPY rootfs/entrypoint.sh /entrypoint.sh
 
 
 ARG PYTHON_VERSION="3.13" \
-  POSTGRES_EXPORTER_VERSION="0.17.1"
+  POSTGRES_EXPORTER_VERSION="0.18.1"
 
 ENV HOME=/data \
   PG_MAJOR=18 \

From 246389efb378f088e0f193e9da933231531b306b Mon Sep 17 00:00:00 2001
From: Eamon <zhang.eamon@hotmail.com>
Date: Mon, 22 Dec 2025 10:14:03 +0800
Subject: [PATCH 36/36] chore(postgresql): add logical backup (#18)

Co-authored-by: zhangeamon <EamonZhang>
---
 .gitignore                                    |  4 +-
 Dockerfile                                    | 33 +++++-----
 charts/database/templates/_helper.tpl         | 46 +++++++++++++
 .../templates/database-cronjob-backup.yaml    | 29 ++++++++
 .../templates/database-secret-creds.yaml      |  7 ++
 charts/database/values.yaml                   | 19 +++++-
 rootfs/entrypoint.sh                          |  9 +--
 rootfs/usr/share/scripts/backup.sh            | 66 +++++++++++++++++++
 rootfs/usr/share/scripts/create_bucket        | 19 ++++++
 9 files changed, 211 insertions(+), 21 deletions(-)
 create mode 100644 charts/database/templates/database-cronjob-backup.yaml
 create mode 100755 rootfs/usr/share/scripts/backup.sh
 create mode 100755 rootfs/usr/share/scripts/create_bucket

diff --git a/.gitignore b/.gitignore
index 1ee9ef0..4573d78 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
 contrib/ci/tmp
-.vscode/
\ No newline at end of file
+.vscode/
+charts/database/Chart.lock
+charts/database/charts/
diff --git a/Dockerfile b/Dockerfile
index d8c2cb9..f0764de 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,12 +10,15 @@ ARG PYTHON_VERSION="3.13" \
 
 ENV HOME=/data \
   PG_MAJOR=18 \
-  PG_MINOR=1
-ENV PGDATA $HOME/$PG_MAJOR
+  PG_MINOR=1 \
+  S3_RCLONE_VERSION="1.71.1" 
 
-RUN install-packages vim gcc \
+ENV PGDATA=$HOME/$PG_MAJOR
+
+RUN install-packages vim gcc pigz jq\
   && install-stack python $PYTHON_VERSION \
   && install-stack postgresql $PG_MAJOR.$PG_MINOR \
+  && install-stack rclone $S3_RCLONE_VERSION \
   && install-stack postgres_exporter $POSTGRES_EXPORTER_VERSION \
   && . init-stack \
   && set -eux; pip3 install --disable-pip-version-check --no-cache-dir psycopg[binary] patroni[kubernetes] 2>/dev/null; set +eux \
@@ -23,18 +26,18 @@ RUN install-packages vim gcc \
   && apt-get autoremove -y \
   && apt-get clean -y \
   && rm -rf \
-    /usr/share/doc \
-    /usr/share/man \
-    /usr/share/info \
-    /usr/share/locale \
-    /var/lib/apt/lists/* \
-    /var/log/* \
-    /var/cache/debconf/* \
-    /etc/systemd \
-    /lib/lsb \
-    /lib/udev \
-    /usr/lib/`echo $(uname -m)`-linux-gnu/gconv/IBM* \
-    /usr/lib/`echo $(uname -m)`-linux-gnu/gconv/EBC* \
+  /usr/share/doc \
+  /usr/share/man \
+  /usr/share/info \
+  /usr/share/locale \
+  /var/lib/apt/lists/* \
+  /var/log/* \
+  /var/cache/debconf/* \
+  /etc/systemd \
+  /lib/lsb \
+  /lib/udev \
+  /usr/lib/`echo $(uname -m)`-linux-gnu/gconv/IBM* \
+  /usr/lib/`echo $(uname -m)`-linux-gnu/gconv/EBC* \
   && mkdir -p /usr/share/man/man{1..8} \
   && mkdir -p $PGDATA \
   && groupadd postgres && useradd -g postgres postgres \
diff --git a/charts/database/templates/_helper.tpl b/charts/database/templates/_helper.tpl
index 38570fb..3d1638f 100644
--- a/charts/database/templates/_helper.tpl
+++ b/charts/database/templates/_helper.tpl
@@ -1,5 +1,51 @@
 {{- define "database.envs" }}
 env:
+- name: RETAIN_BACKUPS_AGE
+  value: "{{.Values.cronjob.retainBackupsAge}}"
+{{- if (.Values.storageEndpoint) }}
+- name: "DRYCC_STORAGE_BUCKET"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: storage-bucket
+- name: "DRYCC_STORAGE_ENDPOINT"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: storage-endpoint
+- name: "DRYCC_STORAGE_ACCESSKEY"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: storage-accesskey
+- name: "DRYCC_STORAGE_SECRETKEY"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: storage-secretkey
+- name: "DRYCC_STORAGE_PATH_STYLE"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: storage-path-style
+{{- else if .Values.storage.enabled  }}
+- name: "DRYCC_STORAGE_BUCKET"
+  value: "database"
+- name: "DRYCC_STORAGE_ENDPOINT"
+  value: http://drycc-storage:9000
+- name: "DRYCC_STORAGE_ACCESSKEY"
+  valueFrom:
+    secretKeyRef:
+      name: storage-creds
+      key: accesskey
+- name: "DRYCC_STORAGE_SECRETKEY"
+  valueFrom:
+    secretKeyRef:
+      name: storage-creds
+      key: secretkey
+- name: "DRYCC_STORAGE_PATH_STYLE"
+  value: "true"
+{{- end }}
 {{- if eq .Values.debug "true" }}
 - name: PATRONI_LOG_LEVEL
   value: DEBUG
diff --git a/charts/database/templates/database-cronjob-backup.yaml b/charts/database/templates/database-cronjob-backup.yaml
new file mode 100644
index 0000000..ee4e042
--- /dev/null
+++ b/charts/database/templates/database-cronjob-backup.yaml
@@ -0,0 +1,29 @@
+{{- if .Values.cronjob.enabled }}
+apiVersion: {{ include "common.capabilities.cronjob.apiVersion" . }}
+kind: CronJob
+metadata:
+  name: drycc-database-cronjob-backup
+  labels:
+    heritage: drycc
+  annotations:
+    component.drycc.cc/version: {{ .Values.imageTag }}
+
+spec:
+  schedule: "{{ .Values.cronjob.scheduleCronJob }}"
+  failedJobsHistoryLimit: 1
+  successfulJobsHistoryLimit: 1
+  jobTemplate:
+    spec:
+      template:
+        spec:
+          restartPolicy: OnFailure              
+          containers:         
+          - name: drycc-database-cronjob-backup
+            image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/database:{{.Values.imageTag}}
+            imagePullPolicy: {{.Values.imagePullPolicy}}
+            command:
+            - init-stack
+            args:  
+            - /usr/share/scripts/backup.sh
+            {{- include "database.envs" . | indent 12 }}
+{{- end -}}
\ No newline at end of file
diff --git a/charts/database/templates/database-secret-creds.yaml b/charts/database/templates/database-secret-creds.yaml
index 1f5eddc..6b7f01d 100644
--- a/charts/database/templates/database-secret-creds.yaml
+++ b/charts/database/templates/database-secret-creds.yaml
@@ -12,3 +12,10 @@ data:
   replicator-password: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "replicator-password" "defaultValue" (.Values.replicatorPassword | default (randAlphaNum 32) | lower) "context" $) }}
   user: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "user" "defaultValue" (.Values.user | default (randAlpha 32) | lower) "context" $) }}
   password: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "password" "defaultValue" (.Values.password | default (randAlphaNum 32)) "context" $) }}
+  {{- if (.Values.storageEndpoint) }}
+  storage-bucket: {{ .Values.storageBucket | b64enc }}
+  storage-endpoint: {{ .Values.storageEndpoint | b64enc }}
+  storage-accesskey: {{ .Values.storageAccesskey | b64enc }}
+  storage-secretkey: {{ .Values.storageSecretkey | b64enc }}
+  storage-path-style: {{ .Values.storagePathStyle | b64enc }}
+  {{- end }}
diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index e407b0a..e856429 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -45,7 +45,24 @@ podAntiAffinityPreset:
     app: "drycc-database"
 
 debug: "false"
+# Patroni pg_ctl timeout
 timeout: "1200"
+
+# The following parameters will no longer use the built-in storage component.
+storageBucket: "database"
+storageEndpoint: ""
+storageAccesskey: ""
+storageSecretkey: ""
+storagePathStyle: "true"
+
+storage:
+  enabled: true
+
+cronjob:
+  enabled: true
+  scheduleCronJob: "0 3 * * *"
+  retainBackupsAge: 30d
+
 # Service
 service:
   # Provide any additional service annotations
@@ -66,7 +83,7 @@ persistence:
   storageClass: ""
 # The username and password to be used by the on-cluster database.
 # If left empty they will be generated
-# The user name should be set to lowercase letters 
+# The user name should be set to lowercase letters
 superuser: "postgres"
 superuserPassword: ""
 replicator: "standby"
diff --git a/rootfs/entrypoint.sh b/rootfs/entrypoint.sh
index 4f005a8..8865438 100755
--- a/rootfs/entrypoint.sh
+++ b/rootfs/entrypoint.sh
@@ -1,5 +1,4 @@
 #!/bin/bash
-
 if [[ $UID -ge 10000 ]]; then
     GID=$(id -g)
     sed -e "s/^postgres:x:[^:]*:[^:]*:/postgres:x:$UID:$GID:/" /etc/passwd > /tmp/passwd
@@ -19,14 +18,14 @@ bootstrap:
       use_pg_rewind: true
       use_slots: true
   initdb:
-  - auth-host: md5
+  - auth-host: scram-sha-256
   - auth-local: trust
   - encoding: UTF8
   - locale: ${LANG}
   - data-checksums
   pg_hba:
-  - host all all 0.0.0.0/0 md5
-  - host replication ${DRYCC_DATABASE_REPLICATOR} ${PATRONI_KUBERNETES_POD_IP}/16 md5
+  - host all all 0.0.0.0/0 scram-sha-256
+  - host replication ${DRYCC_DATABASE_REPLICATOR} ${PATRONI_KUBERNETES_POD_IP}/16 scram-sha-256
   post_bootstrap: /usr/share/scripts/patroni/post_init.sh
 restapi:
   connect_address: '${PATRONI_KUBERNETES_POD_IP}:8008'
@@ -43,6 +42,7 @@ postgresql:
     max_prepared_transactions: 0
     max_locks_per_transaction: 64
     wal_log_hints: "on"
+    wal_level: logical
     track_commit_timestamp: "off"
     archive_mode: "on"
     archive_timeout: 300s
@@ -50,6 +50,7 @@ postgresql:
     log_min_duration_statement: 1000
     log_lock_waits: on
     log_statement: 'ddl' 
+    jit: off
   connect_address: '${PATRONI_KUBERNETES_POD_IP}:5432'
   authentication:
     superuser:
diff --git a/rootfs/usr/share/scripts/backup.sh b/rootfs/usr/share/scripts/backup.sh
new file mode 100755
index 0000000..441c33e
--- /dev/null
+++ b/rootfs/usr/share/scripts/backup.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+set -e
+
+# Setup Rclone 
+/usr/share/scripts/create_bucket
+
+# Backup PostgreSQL databases to S3-compatible object storage
+export PGPASSWORD=$DRYCC_DATABASE_SUPERUSER_PASSWORD
+PGPORT=$DRYCC_DATABASE_REPLICA_SERVICE_PORT_POSTGRES
+PGUSER=postgres
+POSTGRES_HOST=$DRYCC_DATABASE_REPLICA_SERVICE_HOST
+RETAIN_BACKUPS_AGE=$RETAIN_BACKUPS_AGE
+
+# PostgreSQL global objects backup 
+BACKUP_PATH="${DRYCC_STORAGE_BUCKET}/$(date +%Y%m%d%H%M)"
+echo "DB: ${POSTGRES_USER}@${POSTGRES_HOST}"
+echo "S3 Storage: storage:${BACKUP_PATH}"
+# Backup global objects
+if pg_dumpall -g -U "${POSTGRES_USER}" -h "${POSTGRES_HOST}" \
+  | pigz -c -p 4 -6 \
+  | rclone rcat \
+      "storage:${BACKUP_PATH}/roles_globals.sql.gz" \
+      --bwlimit 10M \
+      --transfers 4 \
+      --s3-chunk-size 64M \
+      --stats 5s \
+      --progress \
+      --retries 3; then  
+  echo "✅ PostgreSQL global objects backup complated!" 
+fi 
+  # fetch the list of databases
+  DATABASES=$(psql -U "$POSTGRES_USER" -h "$POSTGRES_HOST" -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;")
+
+  # backup each database individually
+  for DB in $DATABASES; do
+    echo "Backing up $DB to $MINIO_PATH/$DB.sql.gz"
+    if pg_dump -U "${POSTGRES_USER}" -h "${POSTGRES_HOST}" "$DB" \
+        | pigz -c -p 4 -6 \
+        | rclone rcat \
+            "storage:${BACKUP_PATH}/$DB.sql.gz" \
+            --bwlimit 10M \
+            --transfers 4 \
+            --s3-chunk-size 64M \
+            --stats 5s \
+            --progress \
+            --retries 3; then
+        echo "✅ PostgreSQL $DB global objects backup completed!"
+    fi
+  done
+
+  echo "Backup process completed!"
+
+  echo "delete storage before ${RETAIN_BACKUPS_AGE} ..."
+  rclone delete "storage:${DRYCC_STORAGE_BUCKET}" \
+    --min-age ${RETAIN_BACKUPS_AGE} \
+    --include "*.sql.gz" \
+    --dry-run \
+    -v  || true
+
+  rclone delete "storage:${DRYCC_STORAGE_BUCKET}" \
+    --min-age ${RETAIN_BACKUPS_AGE} \
+    --include "*.sql.gz" \
+    || true
+  echo "delete completed."
+
+echo "=== backup completed: $(date) ==="
diff --git a/rootfs/usr/share/scripts/create_bucket b/rootfs/usr/share/scripts/create_bucket
new file mode 100755
index 0000000..addadaa
--- /dev/null
+++ b/rootfs/usr/share/scripts/create_bucket
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+set -e
+
+mkdir -p ~/.config/rclone
+touch ~/.config/rclone/rclone.conf
+rclone config create storage s3 \
+  provider=Other \
+  access_key_id="${DRYCC_STORAGE_ACCESSKEY}" \
+  secret_access_key="${DRYCC_STORAGE_SECRETKEY}" \
+  endpoint="${DRYCC_STORAGE_ENDPOINT}" \
+  force_path_style="${DRYCC_STORAGE_PATH_STYLE:-true}" --no-output
+
+if ! rclone lsd storage: > /dev/null 2>&1; then
+  sleep 9s
+  echo "waiting for object storage to become ready..."
+fi
+
+rclone mkdir "storage:${DRYCC_STORAGE_BUCKET}"
