diff --git a/cnpg-liquid/.helmignore b/cnpg-liquid/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/cnpg-liquid/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/cnpg-liquid/Chart.yaml b/cnpg-liquid/Chart.yaml new file mode 100644 index 0000000..b90eca7 --- /dev/null +++ b/cnpg-liquid/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: cnpg-liquid +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/liquid-code-chart/templates/cnpg-cluster.yaml b/cnpg-liquid/templates/cnpg-cluster.yaml similarity index 95% rename from liquid-code-chart/templates/cnpg-cluster.yaml rename to cnpg-liquid/templates/cnpg-cluster.yaml index b872b3c..611bd99 100644 --- a/liquid-code-chart/templates/cnpg-cluster.yaml +++ b/cnpg-liquid/templates/cnpg-cluster.yaml @@ -2,6 +2,9 @@ apiVersion: postgresql.cnpg.io/v1 kind: Cluster metadata: name: {{ required "Cluster name required" .Values.cnpg.clusterName }} + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "-1" spec: startDelay: 300 stopDelay: 300 diff --git a/cnpg-liquid/values.yaml b/cnpg-liquid/values.yaml new file mode 100644 index 0000000..02935fb --- /dev/null +++ b/cnpg-liquid/values.yaml @@ -0,0 +1,14 @@ +s3: + endpointUrl: https://storage.yandexcloud.net + secretName: s3-credentials + accessKeyKey: ACCESS_KEY_ID + secretKeyKey: ACCESS_SECRET_KEY +cnpg: + clusterName: liquid-db + backup: + enable: true + destinationPath: "s3://liquid-code/backup" + recovery: + enable: false + oldClusterName: liquid-db + sourcePath: "s3://liquid-code/backup" \ No newline at end of file diff --git a/liquid-code-chart/templates/Deployments/backend-deployment.yaml b/liquid-code-chart/templates/Deployments/backend-deployment.yaml index deb1686..fe8980b 100644 --- a/liquid-code-chart/templates/Deployments/backend-deployment.yaml +++ b/liquid-code-chart/templates/Deployments/backend-deployment.yaml @@ -34,7 +34,7 @@ spec: - name: PG_URI valueFrom: secretKeyRef: - name: {{ required "Cluster name required" .Values.cnpg.clusterName }}-app + name: {{ required "Cluster creds secret required!" .Values.database.secretName }} key: uri envFrom: - secretRef: diff --git a/liquid-code-chart/templates/pre-install-migration.yaml b/liquid-code-chart/templates/pre-install-migration.yaml new file mode 100644 index 0000000..0cbc4ee --- /dev/null +++ b/liquid-code-chart/templates/pre-install-migration.yaml @@ -0,0 +1,37 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: {{.Release.Name}}-migration-job + labels: + app.kubernetes.io/managed-by: {{.Release.Service | quote }} + app.kubernetes.io/instance: {{.Release.Name | quote }} + app.kubernetes.io/version: {{ .Chart.AppVersion }} + helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}" + annotations: + "helm.sh/hook": pre-install +spec: + template: + metadata: + name: {{.Release.Name}}-migration-pod + labels: + app.kubernetes.io/managed-by: {{.Release.Service | quote }} + app.kubernetes.io/instance: {{.Release.Name | quote }} + helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}" + spec: + restartPolicy: Never + containers: + - name: {{ .Release.Name }}-backend + image: ghcr.io/nullptroma/liquid-backend:1.0.0 + imagePullPolicy: Always + ports: + - containerPort: 8080 + env: + - name: PG_URI + valueFrom: + secretKeyRef: + name: {{ required "Cluster creds secret required!" .Values.database.secretName }} + key: uri + - name: MIGRATE_ONLY + value: "1" + imagePullSecrets: + - name: github-registry \ No newline at end of file diff --git a/liquid-code-chart/values.yaml b/liquid-code-chart/values.yaml index e5c991a..692b39a 100644 --- a/liquid-code-chart/values.yaml +++ b/liquid-code-chart/values.yaml @@ -3,15 +3,8 @@ s3: secretName: s3-credentials accessKeyKey: ACCESS_KEY_ID secretKeyKey: ACCESS_SECRET_KEY -cnpg: - clusterName: liquid-db - backup: - enable: true - destinationPath: "s3://liquid-code/backup" - recovery: - enable: false - oldClusterName: liquid-db - sourcePath: "s3://liquid-code/backup" jwt: secretName: jwt-secrets +database: + secretName: liquid-db-app imagePullSecret: github-registry