Skip to content

Commit

Permalink
Move cron to a CronJob, queue to a DaemonSet, and add a volume for co…
Browse files Browse the repository at this point in the history
…ntainer nginx files
  • Loading branch information
asbiin committed Oct 26, 2024
1 parent eadc81a commit f3f6bdb
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
helm_args: '--set=nginx.enabled=true --set=image.tag=main-fpm'

- name: Horizontal Pod Autoscaling Enabled
helm_args: '--set=hpa.enabled=true --set=hpa.minPods=2 --set=hpa.maxPods=3 --set=hpa.targetCPUUtilizationPercentage=75'
helm_args: '--set=hpa.enabled=true --set=hpa.minPods=2 --set=hpa.maxPods=3 --set=hpa.cputhreshold=75'

- name: Redis and queue enabled
file: redis.yaml
Expand Down
19 changes: 16 additions & 3 deletions charts/monica/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: monica
description: A Helm chart for Kubernetes to install Monica
type: application
version: 1.0.10
version: 1.0.11
appVersion: "5.0.0"
icon: https://raw.githubusercontent.com/monicahq/monica/aa98c09/public/img/favicon.svg
maintainers:
Expand All @@ -12,10 +12,9 @@ maintainers:
email: [email protected]
keywords:
- crm
kubeVersion: ">=1.16.0-0"
kubeVersion: ">=1.31.0-0"
sources:
- https://github.com/monicahq/helm
- https://github.com/monicahq/docker
dependencies:
- name: postgresql
version: 16.0.*
Expand Down Expand Up @@ -47,3 +46,17 @@ annotations:
artifacthub.io/screenshots: |
- title: Document your life
url: https://user-images.githubusercontent.com/61099/242266547-63d98bd9-35f3-4dfe-92f4-a4a8dd75aa5c.png
artifacthub.io/images: |
- name: monica-next
image: ghcr.io/monicahq/monica-next:main
platforms:
- linux/amd64
artifacthub.io/license: AGPL-3.0
artifacthub.io/links: |
- name: Helm Charts Source
url: https://github.com/monicahq/helm
- name: Website
url: https://www.monicahq.com/
- name: Source Code
url: https://github.com/monicahq/monica

Check failure on line 62 in charts/monica/Chart.yaml

View workflow job for this annotation

GitHub Actions / Lint chart files

62:1 [empty-lines] too many blank lines (1 > 0)
10 changes: 6 additions & 4 deletions charts/monica/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# monica

![Version: 1.0.10](https://img.shields.io/badge/Version-1.0.10-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 5.0.0](https://img.shields.io/badge/AppVersion-5.0.0-informational?style=flat-square)
![Version: 1.0.11](https://img.shields.io/badge/Version-1.0.11-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 5.0.0](https://img.shields.io/badge/AppVersion-5.0.0-informational?style=flat-square)

A Helm chart for Kubernetes to install Monica

Expand All @@ -14,11 +14,10 @@ A Helm chart for Kubernetes to install Monica
## Source Code

* <https://github.com/monicahq/helm>
* <https://github.com/monicahq/docker>

## Requirements

Kubernetes: `>=1.16.0-0`
Kubernetes: `>=1.31.0-0`

| Repository | Name | Version |
|------------|------|---------|
Expand Down Expand Up @@ -98,6 +97,8 @@ Kubernetes: `>=1.16.0-0`
| monica.phpConfigs | object | `{}` | |
| monica.queue.enabled | bool | `false` | |
| monica.queue.lifecycle | object | `{}` | |
| monica.queue.priorityClassName | string | `"important"` | |
| monica.queue.terminationGracePeriodSeconds | int | `20` | |
| monica.storagedir | string | `"/var/www/html/storage"` | |
| monica.strategy.type | string | `"Recreate"` | |
| nameOverride | string | `""` | |
Expand All @@ -120,6 +121,7 @@ Kubernetes: `>=1.16.0-0`
| postgresql.global.postgresql.auth.password | string | `"secret"` | |
| postgresql.global.postgresql.auth.username | string | `"monica"` | |
| postgresql.primary.persistence.enabled | bool | `false` | |
| rbac.create | bool | `true` | |
| readinessProbe.enabled | bool | `true` | |
| readinessProbe.failureThreshold | int | `3` | |
| readinessProbe.initialDelaySeconds | int | `10` | |
Expand All @@ -138,7 +140,7 @@ Kubernetes: `>=1.16.0-0`
| service.type | string | `"ClusterIP"` | |
| serviceAccount.annotations | object | `{}` | |
| serviceAccount.create | bool | `true` | |
| serviceAccount.name | string | `""` | |
| serviceAccount.name | string | `nil` | |
| startupProbe.enabled | bool | `false` | |
| startupProbe.failureThreshold | int | `30` | |
| startupProbe.initialDelaySeconds | int | `30` | |
Expand Down
3 changes: 3 additions & 0 deletions charts/monica/files/init-publicdir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ln -sf ../storage /var/www/html/public/storage
rm -rf /public/*
cp -ra /var/www/html/public/* /public
2 changes: 1 addition & 1 deletion charts/monica/files/nginx-config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ server {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
# Check that the PHP script exists before passing it
# try_files $fastcgi_script_name =404;
try_files $fastcgi_script_name =404;
fastcgi_pass php-handler;
fastcgi_index index.php;
Expand Down
2 changes: 1 addition & 1 deletion charts/monica/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Create environment variables used to configure the monica container as well as t
- name: DB_DATABASE
{{- if .Values.postgresql.auth.database }}
value: {{ .Values.postgresql.auth.database | quote }}
{{ else }}
{{- else }}
value: {{ .Values.postgresql.global.postgresql.auth.database | quote }}
{{- end }}
- name: DB_USERNAME
Expand Down
48 changes: 48 additions & 0 deletions charts/monica/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{- if .Values.monica.cronjob.enabled }}
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ template "monica.fullname" . }}-cron
labels:
{{- include "monica.labels" . | nindent 4 }}
app.kubernetes.io/component: cronjob
spec:
schedule: "*/1 * * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
{{- with .Values.image.pullSecrets }}
imagePullSecrets:
{{- range . }}
- name: {{ . }}
{{- end }}
{{- end }}
template:
spec:
containers:
- name: {{ .Chart.Name }}-cronjob
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/sh
- -c
- php /var/www/html/artisan schedule:run -v
env:
{{- include "monica.env" . | indent 16 }}
resources:
{{ toYaml .Values.resources | indent 16 }}
volumeMounts:
{{- include "monica.volumeMounts" . | trim | nindent 16 }}
restartPolicy: Never
volumes:
{{- if .Values.persistence.enabled }}
- name: monica-storage
persistentVolumeClaim:
claimName: {{ if .Values.persistence.existingClaim }}{{ .Values.persistence.existingClaim }}{{- else }}{{ template "monica.fullname" . }}-storage{{- end }}
{{- end }}
{{- with .Values.monica.extraVolumes }}
{{ toYaml . | indent 12 }}
{{- end }}

{{- end }}
78 changes: 12 additions & 66 deletions charts/monica/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,62 +132,6 @@ spec:
volumeMounts:
{{- include "monica.volumeMounts" . | trim | nindent 12 }}

{{- if .Values.monica.cronjob.enabled }}
- name: {{ .Chart.Name }}-cron
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: [ 'cron.sh' ]
{{- with .Values.monica.cronjob.lifecycle }}
lifecycle:
{{- with .postStartCommand }}
postStart:
exec:
command:
{{- toYaml . | nindent 18 }}
{{- end }}
{{- if .preStopCommand }}
preStop:
exec:
command:
{{- toYaml . | nindent 18 }}
{{- end }}
{{- end }}
env:
{{- include "monica.env" . | indent 12 }}
resources:
{{ toYaml .Values.resources | indent 12 }}
volumeMounts:
{{- include "monica.volumeMounts" . | trim | nindent 12 }}
{{- end }}{{/* monica.cronjob.enabled */}}

{{- if .Values.monica.queue.enabled }}
- name: {{ .Chart.Name }}-queue
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: [ 'queue.sh' ]
{{- with .Values.monica.queue.lifecycle }}
lifecycle:
{{- if .postStartCommand }}
postStart:
exec:
command:
{{- toYaml . | nindent 18 }}
{{- end }}
{{- if .preStopCommand }}
preStop:
exec:
command:
{{- toYaml . | nindent 18 }}
{{- end }}
{{- end }}
env:
{{- include "monica.env" . | indent 12 }}
resources:
{{ toYaml .Values.resources | indent 12 }}
volumeMounts:
{{- include "monica.volumeMounts" . | trim | nindent 12 }}
{{- end }}{{/* monica.queue.enabled */}}

{{- if .Values.nginx.enabled }}
- name: {{ .Chart.Name }}-nginx
image: "{{ .Values.nginx.image.repository }}:{{ .Values.nginx.image.tag }}"
Expand Down Expand Up @@ -251,12 +195,16 @@ spec:
resources:
{{ toYaml .Values.nginx.resources | indent 12 }}
volumeMounts:
- name: monica-nginx-config
mountPath: /etc/nginx/conf.d/
readOnly: true
- name: monica-publicdir
mountPath: /var/www/html/public
readOnly: true
{{- if .Values.persistence.enabled }}
- name: monica-storage
mountPath: {{ .Values.monica.datadir }}
mountPath: {{ .Values.monica.storagedir }}
{{- end }}
- name: monica-nginx-config
mountPath: /etc/nginx/conf.d/
{{- with .Values.monica.extraVolumeMounts }}
{{ toYaml . | indent 12 }}
{{- end }}
Expand Down Expand Up @@ -295,7 +243,7 @@ spec:
- {{ printf "until mariadb --host=%s-mariadb --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --execute=\"SELECT 1;\"; do echo waiting for mysql; sleep 2; done;" .Release.Name }}
{{- else if .Values.postgresql.enabled }}
- name: postgresql-isready
image: {{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}
image: {{ .Values.postgresql.image.registry | default "docker.io" }}/{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}
env:
- name: POSTGRES_USER
valueFrom:
Expand Down Expand Up @@ -327,11 +275,6 @@ spec:
persistentVolumeClaim:
claimName: {{ if .Values.persistence.existingClaim }}{{ .Values.persistence.existingClaim }}{{- else }}{{ template "monica.fullname" . }}-storage{{- end }}
{{- end }}
{{- if .Values.monica.configs }}
- name: monica-config
configMap:
name: {{ template "monica.fullname" . }}-config
{{- end }}
{{- if .Values.monica.phpConfigs }}
- name: monica-phpconfig
configMap:
Expand All @@ -341,6 +284,9 @@ spec:
- name: monica-nginx-config
configMap:
name: {{ template "monica.fullname" . }}-nginxconfig
- name: monica-publicdir
persistentVolumeClaim:
claimName: {{ template "monica.fullname" . }}-publicdir
{{- end }}
{{- with .Values.monica.extraVolumes }}
{{ toYaml . | indent 8 }}
Expand All @@ -358,6 +304,6 @@ spec:
fsGroup: 33
{{- end }}

{{- if .Values.serviceAccount.create }}
{{- if .Values.rbac.create }}
serviceAccountName: {{ include "monica.serviceAccountName" . }}
{{- end }}
42 changes: 42 additions & 0 deletions charts/monica/templates/nginx-init-publicdir.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{- if .Values.nginx.enabled }}
---
kind: Job
apiVersion: batch/v1
metadata:
name: {{ template "monica.fullname" . }}-init
labels:
{{- include "monica.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade,pre-rollback
"helm.sh/hook-weight": "5"
"helm.sh/hook-delete-policy": before-hook-creation
spec:
template:
metadata:
name: {{ template "monica.fullname" . }}-init
labels:
{{- include "monica.labels" . | nindent 8 }}
spec:
{{- with .Values.image.pullSecrets }}
imagePullSecrets:
{{- range . }}
- name: {{ . }}
{{- end }}
{{- end }}
containers:
- name: monica-nginx-init
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- "sh"
- "-c"
- {{ .Files.Get "files/init-publicdir.sh" | quote }}
volumeMounts:
- name: monica-publicdir
mountPath: /public
restartPolicy: Never
volumes:
- name: monica-publicdir
persistentVolumeClaim:
claimName: {{ template "monica.fullname" . }}-publicdir
{{- end }}
16 changes: 16 additions & 0 deletions charts/monica/templates/nginx-volume-publicdir.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.nginx.enabled }}
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "monica.fullname" . }}-publicdir
labels:
{{- include "monica.labels" . | nindent 4 }}
app.kubernetes.io/component: app
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Mi
{{- end -}}
20 changes: 9 additions & 11 deletions charts/monica/templates/persistent-volume.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{- if .Values.persistence.enabled -}}
{{- if not .Values.persistence.existingClaim -}}
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) -}}
---
kind: PersistentVolumeClaim
apiVersion: v1
Expand All @@ -10,21 +9,20 @@ metadata:
app.kubernetes.io/component: app
annotations:
helm.sh/resource-policy: keep
{{- with .Values.persistence.annotations }}
{{- with .Values.persistence.annotations }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- end }}
spec:
accessModes:
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- if .Values.persistence.storageClass }}
{{- if (eq "-" .Values.persistence.storageClass) }}
{{- with .Values.persistence.storageClass }}
{{- if (eq "-" .) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end -}}
{{- else }}
storageClassName: "{{ . }}"
{{- end }}
{{- end }}
{{- end -}}
Loading

0 comments on commit f3f6bdb

Please sign in to comment.