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

Wait until the database is reachable in job-create-site #207

Merged
merged 16 commits into from
Jun 29, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
85 changes: 68 additions & 17 deletions erpnext/templates/job-create-site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ metadata:
name: {{ template "erpnext.fullname" . }}-new-site-{{ now | date "20060102150405" }}
labels:
{{- include "erpnext.labels" . | nindent 4 }}
annotations:
{{- with .Values.jobs.createSite.annotations }}
{{- range $key, $value := . }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
spec:
backoffLimit: {{ .Values.jobs.createSite.backoffLimit }}
template:
Expand Down Expand Up @@ -36,6 +42,33 @@ spec:
fi
done;
echo "sites/common_site_config.json found";

echo "Waiting for database to be reachable...";
wait-for-it -t 180 $(DB_HOST):$(DB_PORT);
echo "Database is reachable.";
env:
- name: "DB_HOST"
{{- if .Values.postgresql.host }}
value: {{ .Values.postgresql.host }}
{{- else if .Values.postgresql.enabled }}
value: {{ .Release.Name }}-postgresql
{{- else if .Values.mariadb.enabled }}
{{- if eq .Values.mariadb.architecture "replication" }}
value: {{ .Release.Name }}-mariadb-primary
{{- else }}
value: {{ .Release.Name }}-mariadb
{{- end }}
{{- else }}
value: "{{ .Values.dbHost }}"
{{- end }}
- name: "DB_PORT"
{{- if .Values.dbPort }}
value: {{ .Values.dbPort | quote }}
{{- else if .Values.postgresql.enabled }}
value: {{ .Values.postgresql.primary.service.ports.postgresql | quote }}
{{- else }}
value: {{ .Values.mariadb.primary.service.ports.mysql | quote }}
{{- end }}
resources:
{{- toYaml .Values.jobs.createSite.resources | nindent 12 }}
securityContext:
Expand All @@ -50,23 +83,41 @@ spec:
command: ["bash", "-c"]
args:
- >
bench new-site $(SITE_NAME)
--no-mariadb-socket
--db-type=$(DB_TYPE)
--db-host=$(DB_HOST)
--db-port=$(DB_PORT)
--admin-password=$(ADMIN_PASSWORD)
--mariadb-root-username=$(DB_ROOT_USER)
--mariadb-root-password=$(DB_ROOT_PASSWORD)
{{- if .Values.jobs.createSite.installApps }}
{{- range .Values.jobs.createSite.installApps }}
--install-app={{ . }}
{{- end }}
{{- end }}
{{- if .Values.jobs.createSite.forceCreate }}
--force
{{- end }}
;rm -f currentsite.txt
set -x;

bench_output=$(bench new-site ${SITE_NAME} \
--no-mariadb-socket \
--db-type=${DB_TYPE} \
--db-host=${DB_HOST} \
--db-port=${DB_PORT} \
--admin-password=${ADMIN_PASSWORD} \
--mariadb-root-username=${DB_ROOT_USER} \
--mariadb-root-password=${DB_ROOT_PASSWORD} \
{{- if .Values.jobs.createSite.installApps }}
{{- range .Values.jobs.createSite.installApps }}
--install-app={{ . }} \
{{- end }}
{{- end }}
{{- if .Values.jobs.createSite.forceCreate }}
--force \
{{- end }}
| tee /dev/stderr);

bench_exit_status=$?;

if [ $bench_exit_status -ne 0 ]; then
# Don't consider the case "site already exists" an error.
if [[ $bench_output == *"already exists"* ]]; then
echo "Site already exists, continuing...";
else
echo "An error occurred in bench new-site: $bench_output"
exit $bench_exit_status;
fi
fi

set -e;

rm -f currentsite.txt
env:
- name: "SITE_NAME"
value: "{{ .Values.jobs.createSite.siteName }}"
Expand Down
Loading