NAS-123672 / 24.04 / add joplin to community apps (#1471)

* add `joplin` to `community` apps

* add storage and service

* add more boilerplat

* add some test values

* add values

* update readme

* add basic ui

* add initialmeta

* add todo

* render config

* use 1001

* fix probes

* reduce permissiosn

* fix portal

* remove todo

* bump common

* simplify probe header

* add deafult creds

* remove redundant values

* update wording
This commit is contained in:
Stavros Kois
2023-08-30 14:19:06 +03:00
committed by GitHub
parent ea33912991
commit a4177f09dc
21 changed files with 579 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
dependencies:
- name: common
repository: file://../../../common
version: 1.1.0
digest: sha256:752ce76025f5b61094bd2b18ca11693eb9d26d0dde4eb2e63cd2330cbffe9e73
generated: "2023-08-24T18:43:23.380249283+03:00"

View File

@@ -0,0 +1,25 @@
name: joplin
description: Joplin is an open source note-taking app. Capture your thoughts and securely access them from any device
annotations:
title: Joplin
type: application
version: 1.0.0
apiVersion: v2
appVersion: 2.12.1-beta
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.0
home: https://joplinapp.org/
icon: https://raw.githubusercontent.com/laurent22/joplin/dev/Assets/LinuxIcons/256x256.png
sources:
- https://github.com/laurent22/joplin
- https://github.com/truenas/charts/tree/master/library/ix-dev/community/joplin
- https://hub.docker.com/r/joplin/server/
keywords:
- notes

View File

@@ -0,0 +1,11 @@
# Joplin
[Joplin](https://joplinapp.org) is an open source note-taking app. Capture your thoughts and securely access them from any device
> When application is installed, a container will be launched with **root** privileges.
> This is required in order to apply the correct permissions to the `postgres` directories.
> Afterward, the `postgres` container will run 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 `postgres` data directories.

View File

@@ -0,0 +1,11 @@
# Joplin
[Joplin](https://joplinapp.org) is an open source note-taking app. Capture your thoughts and securely access them from any device
> When application is installed, a container will be launched with **root** privileges.
> This is required in order to apply the correct permissions to the `postgres` directories.
> Afterward, the `postgres` container will run 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 `postgres` data directories.

View File

@@ -0,0 +1,10 @@
joplinNetwork:
webPort: 31000
joplinStorage:
pgData:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/pgData
pgBackup:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/pgBackup

View File

@@ -0,0 +1,11 @@
joplinNetwork:
webPort: 31000
hostNetwork: true
joplinStorage:
pgData:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/pgData
pgBackup:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/pgBackup

View File

@@ -0,0 +1,9 @@
icon_url: https://raw.githubusercontent.com/laurent22/joplin/dev/Assets/LinuxIcons/256x256.png
categories:
- productivity
screenshots:
- https://joplinapp.org/images/home-top-img-2x.webp
- https://joplinapp.org/images/multimedia-notes-img.png
- https://joplinapp.org/images/save-web-img.png
tags:
- notes

View File

@@ -0,0 +1,8 @@
runAsContext:
- userName: joplin
groupName: joplin
gid: 1001
uid: 1001
description: Joplin can run as a non-root user.
capabilities: []
hostMounts: []

View File

@@ -0,0 +1,207 @@
groups:
- name: Joplin Configuration
description: Configure Joplin
- name: Network Configuration
description: Configure Network for Joplin
- name: Storage Configuration
description: Configure Storage for Joplin
- name: Resources Configuration
description: Configure Resources for Joplin
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: joplinConfig
label: ""
group: Joplin Configuration
schema:
type: dict
attrs:
- variable: baseUrl
label: Base URL
description: |
The base URL for Joplin.</br>
Examples:</br>
https://joplin.example.com
http://192.168.1.100:30062
schema:
type: uri
default: ""
required: true
- variable: additionalEnvs
label: Additional Environment Variables
description: Configure additional environment variables for Joplin.
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: joplinNetwork
label: ""
group: Network Configuration
schema:
type: dict
attrs:
- variable: webPort
label: Web Port
description: The port for the Joplin Web UI.
schema:
type: int
default: 30062
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: joplinStorage
label: ""
group: Storage Configuration
schema:
type: dict
attrs:
- variable: pgData
label: Joplin Postgres Data Storage
description: The path to store Joplin 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: Joplin Postgres Backup Storage
description: The path to store Joplin 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: 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 Joplin.
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 Joplin.
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,29 @@
{{- define "joplin.configuration" -}}
{{- $fullname := (include "ix.v1.common.lib.chart.names.fullname" $) -}}
{{- $dbHost := (printf "%s-postgres" $fullname) -}}
{{- $dbUser := "joplin" -}}
{{- $dbName := "joplin" -}}
{{- $dbPass := randAlphaNum 32 -}}
{{- with (lookup "v1" "Secret" .Release.Namespace (printf "%s-postgres-creds" $fullname)) -}}
{{- $dbPass = ((index .data "POSTGRES_PASSWORD") | b64dec) -}}
{{- end -}}
{{/* Temporary set dynamic db details on values,
so we can print them on the notes */}}
{{- $_ := set .Values "joplinDbPass" $dbPass -}}
{{- $_ := set .Values "joplinDbHost" $dbHost -}}
{{- $dbURL := (printf "postgres://%s:%s@%s:5432/%s?sslmode=disable" $dbUser $dbPass $dbHost $dbName) }}
secret:
postgres-creds:
enabled: true
data:
POSTGRES_USER: {{ $dbUser }}
POSTGRES_DB: {{ $dbName }}
POSTGRES_PASSWORD: {{ $dbPass }}
POSTGRES_HOST: {{ $dbHost }}
POSTGRES_URL: {{ $dbURL }}
{{- end -}}

View File

@@ -0,0 +1,71 @@
{{- define "joplin.workload" -}}
workload:
joplin:
enabled: true
primary: true
type: Deployment
podSpec:
hostNetwork: {{ .Values.joplinNetwork.hostNetwork }}
containers:
joplin:
enabled: true
primary: true
imageSelector: image
securityContext:
runAsUser: 1001
runAsGroup: 1001
readOnlyRootFilesystem: false
env:
APP_PORT: {{ .Values.joplinNetwork.webPort }}
APP_BASE_URL: {{ .Values.joplinConfig.baseUrl }}
DB_CLIENT: pg
POSTGRES_PORT: 5432
POSTGRES_HOST:
secretKeyRef:
name: postgres-creds
key: POSTGRES_HOST
POSTGRES_DATABASE:
secretKeyRef:
name: postgres-creds
key: POSTGRES_DB
POSTGRES_USER:
secretKeyRef:
name: postgres-creds
key: POSTGRES_USER
POSTGRES_PASSWORD:
secretKeyRef:
name: postgres-creds
key: POSTGRES_PASSWORD
{{ with .Values.joplinConfig.additionalEnvs }}
envList:
{{ range $env := . }}
- name: {{ $env.name }}
value: {{ $env.value }}
{{ end }}
{{ end }}
probes:
liveness:
enabled: true
type: http
port: {{ .Values.joplinNetwork.webPort }}
path: /api/ping
httpHeaders:
Host: '{{ .Values.joplinConfig.baseUrl | trimPrefix "https://" | trimPrefix "http://" | trimSuffix "/" }}'
readiness:
enabled: true
type: http
port: {{ .Values.joplinNetwork.webPort }}
path: /api/ping
httpHeaders:
Host: '{{ .Values.joplinConfig.baseUrl | trimPrefix "https://" | trimPrefix "http://" | trimSuffix "/" }}'
startup:
enabled: true
type: http
port: {{ .Values.joplinNetwork.webPort }}
path: /api/ping
httpHeaders:
Host: '{{ .Values.joplinConfig.baseUrl | trimPrefix "https://" | trimPrefix "http://" | trimSuffix "/" }}'
initContainers:
{{- include "ix.v1.common.app.postgresWait" (dict "name" "postgres-wait"
"secretName" "postgres-creds") | nindent 8 }}
{{- end -}}

View File

@@ -0,0 +1,31 @@
{{- define "joplin.persistence" -}}
persistence:
postgresdata:
enabled: true
type: {{ .Values.joplinStorage.pgData.type }}
datasetName: {{ .Values.joplinStorage.pgData.datasetName | default "" }}
hostPath: {{ .Values.joplinStorage.pgData.hostPath | default "" }}
targetSelector:
# Postgres pod
postgres:
# Postgres container
postgres:
mountPath: /var/lib/postgresql/data
# Postgres - Permissions container
permissions:
mountPath: /mnt/directories/postgres_data
postgresbackup:
enabled: true
type: {{ .Values.joplinStorage.pgBackup.type }}
datasetName: {{ .Values.joplinStorage.pgBackup.datasetName | default "" }}
hostPath: {{ .Values.joplinStorage.pgBackup.hostPath | default "" }}
targetSelector:
# Postgres backup pod
postgresbackup:
# Postgres backup container
postgresbackup:
mountPath: /postgres_backup
# Postgres - Permissions container
permissions:
mountPath: /mnt/directories/postgres_backup
{{- end -}}

View File

@@ -0,0 +1,25 @@
{{- define "joplin.portal" -}}
{{ $prot := "http" }}
{{ if hasPrefix "https://" .Values.joplinConfig.baseUrl }}
{{ $prot = "https" }}
{{ end }}
{{ $host := "$node_ip" }}
{{ $port := .Values.joplinNetwork.webPort }}
{{ with .Values.joplinConfig.baseUrl }}
{{ $host = . | trimPrefix "http://" | trimPrefix "https://" | trimSuffix "/" }}
{{ if contains ":" $host }}
{{ $port = (split ":" $host)._1 }}
{{ $host = (split ":" $host)._0 }}
{{ end }}
{{ end }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: portal
data:
port: {{ $port | quote }}
path: "/"
protocol: {{ $prot }}
host: {{ $host }}
{{- 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 "joplin.service" -}}
service:
joplin:
enabled: true
primary: true
type: NodePort
targetSelector: joplin
ports:
webui:
enabled: true
primary: true
port: {{ .Values.joplinNetwork.webPort }}
nodePort: {{ .Values.joplinNetwork.webPort }}
targetSelector: joplin
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 "joplin.service" $ | fromYaml) -}}
{{- $_ := mustMergeOverwrite .Values (include "joplin.persistence" $ | fromYaml) -}}
{{- $_ := mustMergeOverwrite .Values (include "joplin.configuration" $ | fromYaml) -}}
{{- $_ := mustMergeOverwrite .Values (include "postgres.workload" $ | fromYaml) -}}
{{- $_ := mustMergeOverwrite .Values (include "joplin.workload" $ | fromYaml) -}}
{{/* Create the configmap for portal manually*/}}
{{- include "joplin.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'\d+\.\d+\.\d+-beta')
def newer_mapping(image_tags):
key = list(image_tags.keys())[0]
tags = {t.strip("-beta"): 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,47 @@
image:
repository: joplin/server
pullPolicy: IfNotPresent
tag: 2.12.1-beta
resources:
limits:
cpu: 4000m
memory: 8Gi
joplinConfig:
baseUrl: http://localhost:30063
additionalEnvs: []
joplinNetwork:
webPort: 30063
hostNetwork: false
joplinStorage:
pgData:
type: ixVolume
datasetName: pgData
pgBackup:
type: ixVolume
datasetName: pgBackup
notes:
custom: |
## Default Credentials
- Username: `admin@localhost`
- Password: `admin`
## Database
You can connect to the database using the pgAdmin App from the catalog
<details>
<summary>Database Details</summary>
- Database: `joplin`
- Username: `joplin`
- Password: `{{ .Values.joplinDbPass }}`
- Host: `{{ .Values.joplinDbHost }}.{{ .Release.Namespace }}.svc.cluster.local`
- Port: `5432`
</details>
{{- $_ := unset .Values "joplinDbPass" }}
{{- $_ := unset .Values "joplinDbHost" }}