Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ckan): Add backup logic #471

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion stable/ckan/conf/ckan/overlay-production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@
#

[app:main]
ckan.site_title = CKAN-SCHEMING-FDI
ckan.locales_offered = en fr
ckan.site_logo = /base/images/ckan-logo.png
ckan.site_description =
ckan.auth.user_create_organizations = False
ckan.auth.user_create_groups = False
ckan.auth.user_delete_groups = false
ckan.auth.user_delete_organizations = false
ckan.auth.create_dataset_if_not_in_organization = False
ckan.auth.create_unowned_dataset = False
ckan.auth.public_activity_stream_detail = true
ckan.favicon = /base/images/ckan.ico
ckan.gravatar_default = identicon
ckan.preview.direct = png jpg gif
Expand Down
13 changes: 13 additions & 0 deletions stable/ckan/templates/cm/ckan-crontab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.ckan.backup.enabled }}
{{- $fullName := include "ckan.fullname" . -}}
{{- $adminuser := .Values.ckan.backup.adminuser -}}
kind: ConfigMap
apiVersion: v1
metadata:
name: {{ include "ckan.fullname" . }}-crontabs
data:
{{- range $key, $value := .Values.ckan.cronjobs }}
{{ $key }}.sh: |
{{ $value.command }} -c /srv/app/production.ini -O /app/backup/{{ $fullName }}-{{ $key }}-$(date +%Y-%m-%d).json1.gz -z -u {{ $adminuser }} >> /app/backup/{{ $fullName }}-{{ $key }}-$(date +%Y-%m-%d)-log.txt ;
{{- end }}
{{- end }}
34 changes: 31 additions & 3 deletions stable/ckan/templates/deploy/ckan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ spec:
securityContext:
{{- toYaml .Values.ckan.podSecurityContext | nindent 8 }}
volumes:
{{- if .Values.ckan.backup.enabled }}
- name: "ckan-backup"
azureFile:
secretName: {{ include "ckan.fullname" . }}-ckan-backup-secret
shareName: {{ .Values.ckan.backup.shareName }}
- name: {{ include "ckan.fullname" . }}-crontabs
configMap:
name: {{ include "ckan.fullname" . }}-crontabs
defaultMode: 0755
{{- end }}
- name: {{ include "ckan.fullname" . }}-ini-overlay-configmap
configMap:
name: {{ include "ckan.fullname" . }}-ini-overlay-configmap
Expand Down Expand Up @@ -66,7 +76,7 @@ spec:
{{ end }}
initContainers:
- name: create-production-ini
image: "{{ .Values.initContainer.image.repository }}:{{ .Values.initContainer.image.tag }}"
image: busybox
command:
- "sh"
- "-c"
Expand All @@ -82,7 +92,7 @@ spec:
readOnly: false
{{- if .Values.ckan.persistence.enabled }}
- name: set-volume-ownership
image: "{{ .Values.initContainer.image.repository }}:{{ .Values.initContainer.image.tag }}"
image: busybox
command:
- "sh"
- "-c"
Expand All @@ -97,7 +107,7 @@ spec:
containers:
{{ if .Values.pgbouncer.enabled }}
- name: pgbouncer
image: "{{ .Values.pgbouncer.image.repository }}:{{ .Values.pgbouncer.image.tag }}"
image: mcr.microsoft.com/azure-oss-db-tools/pgbouncer-sidecar:latest
imagePullPolicy: Always
ports:
- containerPort: 5432
Expand Down Expand Up @@ -241,6 +251,14 @@ spec:
- |
set -e
source $CKAN_VENV/bin/activate
sudo service cron start
{{- if .Values.ckan.backup.enabled }}
echo "#!/usr/bin/bash" | crontab -
(crontab -l ; echo "PATH=/usr/lib/ckan/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") | crontab -
{{- range $key, $value := .Values.ckan.cronjobs }}
(crontab -l ; echo {{ $value.crontab | quote }}) | crontab -
{{- end }}
{{- end }}
ckan generate config /srv/app/production.ini
python3 <<EOF | xargs -I{} ckan config-tool /srv/app/production.ini "{}"
from ckan.config.environment import CONFIG_FROM_ENV_VARS
Expand All @@ -255,6 +273,8 @@ spec:
ckan config-tool /srv/app/production.ini -f /config/production.ini
ckan -c /srv/app/production.ini db init
python3 /srv/prerun/prerun.py
printenv > /tmp/enviroment
sudo bash -c "cat /tmp/enviroment > /etc/environment"
ckan -c /srv/app/production.ini run --host 0.0.0.0
ports:
- name: http
Expand Down Expand Up @@ -305,6 +325,8 @@ spec:
secretKeyRef:
name: {{ include "ckan.fullname" . }}
key: sysadminPassword
- name: BEAKER_SESSION_SECRET
value: {{ .Values.ckan.beaker_session_secret }}
- name: CKAN_SYSADMIN_EMAIL
value: {{ .Values.ckan.sysadminEmail }}
- name: CKAN_SITE_TITLE
Expand Down Expand Up @@ -410,6 +432,12 @@ spec:
failureThreshold: {{ .Values.ckan.liveness.failureThreshold }}
timeoutSeconds: {{ .Values.ckan.liveness.timeoutSeconds }}
volumeMounts:
{{- if .Values.ckan.backup.enabled}}
- mountPath: "/app/backup"
name: "ckan-backup"
- name: {{ include "ckan.fullname" . }}-crontabs
mountPath: /app/
{{- end }}
- name: {{ include "ckan.fullname" . }}-prerun-configmap
mountPath: /srv/prerun
- name: {{ include "ckan.fullname" . }}-ini-overlay-configmap
Expand Down
10 changes: 10 additions & 0 deletions stable/ckan/templates/secret/ckan-backup-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if .Values.ckan.backup.enabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "ckan.fullname" . }}-ckan-backup-secret
type: Opaque
data:
azurestorageaccountname: {{ .Values.ckan.backup.azurestorageaccountname | b64enc }}
azurestorageaccountkey: {{ .Values.ckan.backup.azurestorageaccountkey | b64enc }}
{{- end }}
6 changes: 6 additions & 0 deletions stable/ckan/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ ckan:
activityStreamsEmailNotifications_jobs: "false"
debug: "false"
maintenanceMode: "false"
backup:
adminuser: ""
enabled: true
shareName: ""
azurestorageaccountname: ""
azurestorageaccountkey: ""
psql:
initialize: true
db:
Expand Down
Loading