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 (#16)
  • Loading branch information
asbiin authored Oct 27, 2024
1 parent eadc81a commit 1db38f0
Show file tree
Hide file tree
Showing 18 changed files with 321 additions and 111 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ updates:
directory: '/'
schedule:
interval: weekly

# Maintain dependencies for Helm
- package-ecosystem: docker
directory: /charts/monica
schedule:
interval: weekly
7 changes: 5 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
env:
helm: v3.16.2
python-version: 3.x
kubectl: v1.16.0

jobs:
linter:
Expand Down Expand Up @@ -55,7 +56,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 Expand Up @@ -96,8 +97,10 @@ jobs:
- name: Create kind cluster
uses: helm/kind-action@v1
if: steps.list-changed.outputs.changed == 'true'
with:
kubectl_version: ${{ env.kubectl }}

- name: Cp test case file
- name: Copy test case file
if: matrix.test_cases.file != ''
run: cp .github/tests/${{ matrix.test_cases.file }} charts/monica/ci/test-values.yaml

Expand Down
32 changes: 32 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Contributing

## Testing

Install prerequisites:
- [helm](https://helm.sh/)
- [helm chart testing](https://github.com/helm/chart-testing)
- [minikube](https://minikube.sigs.k8s.io/docs/start/)

Start minikube:

```sh
minikube start
```

Start chart-testing:

```sh
ct install --config ct.yaml --helm-extra-args '--timeout 200s'
```

You can also add a yaml file in the `charts/monica/ci` directory to test the chart with different values.

## Pre-commit

This repository uses [pre-commit](https://pre-commit.com/) to run checks before each commit.

To install pre-commit, run:

```sh
pre-commit install
```
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[Helm](https://helm.sh) repo for different charts related to Monica which can be installed on [Kubernetes](https://kubernetes.io)

### Add Helm repository
## Add Helm repository

To install the repo just run:

Expand All @@ -11,7 +11,7 @@ helm repo add monica https://monicahq.github.io/helm/
helm repo update
```

### Helm Charts
## Helm Charts

* [monica](https://monicahq.github.io/helm/)

Expand All @@ -24,3 +24,18 @@ helm repo update
```

For more information, please checkout the chart level [README.md](./charts/monica/README.md).


## Contributing

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

## License

Author: [Alexis Saettler](https://github.com/asbiin)

This project is part of [MonicaHQ](https://github.com/monicahq/).

Copyright © 2019–2024.

Licensed under the AGPL-3.0 License. [View license](LICENSE.md).
31 changes: 29 additions & 2 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 @@ -15,7 +15,6 @@ keywords:
kubeVersion: ">=1.16.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,31 @@ 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
artifacthub.io/changes: |
- kind: changed
description: Use a CronJob for the cron job instead of a container
- kind: changed
description: Use a DaemonSet for the queue instead of a container
- kind: fixed
description: Fix static file rendering (css, js, ...) for nginx using and emptydir
- kind: fixed
description: Fixed hpa test value
- kind: fixed
description: Fixed phpConfigs rendering
- kind: added
description: Added a rbac.create option
- kind: added
description: Added a monica.queue.priorityClassName option
8 changes: 5 additions & 3 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,7 +14,6 @@ A Helm chart for Kubernetes to install Monica
## Source Code

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

## Requirements

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
31 changes: 28 additions & 3 deletions 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 Expand Up @@ -261,10 +261,35 @@ Create volume mounts for the monica storagedir.
{{- with .Values.monica.extraVolumeMounts }}
{{ toYaml . }}
{{- end }}
{{- $nginxEnabled := .Values.nginx.enabled -}}
{{- range $key, $value := .Values.monica.phpConfigs }}
- name: monica-phpconfig
mountPath: {{ $nginxEnabled | ternary (printf "/usr/local/etc/php-fpm.d/%s" $key | quote) (printf "/usr/local/etc/php/conf.d/%s" $key | quote) }}
mountPath: {{ printf "/usr/local/etc/php/conf.d/%s" $key | quote }}
subPath: {{ $key }}
{{- end }}
{{- if .Values.nginx.enabled }}
{{- range $key, $value := .Values.monica.phpConfigs }}
- name: monica-phpconfig
mountPath: {{ printf "/usr/local/etc/php-fpm.d/%s" $key | quote }}
subPath: {{ $key }}
{{- end }}
{{- end }}
{{- end -}}

{{/*
Create volumes for the monica storagedir.
*/}}
{{- define "monica.volumes" -}}
{{- if .Values.persistence.enabled }}
- name: monica-storage
persistentVolumeClaim:
claimName: {{ if .Values.persistence.existingClaim }}{{ .Values.persistence.existingClaim }}{{- else }}{{ template "monica.fullname" . }}-storage{{- end }}
{{- end }}
{{- if .Values.monica.phpConfigs }}
- name: monica-phpconfig
configMap:
name: {{ template "monica.fullname" . }}-phpconfig
{{- end }}
{{- with .Values.monica.extraVolumes }}
{{ toYaml . }}
{{- end }}
{{- end -}}
43 changes: 43 additions & 0 deletions charts/monica/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- 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
annotations:
helm.sh/hook: post-install,post-upgrade,post-rollback
helm.sh/hook-weight: "15"
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:
{{- include "monica.volumes" . | trim | nindent 12 }}
{{- end }}
Loading

0 comments on commit 1db38f0

Please sign in to comment.