Skip to content

Commit

Permalink
helm: add default values and internal database options
Browse files Browse the repository at this point in the history
  • Loading branch information
sonroyaalmerol authored May 16, 2024
1 parent fb4e584 commit bea582d
Show file tree
Hide file tree
Showing 7 changed files with 486 additions and 120 deletions.
232 changes: 116 additions & 116 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,117 +1,117 @@
---
name: Release image
on: # yamllint disable-line rule:truthy
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
check_versions:
name: Release - Version checking
runs-on: ubuntu-latest
outputs:
base_version: ${{ steps.sogo.outputs.VERSION }}
revision: ${{ steps.image.outputs.REVISION }}
next_revision: ${{ steps.image.outputs.NEXT_REVISION }}
release: ${{ steps.condition.outputs.RELEASE }}
steps:
- name: Get latest version of SOGo
id: sogo
run: |
echo "VERSION=$(curl -s https://api.github.com/repos/Alinto/sogo/releases/latest | jq -r '.tag_name' | sed 's/SOGo-//')" >> "$GITHUB_OUTPUT"
- name: Get latest version of Docker image
id: image
run: |
RAW_LATEST_RELEASE=$(curl -s https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest)
VERSION=$(echo "$RAW_LATEST_RELEASE" | jq -r '.tag_name')
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "BASE_VERSION=$(echo "$VERSION" | sed 's/-.*//')" >> "$GITHUB_OUTPUT"
REVISION=$([[ "$VERSION" == *-* ]] && echo "$VERSION" | sed 's/.*-//' || echo "")
echo "REVISION=$REVISION" >> "$GITHUB_OUTPUT"
NEXT_REVISION=$([[ "$REVISION" =~ ^[0-9]+$ ]] && echo $(($REVISION + 1)) || echo 1)
echo "NEXT_REVISION=$NEXT_REVISION" >> "$GITHUB_OUTPUT"
- name: Decide if release version or not
id: condition
env:
SOGO_VERSION: ${{steps.sogo.outputs.VERSION}}
DOCKER_VERSION: ${{steps.image.outputs.BASE_VERSION}}
DOCKER_REVISION: ${{steps.image.outputs.REVISION}}
ACTION_TRIGGER: ${{github.event_name}}
run: |
VERSIONS_ARE_EQUAL=$([ "$SOGO_VERSION" = "$DOCKER_VERSION" ] && echo "true" || echo "false")
if [ "$ACTION_TRIGGER" = "workflow_dispatch" ] || [ "$VERSIONS_ARE_EQUAL" != "true" ]; then
RELEASE="true"
else
RELEASE="false"
fi
echo "RELEASE=$RELEASE" >> "$GITHUB_OUTPUT"
release:
name: Release - Docker image
needs: check_versions
runs-on: ubuntu-latest
if: needs.check_versions.outputs.release == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker - Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Docker - GHCR Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker - Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=${{ needs.check_versions.outputs.base_version }}
type=raw,value=${{ needs.check_versions.outputs.base_version }}-${{ needs.check_versions.outputs.next_revision }}
flavor: latest=true

- name: Docker - Build / Push
id: docker_build
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
SOGO_VERSION=${{ needs.check_versions.outputs.base_version }}
- name: Github Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check_versions.outputs.base_version }}-${{ needs.check_versions.outputs.next_revision }}
make_latest: 'true'
generate_release_notes: true
body: |
---
name: Release image
on: # yamllint disable-line rule:truthy
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
check_versions:
name: Release - Version checking
runs-on: ubuntu-latest
outputs:
base_version: ${{ steps.sogo.outputs.VERSION }}
revision: ${{ steps.image.outputs.REVISION }}
next_revision: ${{ steps.image.outputs.NEXT_REVISION }}
release: ${{ steps.condition.outputs.RELEASE }}
steps:
- name: Get latest version of SOGo
id: sogo
run: |
echo "VERSION=$(curl -s https://api.github.com/repos/Alinto/sogo/releases/latest | jq -r '.tag_name' | sed 's/SOGo-//')" >> "$GITHUB_OUTPUT"
- name: Get latest version of Docker image
id: image
run: |
RAW_LATEST_RELEASE=$(curl -s https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest)
VERSION=$(echo "$RAW_LATEST_RELEASE" | jq -r '.tag_name')
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "BASE_VERSION=$(echo "$VERSION" | sed 's/-.*//')" >> "$GITHUB_OUTPUT"
REVISION=$([[ "$VERSION" == *-* ]] && echo "$VERSION" | sed 's/.*-//' || echo "")
echo "REVISION=$REVISION" >> "$GITHUB_OUTPUT"
NEXT_REVISION=$([[ "$REVISION" =~ ^[0-9]+$ ]] && echo $(($REVISION + 1)) || echo 1)
echo "NEXT_REVISION=$NEXT_REVISION" >> "$GITHUB_OUTPUT"
- name: Decide if release version or not
id: condition
env:
SOGO_VERSION: ${{steps.sogo.outputs.VERSION}}
DOCKER_VERSION: ${{steps.image.outputs.BASE_VERSION}}
DOCKER_REVISION: ${{steps.image.outputs.REVISION}}
ACTION_TRIGGER: ${{github.event_name}}
run: |
VERSIONS_ARE_EQUAL=$([ "$SOGO_VERSION" = "$DOCKER_VERSION" ] && echo "true" || echo "false")
if [ "$ACTION_TRIGGER" = "workflow_dispatch" ] || [ "$VERSIONS_ARE_EQUAL" != "true" ]; then
RELEASE="true"
else
RELEASE="false"
fi
echo "RELEASE=$RELEASE" >> "$GITHUB_OUTPUT"
release:
name: Release - Docker image
needs: check_versions
runs-on: ubuntu-latest
if: needs.check_versions.outputs.release == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker - Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Docker - GHCR Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker - Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=${{ needs.check_versions.outputs.base_version }}
type=raw,value=${{ needs.check_versions.outputs.base_version }}-${{ needs.check_versions.outputs.next_revision }}
flavor: latest=true

- name: Docker - Build / Push
id: docker_build
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
SOGO_VERSION=${{ needs.check_versions.outputs.base_version }}
- name: Github Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check_versions.outputs.base_version }}-${{ needs.check_versions.outputs.next_revision }}
make_latest: 'true'
generate_release_notes: true
body: |
SOGo Update: https://github.com/Alinto/sogo/releases/tag/SOGo-${{ needs.check_versions.outputs.base_version }}
16 changes: 15 additions & 1 deletion charts/sogo/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ keywords:
- alinto
- inverse
- mail
- calendar
home: https://github.com/sonroyaalmerol/docker-sogo
sources:
- https://github.com/sonroyaalmerol/docker-sogo
Expand All @@ -16,7 +17,7 @@ maintainers:
email: [email protected]
url: https://github.com/sonroyaalmerol
icon: https://www.sogo.nu/img/sogo.svg
appVersion: "5.10.0-1"
appVersion: "5.10.0"
deprecated: false
annotations:
artifacthub.io/license: MIT
Expand All @@ -29,3 +30,16 @@ annotations:
artifacthub.io/screenshots: |
- title: SOGo
url: https://www.sogo.nu/img/screenshot.png
dependencies:
- name: postgresql
version: 12.12.*
repository: oci://registry-1.docker.io/bitnamicharts
condition: postgresql.enabled
- name: mariadb
version: 12.2.*
repository: oci://registry-1.docker.io/bitnamicharts
condition: mariadb.enabled
- name: memcached
version: 17.13.*
repository: oci://registry-1.docker.io/bitnamicharts
condition: redis.enabled
36 changes: 35 additions & 1 deletion charts/sogo/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,44 @@ Create image name that is used in the deployment
{{- if .Values.image.tag -}}
{{- printf "%s:%s" .Values.image.repository .Values.image.tag -}}
{{- else -}}
{{- printf "%s:%s-%s" .Values.image.repository .Chart.AppVersion .Values.image.flavor -}}
{{- if .Values.image.revision -}}
{{- printf "%s:%s-%s" .Values.image.repository .Chart.AppVersion .Values.image.revision -}}
{{- else -}}
{{- printf "%s:%s" .Values.image.repository .Chart.AppVersion -}}
{{- end -}}
{{- end -}}
{{- end -}}


{{/*
Create DB URL paths
*/}}
{{- define "sogo.db.baseUrl" -}}
{{- if .Values.postgresql.enabled -}}
{{- printf "postgresql://%s:%s@%s:5432/%s" (or .Values.postgresql.global.postgresql.auth.username .Values.postgresql.auth.username) (or .Values.postgresql.global.postgresql.auth.password .Values.postgresql.auth.password) (template "postgresql.v1.primary.fullname" .Subcharts.postgresql) (or .Values.postgresql.global.postgresql.auth.database .Values.postgresql.auth.database) -}}
{{- else if .Values.mariadb.enabled -}}
{{- printf "mysql://%s:%s@%s:3306/%s" .Values.mariadb.auth.username .Values.mariadb.auth.password (template "mariadb.primary.fullname" .Subcharts.mariadb) .Values.mariadb.auth.database -}}
{{- end -}}
{{- end -}}

{{- define "sogo.db.configs" -}}
SOGoProfileURL: {{ printf "%s/sogo_user_profile" (include "sogo.db.baseUrl" .) }}
OCSFolderInfoURL: {{ printf "%s/sogo_folder_info" (include "sogo.db.baseUrl" .) }}
OCSSessionsFolderURL: {{ printf "%s/sogo_sessions_folder" (include "sogo.db.baseUrl" .) }}
OCSAdminURL: {{ printf "%s/sogo_admin" (include "sogo.db.baseUrl" .) }}
{{- end -}}

{{- define "sogo.memcached.configs" -}}
SOGoMemcachedHost: {{ template "common.names.fullname" .Subcharts.memcached }}
{{- end -}}

{{- $parts := split "://" (include "sogo.db.baseUrl" .) -}}
{{- $db_type := index $parts 0 -}}
{{- $remaining := index $parts 1 -}}

{{- define "sogo.db.type" -}}
{{- printf "%s" $db_type -}}
{{- end -}}

{{- define "sogo.ingress.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}
Expand Down
10 changes: 9 additions & 1 deletion charts/sogo/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ metadata:
app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
configs: |
{{ .Values.sogo.configs | toYaml | indent 4 }}
{{- .Values.sogo.configs | toYaml | nindent 4 }}
{{- if or .Values.mariadb.enabled .Values.postgresql.enabled }}
internal-db: |
{{- include "sogo.db.configs" . | nindent 4 }}
{{- end }}
{{- if .Values.memcached.enabled }}
internal-memcached: |
{{- include "sogo.memcached.configs" . | nindent 4 }}
{{- end }}
{{- end }}
36 changes: 36 additions & 0 deletions charts/sogo/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ spec:
subPath: secrets
readOnly: true
{{- end }}
{{- if or .Values.mariadb.enabled .Values.postgresql.enabled }}
- name: sogo-configs
mountPath: /etc/sogo/sogo.conf.d/98-internal-db.yaml
subPath: internal-db
readOnly: true
{{- end }}
{{- if .Values.memcached.enabled }}
- name: sogo-configs
mountPath: /etc/sogo/sogo.conf.d/98-internal-memcached.yaml
subPath: internal-memcached
readOnly: true
{{- end }}
{{- with .Values.sogo.extraSidecarContainers }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -149,6 +161,30 @@ spec:
{{- 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" }}
- name: mariadb-isalive
image: {{ .Values.mariadb.image.registry | default "docker.io" }}/{{ .Values.mariadb.image.repository }}:{{ .Values.mariadb.image.tag }}
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" }}
- name: postgresql-isready
image: {{ .Values.postgresql.image.registry | default "docker.io" }}/{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}
command:
- "sh"
- "-c"
- {{ printf "until pg_isready -h %s -U %s ; do sleep 2 ; done" $host._0 $auth._0 }}
{{- end }}
{{- end }}{{/* end-if any database-initContainer */}}
{{- end }}{{/* end-if any initContainer */}}
{{- with .Values.affinity }}
affinity:
Expand Down
Loading

0 comments on commit bea582d

Please sign in to comment.