Skip to content

Commit 772c7af

Browse files
authored
Fix the nginx template (#12)
1 parent 6ec6bc6 commit 772c7af

File tree

18 files changed

+390
-214
lines changed

18 files changed

+390
-214
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
internalDatabase:
2+
enabled: false
3+
4+
externalDatabase:
5+
enabled: true
6+
type: mysql
7+
user: root
8+
password: root
9+
database: monica
10+
host: %DB_HOST%

.github/workflows/docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ on:
55
types: [opened, synchronize, reopened]
66

77
jobs:
8-
release:
8+
docs:
99
runs-on: ubuntu-latest
10+
name: Helm docs
1011
steps:
1112
- name: Checkout
1213
uses: actions/checkout@v4

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212

1313
jobs:
1414
release:
15+
name: Release Charts
1516
runs-on: ubuntu-latest
1617
steps:
1718
- name: Checkout

.github/workflows/tests.yml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ env:
99

1010
jobs:
1111
linter:
12+
name: Lint chart files
1213
runs-on: ubuntu-latest
1314
steps:
1415
- name: Checkout
@@ -39,24 +40,32 @@ jobs:
3940
fail-fast: false
4041
matrix:
4142
test_cases:
42-
# test the plain helm chart with nothing changed
4343
- name: Default - no custom values
4444

45-
# test the helm chart with postgresql subchart enabled
4645
- name: PostgreSQL enabled
4746
helm_args: '--set=internalDatabase.enabled=false --set=postgresql.enabled=true'
4847

49-
# test the helm chart with mariadb subchart enabled
5048
- name: Mariadb enabled
5149
helm_args: '--set=internalDatabase.enabled=false --set=mariadb.enabled=true'
5250

53-
# test the helm chart with redis, queue and more
51+
- name: Nodeport service enabled
52+
helm_args: '--set=service.type=NodePort --set=service.nodePort=30001'
53+
54+
- name: nginx enabled
55+
helm_args: '--set=nginx.enabled=true --set=image.tag=main-fpm'
56+
57+
- name: Horizontal Pod Autoscaling Enabled
58+
helm_args: '--set=hpa.enabled=true --set=hpa.minPods=2 --set=hpa.maxPods=3 --set=hpa.targetCPUUtilizationPercentage=75'
59+
5460
- name: Redis and queue enabled
5561
file: redis.yaml
5662

57-
# test the helm chart with meilisearch
5863
- name: Meilisearch and queue enabled
59-
file: meilisearch.yaml
64+
file: meilisearch.yaml
65+
66+
# - name: External database
67+
# external_database: true
68+
# file: external_database.yaml
6069

6170
steps:
6271
- name: Checkout
@@ -92,5 +101,17 @@ jobs:
92101
if: matrix.test_cases.file != ''
93102
run: cp .github/tests/${{ matrix.test_cases.file }} charts/monica/ci/test-values.yaml
94103

104+
- name: Create mysql database
105+
if: matrix.test_cases.external_database
106+
run: |
107+
sudo systemctl start mysql.service
108+
mysql --protocol=tcp -u root -proot -e "CREATE DATABASE IF NOT EXISTS monica CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
109+
hostname -I
110+
IFS=' '
111+
read -ra hostname <<< $(hostname -I)
112+
DB_HOST=${hostname[1]}
113+
sed -i "s/%DB_HOST%/$DB_HOST/" charts/monica/ci/test-values.yaml
114+
95115
- name: Run chart-testing (install)
96-
run: ct install --config ct.yaml --helm-extra-args '--timeout 600s' --target-branch ${{ github.event.repository.default_branch }} --helm-extra-set-args "--set=image.repository=ghcr.io/monicahq/monica-next --set=image.tag=main ${{ matrix.test_cases.helm_args }}"
116+
if: steps.list-changed.outputs.changed == 'true'
117+
run: ct install --config ct.yaml --helm-extra-args '--timeout 600s' --target-branch ${{ github.event.repository.default_branch }} --helm-extra-set-args "${{ matrix.test_cases.helm_args }}"

charts/monica/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ apiVersion: v2
22
name: monica
33
description: A Helm chart for Kubernetes to install Monica
44
type: application
5-
version: 1.0.7
5+
version: 1.0.8
66
appVersion: "5.0.0"
7-
icon: https://www.monicahq.com/favicon.ico
7+
icon: https://raw.githubusercontent.com/monicahq/monica/aa98c09/public/img/favicon.svg
88
maintainers:
99
- name: MonicaHQ
1010
url: https://github.com/monicahq/monica

charts/monica/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# monica
22

3-
![Version: 1.0.7](https://img.shields.io/badge/Version-1.0.7-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)
3+
![Version: 1.0.8](https://img.shields.io/badge/Version-1.0.8-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)
44

55
A Helm chart for Kubernetes to install Monica
66

@@ -42,6 +42,10 @@ Kubernetes: `>=1.16.0-0`
4242
| externalDatabase.type | string | `"mysql"` | |
4343
| externalDatabase.user | string | `"monica"` | |
4444
| fullnameOverride | string | `""` | |
45+
| hpa.cputhreshold | int | `60` | |
46+
| hpa.enabled | bool | `false` | |
47+
| hpa.maxPods | int | `10` | |
48+
| hpa.minPods | int | `1` | |
4549
| image.pullPolicy | string | `"IfNotPresent"` | |
4650
| image.repository | string | `"ghcr.io/monicahq/monica-next"` | |
4751
| image.tag | string | `"main"` | |
@@ -53,6 +57,12 @@ Kubernetes: `>=1.16.0-0`
5357
| internalDatabase.enabled | bool | `true` | |
5458
| internalDatabase.name | string | `"/var/www/html/database/monica.sqlite"` | |
5559
| lifecycle | object | `{}` | |
60+
| livenessProbe.enabled | bool | `true` | |
61+
| livenessProbe.failureThreshold | int | `3` | |
62+
| livenessProbe.initialDelaySeconds | int | `10` | |
63+
| livenessProbe.periodSeconds | int | `10` | |
64+
| livenessProbe.successThreshold | int | `1` | |
65+
| livenessProbe.timeoutSeconds | int | `5` | |
5666
| mariadb.architecture | string | `"standalone"` | |
5767
| mariadb.auth.database | string | `"monica"` | |
5868
| mariadb.auth.password | string | `"secret"` | |
@@ -92,6 +102,7 @@ Kubernetes: `>=1.16.0-0`
92102
| monica.strategy.type | string | `"Recreate"` | |
93103
| nameOverride | string | `""` | |
94104
| nginx.config.default | bool | `true` | |
105+
| nginx.containerPort | int | `80` | |
95106
| nginx.enabled | bool | `false` | |
96107
| nginx.image.pullPolicy | string | `"IfNotPresent"` | |
97108
| nginx.image.repository | string | `"nginx"` | |
@@ -109,6 +120,12 @@ Kubernetes: `>=1.16.0-0`
109120
| postgresql.global.postgresql.auth.password | string | `"secret"` | |
110121
| postgresql.global.postgresql.auth.username | string | `"monica"` | |
111122
| postgresql.primary.persistence.enabled | bool | `false` | |
123+
| readinessProbe.enabled | bool | `true` | |
124+
| readinessProbe.failureThreshold | int | `3` | |
125+
| readinessProbe.initialDelaySeconds | int | `10` | |
126+
| readinessProbe.periodSeconds | int | `10` | |
127+
| readinessProbe.successThreshold | int | `1` | |
128+
| readinessProbe.timeoutSeconds | int | `5` | |
112129
| redis.auth.enabled | bool | `true` | |
113130
| redis.auth.password | string | `"secret"` | |
114131
| redis.enabled | bool | `false` | |
@@ -122,6 +139,12 @@ Kubernetes: `>=1.16.0-0`
122139
| serviceAccount.annotations | object | `{}` | |
123140
| serviceAccount.create | bool | `true` | |
124141
| serviceAccount.name | string | `""` | |
142+
| startupProbe.enabled | bool | `false` | |
143+
| startupProbe.failureThreshold | int | `30` | |
144+
| startupProbe.initialDelaySeconds | int | `30` | |
145+
| startupProbe.periodSeconds | int | `10` | |
146+
| startupProbe.successThreshold | int | `1` | |
147+
| startupProbe.timeoutSeconds | int | `5` | |
125148
| tests.unitTests.resources.limits.cpu | string | `"200m"` | |
126149
| tests.unitTests.resources.limits.memory | string | `"256Mi"` | |
127150
| tests.unitTests.resources.requests.cpu | string | `"100m"` | |
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
upstream php-handler {
2+
server 127.0.0.1:9000;
3+
}
4+
5+
server {
6+
listen {{ .Values.nginx.containerPort | default 80 }};
7+
listen [::]:{{ .Values.nginx.containerPort | default 80 }};
8+
9+
## HSTS ##
10+
# Add the 'Strict-Transport-Security' headers to enable HSTS protocol.
11+
# WARNING: Only add the preload option once you read about the consequences: https://hstspreload.org/.
12+
# This form will add the domain to a hardcoded list that is shipped in all major browsers and getting
13+
# removed from this list could take several months.
14+
#
15+
#add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload;" always;
16+
17+
add_header Referrer-Policy "no-referrer" always;
18+
add_header X-Content-Type-Options "nosniff" always;
19+
add_header X-Download-Options "noopen" always;
20+
add_header X-Frame-Options "SAMEORIGIN" always;
21+
add_header X-Permitted-Cross-Domain-Policies "none" always;
22+
add_header X-Robots-Tag "none" always;
23+
add_header X-XSS-Protection "1; mode=block" always;
24+
25+
# Remove X-Powered-By, which is an information leak
26+
fastcgi_hide_header X-Powered-By;
27+
28+
root /var/www/html/public;
29+
30+
index index.php index.html index.htm;
31+
32+
charset utf-8;
33+
34+
location / {
35+
try_files $uri $uri/ /index.php?$query_string;
36+
}
37+
38+
location ~ ^/(?:robots.txt|security.txt) {
39+
allow all;
40+
log_not_found off;
41+
access_log off;
42+
}
43+
44+
error_page 404 500 502 503 504 /index.php;
45+
46+
location ~ /\.well-known/(?:carddav|caldav) {
47+
return 301 $scheme://$host/dav;
48+
}
49+
location = /.well-known/security.txt {
50+
return 301 $scheme://$host/security.txt;
51+
}
52+
location ~ /\.(?!well-known).* {
53+
deny all;
54+
}
55+
56+
# set max upload size
57+
client_max_body_size 10G;
58+
fastcgi_buffers 64 4K;
59+
60+
# Enable gzip but do not remove ETag headers
61+
gzip on;
62+
gzip_vary on;
63+
gzip_comp_level 4;
64+
gzip_min_length 256;
65+
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
66+
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
67+
68+
# Uncomment if your server is build with the ngx_pagespeed module
69+
# This module is currently not supported.
70+
#pagespeed off;
71+
72+
location ~ \.php(?:$|/) {
73+
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
74+
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
75+
76+
# Check that the PHP script exists before passing it
77+
# try_files $fastcgi_script_name =404;
78+
79+
fastcgi_pass php-handler;
80+
fastcgi_index index.php;
81+
82+
include fastcgi_params;
83+
84+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
85+
# Bypass the fact that try_files resets $fastcgi_path_info
86+
# see: http://trac.nginx.org/nginx/ticket/321
87+
set $path_info $fastcgi_path_info;
88+
fastcgi_param PATH_INFO $path_info;
89+
}
90+
91+
# Adding the cache control header for js and css files
92+
# Make sure it is BELOW the PHP block
93+
location ~ \.(?:css|js|woff2?|svg|gif|json)$ {
94+
try_files $uri /index.php$request_uri;
95+
add_header Cache-Control "public, max-age=15778463";
96+
97+
## HSTS ##
98+
# Add the 'Strict-Transport-Security' headers to enable HSTS protocol.
99+
# Note it is intended to have those duplicated to the ones above.
100+
# WARNING: Only add the preload option once you read about the consequences: https://hstspreload.org/.
101+
# This form will add the domain to a hardcoded list that is shipped in all major browsers and getting
102+
# removed from this list could take several months.
103+
#
104+
#add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload;" always;
105+
106+
add_header Referrer-Policy "no-referrer" always;
107+
add_header X-Content-Type-Options "nosniff" always;
108+
add_header X-Download-Options "noopen" always;
109+
add_header X-Frame-Options "SAMEORIGIN" always;
110+
add_header X-Permitted-Cross-Domain-Policies "none" always;
111+
add_header X-Robots-Tag "none" always;
112+
add_header X-XSS-Protection "1; mode=block" always;
113+
114+
# Optional: Don't log access to assets
115+
access_log off;
116+
}
117+
118+
location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
119+
try_files $uri /index.php$request_uri;
120+
121+
# Optional: Don't log access to assets
122+
access_log off;
123+
}
124+
125+
# deny access to .htaccess files
126+
location ~ /\.ht {
127+
deny all;
128+
}
129+
}

charts/monica/templates/NOTES.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ .Values.monica.host }}{{ $.Values.ingress.path }}
4+
{{- else if contains "NodePort" .Values.service.type }}
5+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "monica.fullname" . }})
6+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
7+
echo http://$NODE_IP:$NODE_PORT
8+
{{- else if contains "LoadBalancer" .Values.service.type }}
9+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
10+
You can watch the status of by running 'kubectl get svc -w {{ include "monica.fullname" . }}'
11+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "monica.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
12+
echo http://$SERVICE_IP:{{ .Values.service.port }}
13+
{{- else if contains "ClusterIP" .Values.service.type }}
14+
kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ template "monica.fullname" . }} {{ .Values.service.port }}:{{ .Values.service.port }} &
15+
echo "Visit http://127.0.0.1:{{ .Values.service.port }} to use your application"
16+
{{- end }}

charts/monica/templates/_helpers.tpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ Create chart name and version as used by the chart label.
3535
Common labels
3636
*/}}
3737
{{- define "monica.labels" -}}
38-
helm.sh/chart: {{ include "monica.chart" . }}
3938
{{ include "monica.selectorLabels" . }}
39+
helm.sh/chart: {{ include "monica.chart" . }}
40+
app.kubernetes.io/managed-by: {{ .Release.Service }}
4041
{{- if or .Chart.AppVersion .Values.image.tag }}
4142
app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }}
4243
{{- end }}
43-
app.kubernetes.io/managed-by: {{ .Release.Service }}
4444
{{- end -}}
4545

4646
{{/*
@@ -49,7 +49,6 @@ Selector labels
4949
{{- define "monica.selectorLabels" -}}
5050
app.kubernetes.io/name: {{ include "monica.name" . }}
5151
app.kubernetes.io/instance: {{ .Release.Name }}
52-
app.kubernetes.io/component: app
5352
{{- end -}}
5453

5554
{{/*

0 commit comments

Comments
 (0)