Add listmonk to community train (#1633)

* initial commit

* add templates

* add description

* more ci values

* add description

* add readme

* probe path

* run 1 test only

* fix init

* hmm

* I see

* test this

* add questions and metadata

* fix path
This commit is contained in:
Stavros Kois
2023-10-14 23:20:39 +03:00
committed by GitHub
parent 2046d5924d
commit 0bd1b519c4
22 changed files with 758 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
dependencies:
- name: common
repository: file://../../../common
version: 1.1.1
digest: sha256:a7dbe3e4d42dbcd4325776e5e01a1d630c7f185f79e7ebf22b1b9cc80f56eed7
generated: "2023-10-11T15:34:06.716391369+03:00"

View File

@@ -0,0 +1,26 @@
name: listmonk
description: Listmonk is a self-hosted newsletter and mailing list manager.
annotations:
title: Listmonk
type: application
version: 1.0.0
apiVersion: v2
appVersion: v2.5.1
kubeVersion: '>=1.16.0-0'
maintainers:
- name: truenas
url: https://www.truenas.com/
email: dev@ixsystems.com
dependencies:
- name: common
repository: file://../../../common
version: 1.1.1
home: https://listmonk.app/
icon: https://listmonk.app/static/images/logo.svg
sources:
- https://hub.docker.com/r/listmonk/listmonk
- https://github.com/knadh/listmonk
- https://github.com/truenas/charts/tree/master/library/ix-dev/community/listmonk
keywords:
- mailing-list
- newsletter

View File

@@ -0,0 +1,12 @@
# Listmonk
[Listmonk](https://listmonk.app/) is a self-hosted newsletter and mailing list manager.
> When application is installed, a container will be launched with **root** privileges.
> This is required in order to apply the correct permissions to the `listmonk` directories.
> Afterward, the `listmonk` container will run as a **non**-root user (default `568`).
> Same applies to the `postgres` container. This will run afterwards as a **non**-root user (`999`).
> On each upgrade, a container will be launched with **root** privileges in order to apply the correct
> permissions to the `postgres` **backups** directory. Container that performs the backup will run as a **non**-root user (`999`) afterwards.
> Keep in mind the permissions on the backup directory will be changed to `999:999` on **every** update.
> But will only be changed once for the `listmonk` and `postgres` data directories.

View File

@@ -0,0 +1,12 @@
# Listmonk
[Listmonk](https://listmonk.app/) is a self-hosted newsletter and mailing list manager.
> When application is installed, a container will be launched with **root** privileges.
> This is required in order to apply the correct permissions to the `listmonk` directories.
> Afterward, the `listmonk` container will run as a **non**-root user (default `568`).
> Same applies to the `postgres` container. This will run afterwards as a **non**-root user (`999`).
> On each upgrade, a container will be launched with **root** privileges in order to apply the correct
> permissions to the `postgres` **backups** directory. Container that performs the backup will run as a **non**-root user (`999`) afterwards.
> Keep in mind the permissions on the backup directory will be changed to `999:999` on **every** update.
> But will only be changed once for the `listmonk` and `postgres` data directories.

View File

@@ -0,0 +1,14 @@
listmonkNetwork:
webPort: 31000
listmonkRunAs:
user: 1000
group: 1000
listmonkStorage:
uploads:
type: pvc
pgData:
type: pvc
pgBackup:
type: emptyDir

View File

@@ -0,0 +1,19 @@
listmonkNetwork:
webPort: 31000
listmonkConfig:
adminUsername: admin
adminPassword: password
listmonkStorage:
uploads:
type: pvc
pgData:
type: pvc
pgBackup:
type: emptyDir
additionalStorages:
- type: pvc
mountPath: /data1
- type: pvc
mountPath: /data2

View File

@@ -0,0 +1,11 @@
listmonkNetwork:
webPort: 30000
hostNetwork: true
listmonkStorage:
uploads:
type: pvc
pgData:
type: pvc
pgBackup:
type: emptyDir

View File

@@ -0,0 +1,10 @@
icon_url: https://listmonk.app/static/images/logo.svg
categories:
- productivity
screenshots:
- https://listmonk.app/static/images/splash.png
- https://listmonk.app/static/images/templating.png
- https://listmonk.app/static/images/performance.png
tags:
- mailing-list
- newsletter

View File

@@ -0,0 +1,8 @@
runAsContext:
- userName: listmonk
groupName: listmonk
gid: 568
uid: 568
description: Listmonk can run as any non-root user.
capabilities: []
hostMounts: []

View File

@@ -0,0 +1,325 @@
groups:
- name: Listmonk Configuration
description: Configure Listmonk
- name: User and Group Configuration
description: Configure User and Group for Listmonk
- name: Network Configuration
description: Configure Network for Listmonk
- name: Storage Configuration
description: Configure Storage for Listmonk
- name: Resources Configuration
description: Configure Resources for Listmonk
portals:
web_portal:
protocols:
- "$kubernetes-resource_configmap_portal_protocol"
host:
- "$kubernetes-resource_configmap_portal_host"
ports:
- "$kubernetes-resource_configmap_portal_port"
path: "$kubernetes-resource_configmap_portal_path"
questions:
- variable: listmonkConfig
label: ""
group: Listmonk Configuration
schema:
type: dict
attrs:
- variable: adminUsername
label: Admin Username (Optional)
description: |
The username for the Listmonk admin user.</br>
Leave empty to disable authentication.
schema:
type: string
default: ""
- variable: adminPassword
label: Admin Password
description: The password for the Listmonk admin user.
schema:
type: string
default: ""
show_if: [["adminUsername", "!=", ""]]
required: true
- variable: additionalEnvs
label: Additional Environment Variables
description: Configure additional environment variables for Listmonk.
schema:
type: list
default: []
items:
- variable: env
label: Environment Variable
schema:
type: dict
attrs:
- variable: name
label: Name
schema:
type: string
required: true
- variable: value
label: Value
schema:
type: string
required: true
- variable: listmonkRunAs
label: ""
group: User and Group Configuration
schema:
type: dict
attrs:
- variable: user
label: User ID
description: The user id that Listmonk will run as.
schema:
type: int
min: 2
default: 568
required: true
- variable: group
label: Group ID
description: The group id that Listmonk will run as.
schema:
type: int
min: 2
default: 568
required: true
- variable: listmonkNetwork
label: ""
group: Network Configuration
schema:
type: dict
attrs:
- variable: webPort
label: Web Port
description: The port for the Listmonk Web UI.
schema:
type: int
default: 30093
min: 9000
max: 65535
required: true
- variable: hostNetwork
label: Host Network
description: |
Bind to the host network. It's recommended to keep this disabled.</br>
schema:
type: boolean
default: false
- variable: listmonkStorage
label: ""
group: Storage Configuration
schema:
type: dict
attrs:
- variable: uploads
label: Listmonk Uploads Storage
description: The path to store Listmonk uploads.
schema:
type: dict
attrs:
- variable: type
label: Type
description: |
ixVolume: Is dataset created automatically by the system.</br>
Host Path: Is a path that already exists on the system.
schema:
type: string
required: true
default: ixVolume
enum:
- value: hostPath
description: Host Path (Path that already exists on the system)
- value: ixVolume
description: ixVolume (Dataset created automatically by the system)
- variable: datasetName
label: Dataset Name
schema:
type: string
show_if: [["type", "=", "ixVolume"]]
required: true
hidden: true
immutable: true
default: uploads
$ref:
- "normalize/ixVolume"
- variable: hostPath
label: Host Path
schema:
type: hostpath
show_if: [["type", "=", "hostPath"]]
immutable: true
required: true
- variable: pgData
label: Listmonk Postgres Data Storage
description: The path to store Listmonk Postgres Data.
schema:
type: dict
attrs:
- variable: type
label: Type
description: |
ixVolume: Is dataset created automatically by the system.</br>
Host Path: Is a path that already exists on the system.
schema:
type: string
required: true
default: ixVolume
enum:
- value: hostPath
description: Host Path (Path that already exists on the system)
- value: ixVolume
description: ixVolume (Dataset created automatically by the system)
- variable: datasetName
label: Dataset Name
schema:
type: string
show_if: [["type", "=", "ixVolume"]]
required: true
hidden: true
immutable: true
default: pgData
$ref:
- "normalize/ixVolume"
- variable: hostPath
label: Host Path
schema:
type: hostpath
show_if: [["type", "=", "hostPath"]]
immutable: true
required: true
- variable: pgBackup
label: Listmonk Postgres Backup Storage
description: The path to store Listmonk Postgres Backup.
schema:
type: dict
attrs:
- variable: type
label: Type
description: |
ixVolume: Is dataset created automatically by the system.</br>
Host Path: Is a path that already exists on the system.
schema:
type: string
required: true
default: ixVolume
enum:
- value: hostPath
description: Host Path (Path that already exists on the system)
- value: ixVolume
description: ixVolume (Dataset created automatically by the system)
- variable: datasetName
label: Dataset Name
schema:
type: string
show_if: [["type", "=", "ixVolume"]]
required: true
hidden: true
immutable: true
default: pgBackup
$ref:
- "normalize/ixVolume"
- variable: hostPath
label: Host Path
schema:
type: hostpath
show_if: [["type", "=", "hostPath"]]
immutable: true
required: true
- variable: additionalStorages
label: Additional Storage
description: Additional storage for Listmonk.
schema:
type: list
default: []
items:
- variable: storageEntry
label: Storage Entry
schema:
type: dict
attrs:
- variable: type
label: Type
description: |
ixVolume: Is dataset created automatically by the system.</br>
Host Path: Is a path that already exists on the system.
schema:
type: string
required: true
default: "ixVolume"
enum:
- value: "hostPath"
description: Host Path (Path that already exists on the system)
- value: "ixVolume"
description: ixVolume (Dataset created automatically by the system)
- variable: mountPath
label: Mount Path
description: The path inside the container to mount the storage.
schema:
type: path
required: true
- variable: hostPath
label: Host Path
description: The host path to use for storage.
schema:
type: hostpath
show_if: [["type", "=", "hostPath"]]
required: true
- variable: datasetName
label: Dataset Name
description: The name of the dataset to use for storage.
schema:
type: string
show_if: [["type", "=", "ixVolume"]]
required: true
immutable: true
default: "storage_entry"
$ref:
- "normalize/ixVolume"
- variable: resources
group: Resources Configuration
label: ""
schema:
type: dict
attrs:
- variable: limits
label: Limits
schema:
type: dict
attrs:
- variable: cpu
label: CPU
description: CPU limit for Listmonk.
schema:
type: string
max_length: 6
valid_chars: '^(0\.[1-9]|[1-9][0-9]*)(\.[0-9]|m?)$'
valid_chars_error: |
Valid CPU limit formats are</br>
- Plain Integer - eg. 1</br>
- Float - eg. 0.5</br>
- Milicpu - eg. 500m
default: "4000m"
required: true
- variable: memory
label: Memory
description: Memory limit for Listmonk.
schema:
type: string
max_length: 12
valid_chars: '^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$'
valid_chars_error: |
Valid Memory limit formats are</br>
- Suffixed with E/P/T/G/M/K - eg. 1G</br>
- Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi</br>
- Plain Integer in bytes - eg. 1024</br>
- Exponent - eg. 134e6
default: "8Gi"
required: true

View File

@@ -0,0 +1 @@
{{ include "ix.v1.common.lib.chart.notes" $ }}

View File

@@ -0,0 +1,41 @@
{{- define "listmonk.configuration" -}}
{{- $fullname := (include "ix.v1.common.lib.chart.names.fullname" $) -}}
{{- $dbHost := (printf "%s-postgres" $fullname) -}}
{{- $dbUser := "listmonk" -}}
{{- $dbName := "listmonk" -}}
{{- $dbPass := (randAlphaNum 32) -}}
{{- with (lookup "v1" "Secret" .Release.Namespace (printf "%s-postgres-creds" $fullname)) -}}
{{- $dbPass = ((index .data "POSTGRES_PASSWORD") | b64dec) -}}
{{- end -}}
{{- $dbURL := (printf "postgres://%s:%s@%s:5432/%s?sslmode=disable" $dbUser $dbPass $dbHost $dbName) -}}
{{/* Temporary set dynamic db details on values,
so we can print them on the notes */}}
{{- $_ := set .Values "listmonkDbPass" $dbPass -}}
{{- $_ := set .Values "listmonkDbHost" $dbHost -}}
secret:
postgres-creds:
enabled: true
data:
POSTGRES_USER: {{ $dbUser }}
POSTGRES_DB: {{ $dbName }}
POSTGRES_PASSWORD: {{ $dbPass }}
POSTGRES_HOST: {{ $dbHost }}
POSTGRES_URL: {{ $dbURL }}
listmonk-creds:
enabled: true
data:
LISTMONK_app__address: {{ printf "0.0.0.0:%v" .Values.listmonkNetwork.webPort }}
LISTMONK_db__port: "5432"
LISTMONK_db__host: {{ $dbHost }}
LISTMONK_db__user: {{ $dbUser }}
LISTMONK_db__password: {{ $dbPass }}
LISTMONK_db__database: {{ $dbName }}
LISTMONK_db__sslmode: "disable"
LISTMONK_app__admin_username: {{ .Values.listmonkConfig.adminUsername | quote }}
LISTMONK_app__admin_password: {{ .Values.listmonkConfig.adminPassword | quote }}
{{- end -}}

View File

@@ -0,0 +1,68 @@
{{- define "listmonk.workload" -}}
workload:
listmonk:
enabled: true
primary: true
type: Deployment
podSpec:
hostNetwork: {{ .Values.listmonkNetwork.hostNetwork }}
containers:
listmonk:
enabled: true
primary: true
imageSelector: image
securityContext:
runAsUser: {{ .Values.listmonkRunAs.user }}
runAsGroup: {{ .Values.listmonkRunAs.group }}
envFrom:
- secretRef:
name: listmonk-creds
{{ with .Values.listmonkConfig.additionalEnvs }}
envList:
{{ range $env := . }}
- name: {{ $env.name }}
value: {{ $env.value }}
{{ end }}
{{ end }}
probes:
liveness:
enabled: true
type: http
port: {{ .Values.listmonkNetwork.webPort }}
path: /health
readiness:
enabled: true
type: http
port: {{ .Values.listmonkNetwork.webPort }}
path: /health
startup:
enabled: true
type: http
port: {{ .Values.listmonkNetwork.webPort }}
path: /health
initContainers:
{{- include "ix.v1.common.app.permissions" (dict "containerName" "01-permissions"
"UID" .Values.listmonkRunAs.user
"GID" .Values.listmonkRunAs.group
"mode" "check"
"type" "init") | nindent 8 }}
{{- include "ix.v1.common.app.postgresWait" (dict "name" "02-postgres-wait"
"secretName" "postgres-creds") | nindent 8 }}
03-db:
enabled: true
type: init
imageSelector: image
securityContext:
runAsUser: {{ .Values.listmonkRunAs.user }}
runAsGroup: {{ .Values.listmonkRunAs.group }}
envFrom:
- secretRef:
name: listmonk-creds
command:
- /bin/sh
args:
- -c
- |
/listmonk/listmonk --install --idempotent --yes
/listmonk/listmonk --upgrade --yes
{{- end -}}

View File

@@ -0,0 +1,64 @@
{{- define "listmonk.persistence" -}}
persistence:
uploads:
enabled: true
type: {{ .Values.listmonkStorage.uploads.type }}
datasetName: {{ .Values.listmonkStorage.uploads.datasetName | default "" }}
hostPath: {{ .Values.listmonkStorage.uploads.hostPath | default "" }}
targetSelector:
listmonk:
listmonk:
mountPath: /listmonk/uploads
01-permissions:
mountPath: /mnt/directories/uploads
tmp:
enabled: true
type: emptyDir
targetSelector:
listmonk:
listmonk:
mountPath: /tmp
{{- range $idx, $storage := .Values.listmonkStorage.additionalStorages }}
{{ printf "listmonk-%v" (int $idx) }}:
enabled: true
type: {{ $storage.type }}
datasetName: {{ $storage.datasetName | default "" }}
hostPath: {{ $storage.hostPath | default "" }}
targetSelector:
listmonk:
listmonk:
mountPath: {{ $storage.mountPath }}
{{- end -}}
{{/* Database */}}
postgresdata:
enabled: true
type: {{ .Values.listmonkStorage.pgData.type }}
datasetName: {{ .Values.listmonkStorage.pgData.datasetName | default "" }}
hostPath: {{ .Values.listmonkStorage.pgData.hostPath | default "" }}
targetSelector:
# Postgres pod
postgres:
# Postgres container
postgres:
mountPath: /var/lib/postgresql/data
# Postgres - Permissions container
# Different than the 01-permissions
permissions:
mountPath: /mnt/directories/postgres_data
postgresbackup:
enabled: true
type: {{ .Values.listmonkStorage.pgBackup.type }}
datasetName: {{ .Values.listmonkStorage.pgBackup.datasetName | default "" }}
hostPath: {{ .Values.listmonkStorage.pgBackup.hostPath | default "" }}
targetSelector:
# Postgres backup pod
postgresbackup:
# Postgres backup container
postgresbackup:
mountPath: /postgres_backup
# Postgres - Permissions container
# Different than the 01-permissions
permissions:
mountPath: /mnt/directories/postgres_backup
{{- end -}}

View File

@@ -0,0 +1,12 @@
{{- define "listmonk.portal" -}}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: portal
data:
path: "/"
port: {{ .Values.listmonkNetwork.webPort | quote }}
protocol: "http"
host: $node_ip
{{- end -}}

View File

@@ -0,0 +1,6 @@
{{- define "postgres.workload" -}}
workload:
{{- include "ix.v1.common.app.postgres" (dict "secretName" "postgres-creds"
"resources" .Values.resources
"ixChartContext" .Values.ixChartContext) | nindent 2 }}
{{- end -}}

View File

@@ -0,0 +1,26 @@
{{- define "listmonk.service" -}}
service:
listmonk:
enabled: true
primary: true
type: NodePort
targetSelector: listmonk
ports:
webui:
enabled: true
primary: true
port: {{ .Values.listmonkNetwork.webPort }}
nodePort: {{ .Values.listmonkNetwork.webPort }}
targetSelector: listmonk
postgres:
enabled: true
type: ClusterIP
targetSelector: postgres
ports:
postgres:
enabled: true
primary: true
port: 5432
targetPort: 5432
targetSelector: postgres
{{- end -}}

View File

@@ -0,0 +1,13 @@
{{- include "ix.v1.common.loader.init" . -}}
{{/* Merge the templates with Values */}}
{{- $_ := mustMergeOverwrite .Values (include "listmonk.configuration" $ | fromYaml) -}}
{{- $_ := mustMergeOverwrite .Values (include "listmonk.persistence" $ | fromYaml) -}}
{{- $_ := mustMergeOverwrite .Values (include "listmonk.service" $ | fromYaml) -}}
{{- $_ := mustMergeOverwrite .Values (include "listmonk.workload" $ | fromYaml) -}}
{{- $_ := mustMergeOverwrite .Values (include "postgres.workload" $ | fromYaml) -}}
{{/* Create the configmap for portal manually*/}}
{{- include "listmonk.portal" $ -}}
{{- include "ix.v1.common.loader.apply" . -}}

View File

@@ -0,0 +1 @@
{"filename": "values.yaml", "keys": ["image"]}

View File

@@ -0,0 +1,31 @@
#!/usr/bin/python3
import json
import re
import sys
from catalog_update.upgrade_strategy import semantic_versioning
RE_STABLE_VERSION = re.compile(r'v\d+\.\d+\.\d+')
def newer_mapping(image_tags):
key = list(image_tags.keys())[0]
tags = {t.strip('v'): t for t in image_tags[key] if RE_STABLE_VERSION.fullmatch(t)}
version = semantic_versioning(list(tags))
if not version:
return {}
return {
'tags': {key: tags[version]},
'app_version': version,
}
if __name__ == '__main__':
try:
versions_json = json.loads(sys.stdin.read())
except ValueError:
raise ValueError('Invalid json specified')
print(json.dumps(newer_mapping(versions_json)))

View File

@@ -0,0 +1,52 @@
image:
repository: listmonk/listmonk
pullPolicy: IfNotPresent
tag: v2.5.1
resources:
limits:
cpu: 4000m
memory: 8Gi
listmonkConfig:
adminUsername: ''
adminPassword: ''
additionalEnvs: []
listmonkNetwork:
webPort: 30093
hostNetwork: false
listmonkRunAs:
user: 568
group: 568
listmonkStorage:
uploads:
type: ixVolume
datasetName: uploads
pgData:
type: ixVolume
datasetName: pgData
pgBackup:
type: ixVolume
datasetName: pgBackup
additionalStorages: []
notes:
custom: |
## Database
You can connect to the database using the pgAdmin App from the catalog
<details>
<summary>Database Details</summary>
- Database: `listmonk`
- Username: `listmonk`
- Password: `{{ .Values.listmonkDbPass }}`
- Host: `{{ .Values.listmonkDbHost }}.{{ .Release.Namespace }}.svc.cluster.local`
- Port: `5432`
</details>
{{- $_ := unset .Values "listmonkDbPass" }}
{{- $_ := unset .Values "listmonkDbHost" }}