Skip to content

Commit

Permalink
Merge pull request #6 from sonroyaalmerol/fix-init-helm
Browse files Browse the repository at this point in the history
helm: fix init containers
  • Loading branch information
sonroyaalmerol authored May 17, 2024
2 parents 7ba65a1 + bbb4b8f commit 2f6a752
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 25 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/helm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Update Chart AppVersion
env:
ACTION_TRIGGER: ${{github.event_name}}
if: github.event_name == 'workflow_call'
run: |
CHART_PATH="charts/sogo/Chart.yaml"
Expand All @@ -52,12 +51,7 @@ jobs:
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
if [ "$ACTION_TRIGGER" = "workflow_dispatch" ]; then
# Increment the version
PATCH=$((PATCH + 1))
else
MINOR=$((MINOR + 1))
fi
MINOR=$((MINOR + 1))
# Form the new version
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
Expand Down
6 changes: 3 additions & 3 deletions charts/sogo/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: sogo
version: 0.1.0
version: 0.1.1
description: A helm chart for the docker-sogo docker image
type: application
keywords:
Expand Down Expand Up @@ -32,11 +32,11 @@ annotations:
url: https://www.sogo.nu/img/screenshot.png
dependencies:
- name: postgresql
version: 12.12.*
version: 15.3.*
repository: oci://registry-1.docker.io/bitnamicharts
condition: postgresql.enabled
- name: mariadb
version: 12.2.*
version: 18.0.*
repository: oci://registry-1.docker.io/bitnamicharts
condition: mariadb.enabled
- name: memcached
Expand Down
56 changes: 56 additions & 0 deletions charts/sogo/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,62 @@ OCSSessionsFolderURL: {{ printf "%s/sogo_sessions_folder" (include "sogo.db.base
OCSAdminURL: {{ printf "%s/sogo_admin" (include "sogo.db.baseUrl" .) }}
{{- end -}}

{{- define "sogo.db.parsed.type" -}}
{{- if .Values.sogo.configs.OCSFolderInfoURL }}
{{- $parts := split "://" .Values.sogo.configs.OCSFolderInfoURL -}}
{{- $db_type := $parts._0 -}}
{{- printf "%s" $db_type -}}
{{- end -}}
{{- end -}}

{{- define "sogo.db.parsed.hostname" -}}
{{- if .Values.sogo.configs.OCSFolderInfoURL }}
{{- $parts := split "://" .Values.sogo.configs.OCSFolderInfoURL -}}
{{- $db_type := $parts._0 -}}
{{- $remaining := $parts._1 -}}
{{- $parts = split "/" $remaining -}}
{{- $base_url = split "@" $parts._0 -}}
{{- $host = split ":" $base_url._1 -}}
{{- printf "%s" $host._0 -}}
{{- end -}}
{{- end -}}

{{- define "sogo.db.parsed.port" -}}
{{- if .Values.sogo.configs.OCSFolderInfoURL }}
{{- $parts := split "://" .Values.sogo.configs.OCSFolderInfoURL -}}
{{- $db_type := $parts._0 -}}
{{- $remaining := $parts._1 -}}
{{- $parts = split "/" $remaining -}}
{{- $base_url = split "@" $parts._0 -}}
{{- $host = split ":" $base_url._1 -}}
{{- printf "%s" $host._1 -}}
{{- end -}}
{{- end -}}

{{- define "sogo.db.parsed.username" -}}
{{- if .Values.sogo.configs.OCSFolderInfoURL }}
{{- $parts := split "://" .Values.sogo.configs.OCSFolderInfoURL -}}
{{- $db_type := $parts._0 -}}
{{- $remaining := $parts._1 -}}
{{- $parts = split "/" $remaining -}}
{{- $base_url = split "@" $parts._0 -}}
{{- $auth = split ":" $base_url._0 -}}
{{- printf "%s" $auth._0 -}}
{{- end -}}
{{- end -}}

{{- define "sogo.db.parsed.password" -}}
{{- if .Values.sogo.configs.OCSFolderInfoURL }}
{{- $parts := split "://" .Values.sogo.configs.OCSFolderInfoURL -}}
{{- $db_type := $parts._0 -}}
{{- $remaining := $parts._1 -}}
{{- $parts = split "/" $remaining -}}
{{- $base_url = split "@" $parts._0 -}}
{{- $auth = split ":" $base_url._0 -}}
{{- printf "%s" $auth._1 -}}
{{- end -}}
{{- end -}}

{{- define "sogo.memcached.configs" -}}
SOGoMemcachedHost: {{ template "common.names.fullname" .Subcharts.memcached }}
{{- end -}}
Expand Down
24 changes: 24 additions & 0 deletions charts/sogo/templates/db-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- if or .Values.mariadb.enabled .Values.postgresql.enabled .Values.sogo.configs.OCSFolderInfoURL }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-db
labels:
app.kubernetes.io/name: {{ include "sogo.name" . }}
helm.sh/chart: {{ include "sogo.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
type: Opaque
data:
{{- if .Values.sogo.configs.OCSFolderInfoURL }}
db-username: {{ include "sogo.db.parsed.username" . | b64enc | quote }}
db-password: {{ include "sogo.db.parsed.password" . | b64enc | quote }}
{{- else if .Values.mariadb.enabled }}
db-username: {{ .Values.mariadb.auth.username | b64enc | quote }}
db-password: {{ .Values.mariadb.auth.password | b64enc | quote }}
{{- else if .Values.postgresql.enabled }}
db-username: {{ .Values.postgresql.global.postgresql.auth.username | b64enc | quote }}
db-password: {{ .Values.postgresql.global.postgresql.auth.password | b64enc | quote }}
{{- end }}
{{- end }}
44 changes: 30 additions & 14 deletions charts/sogo/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,34 +156,50 @@ spec:
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if or .Values.sogo.extraInitContainers }}
{{- if or .Values.sogo.extraInitContainers .Values.sogo.configs.OCSFolderInfoURL .Values.mariadb.enabled .Values.postgresql.enabled }}
initContainers:
{{- with .Values.sogo.extraInitContainers }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if or .Values.sogo.configs.OCSFolderInfoURL }}
{{- $parts := split "://" .Values.sogo.configs.OCSFolderInfoURL -}}
{{- $db_type := $parts._0 -}}
{{- $remaining := $parts._1 -}}
{{- $parts = split "/" $remaining -}}
{{- $base_url = split "@" $parts._0 -}}
{{- $auth = split ":" $base_url._0 -}}
{{- $host = split ":" $base_url._1 -}}
{{- if eq $db_type "mysql" }}
{{- if or .Values.mariadb.enabled (eq (include "sogo.db.parsed.type" .) "mysql") }}
- name: mariadb-isalive
image: {{ .Values.mariadb.image.registry | default "docker.io" }}/{{ .Values.mariadb.image.repository }}:{{ .Values.mariadb.image.tag }}
env:
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: {{ printf "%s-db" .Release.Name }}
key: db-username
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: {{ printf "%s-db" .Release.Name }}
key: db-password
- name: MYSQL_HOST
value: {{ include "sogo.db.parsed.hostname" . | default (printf "%s-mariadb" .Release.Name) }}
- name: MYSQL_PORT
value: {{ include "sogo.db.parsed.port" . | default "3306" | quote }}
command:
- "sh"
- "-c"
- {{ printf "until mysql --host=%s --user=%s --password=%s --execute=\"SELECT 1;\"; do echo waiting for mysql; sleep 2; done;" $host._0 $auth._0 $auth._1 }}
{{- else if eq $db_type "postgresql" }}
- "until mysql --host=${MYSQL_HOST} --port=${MYSQL_PORT} --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --execute=\"SELECT 1;\"; do echo waiting for mysql; sleep 2; done;"
{{- else if or .Values.postgresql.enabled (eq (include "sogo.db.parsed.type" .) "postgresql") }}
- name: postgresql-isready
image: {{ .Values.postgresql.image.registry | default "docker.io" }}/{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: {{ printf "%s-db" .Release.Name }}
key: db-username
- name: POSTGRES_HOST
value: {{ include "sogo.db.parsed.hostname" . | default (include "postgresql.v1.primary.fullname" .Subcharts.postgresql) }}
- name: POSTGRES_PORT
value: {{ include "sogo.db.parsed.port" . | default "5432" | quote }}
command:
- "sh"
- "-c"
- {{ printf "until pg_isready -h %s -U %s ; do sleep 2 ; done" $host._0 $auth._0 }}
{{- end }}
- "until pg_isready -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} ; do sleep 2 ; done"
{{- end }}{{/* end-if any database-initContainer */}}
{{- end }}{{/* end-if any initContainer */}}
{{- with .Values.affinity }}
Expand Down

0 comments on commit 2f6a752

Please sign in to comment.