diff --git a/library/ix-dev/test/jellyfin/Chart.lock b/library/ix-dev/test/jellyfin/Chart.lock new file mode 100644 index 0000000000..4441bbc9f5 --- /dev/null +++ b/library/ix-dev/test/jellyfin/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: common + repository: file://../../../common + version: 1.1.1 +digest: sha256:a7dbe3e4d42dbcd4325776e5e01a1d630c7f185f79e7ebf22b1b9cc80f56eed7 +generated: "2023-09-21T15:59:06.600933007+03:00" diff --git a/library/ix-dev/test/jellyfin/Chart.yaml b/library/ix-dev/test/jellyfin/Chart.yaml new file mode 100644 index 0000000000..5bb429973a --- /dev/null +++ b/library/ix-dev/test/jellyfin/Chart.yaml @@ -0,0 +1,26 @@ +name: jellyfin +description: Jellyfin is a Free Software Media System that puts you in control of managing and streaming your media. +annotations: + title: Jellyfin +type: application +version: 1.0.13 +apiVersion: v2 +appVersion: '10.8.10' +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://jellyfin.org/ +icon: https://jellyfin.org/images/logo.svg +sources: + - https://hub.docker.com/r/jellyfin/jellyfin + - https://github.com/truenas/charts/tree/master/community/jellyfin + - https://jellyfin.org/ +keywords: + - media + - streaming diff --git a/library/ix-dev/test/jellyfin/README.md b/library/ix-dev/test/jellyfin/README.md new file mode 100644 index 0000000000..e6cc2f8b26 --- /dev/null +++ b/library/ix-dev/test/jellyfin/README.md @@ -0,0 +1,8 @@ +# Jellyfin + +[Jellyfin](https://jellyfin.org/) is a Free Software Media System that puts you in control of managing and streaming your media. + +> When application is installed, a container will be launched with **root** privileges. +> This is required in order to apply the correct permissions to the `Jellyfin` directories. +> Afterward, the `Jellyfin` container will run as a **non**-root user (Default: `568`). +> All mounted storage(s) will be `chown`ed only if the parent directory does not match the configured user. diff --git a/library/ix-dev/test/jellyfin/app-readme.md b/library/ix-dev/test/jellyfin/app-readme.md new file mode 100644 index 0000000000..e6cc2f8b26 --- /dev/null +++ b/library/ix-dev/test/jellyfin/app-readme.md @@ -0,0 +1,8 @@ +# Jellyfin + +[Jellyfin](https://jellyfin.org/) is a Free Software Media System that puts you in control of managing and streaming your media. + +> When application is installed, a container will be launched with **root** privileges. +> This is required in order to apply the correct permissions to the `Jellyfin` directories. +> Afterward, the `Jellyfin` container will run as a **non**-root user (Default: `568`). +> All mounted storage(s) will be `chown`ed only if the parent directory does not match the configured user. diff --git a/library/ix-dev/test/jellyfin/charts/common-1.1.1.tgz b/library/ix-dev/test/jellyfin/charts/common-1.1.1.tgz new file mode 100644 index 0000000000..4e9d954e92 Binary files /dev/null and b/library/ix-dev/test/jellyfin/charts/common-1.1.1.tgz differ diff --git a/library/ix-dev/test/jellyfin/ci/basic-values.yaml b/library/ix-dev/test/jellyfin/ci/basic-values.yaml new file mode 100644 index 0000000000..460f2bfda1 --- /dev/null +++ b/library/ix-dev/test/jellyfin/ci/basic-values.yaml @@ -0,0 +1,24 @@ +jellyfinNetwork: + webPort: 31000 + +jellyfinRunAs: + user: 1000 + group: 1000 + +jellyfinStorage: + config: + type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/config + cache: + type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/cache + transcodes: + type: emptyDir + medium: Memory + size: 1Gi + +# Make sure installation don't fail when 0 GPU are assigned +jellyfinGPU: + nvidia.com/gpu: 0 + intel.com/gpu: 0 +# TODO: Test assigning GPUs on a GPU-enabled system diff --git a/library/ix-dev/test/jellyfin/ci/extra-values.yaml b/library/ix-dev/test/jellyfin/ci/extra-values.yaml new file mode 100644 index 0000000000..db993b9465 --- /dev/null +++ b/library/ix-dev/test/jellyfin/ci/extra-values.yaml @@ -0,0 +1,22 @@ +jellyfinNetwork: + webPort: 31000 + +jellyfinStorage: + config: + type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/config + cache: + type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/cache + transcodes: + type: emptyDir + medium: '' + size: '' + + additionalStorages: + - type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/movies + mountPath: /movies + - type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/series + mountPath: /series diff --git a/library/ix-dev/test/jellyfin/ci/hostNet-values.yaml b/library/ix-dev/test/jellyfin/ci/hostNet-values.yaml new file mode 100644 index 0000000000..d85fc2ab77 --- /dev/null +++ b/library/ix-dev/test/jellyfin/ci/hostNet-values.yaml @@ -0,0 +1,13 @@ +jellyfinNetwork: + hostNetwork: true + +jellyfinStorage: + config: + type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/config + cache: + type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/cache + transcodes: + type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/transcodes diff --git a/library/ix-dev/test/jellyfin/item.yaml b/library/ix-dev/test/jellyfin/item.yaml new file mode 100644 index 0000000000..4292f5a67e --- /dev/null +++ b/library/ix-dev/test/jellyfin/item.yaml @@ -0,0 +1,12 @@ +icon_url: https://jellyfin.org/images/logo.svg +categories: + - media +screenshots: + - https://jellyfin.org/assets/images/10.8-home-4a73a92bf90d1eeffa5081201ca9c7bb.png + - https://jellyfin.org/assets/images/10.8-details-df4f7caaee389ffbaeeaa95b668fa037.png +tags: + - entertainment + - movies + - series + - tv + - streaming diff --git a/library/ix-dev/test/jellyfin/metadata.yaml b/library/ix-dev/test/jellyfin/metadata.yaml new file mode 100644 index 0000000000..d806ba85f0 --- /dev/null +++ b/library/ix-dev/test/jellyfin/metadata.yaml @@ -0,0 +1,8 @@ +runAsContext: + - userName: jellyfin + groupName: jellyfin + gid: 568 + uid: 568 + description: Jellyfin runs as any non-root user. +capabilities: [] +hostMounts: [] diff --git a/library/ix-dev/test/jellyfin/migrations/migrate b/library/ix-dev/test/jellyfin/migrations/migrate new file mode 100755 index 0000000000..8f7e3dc857 --- /dev/null +++ b/library/ix-dev/test/jellyfin/migrations/migrate @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +import json +import os +import sys + + +def migrate(values): + storageKey = 'jellyfinStorage' + storages = ['config', 'cache', 'transcodes'] + + + for storage in storages: + check_val = values.get(storageKey, {}).get(storage, {}) + if not isinstance(check_val, dict) or not check_val or check_val.get('type', 'hostPath') == 'hostPath': + continue + + values[storageKey][storage] = {key: value for key, value in check_val.items() if key != 'hostPath'} + + return values + + +if __name__ == '__main__': + if len(sys.argv) != 2: + exit(1) + + if os.path.exists(sys.argv[1]): + with open(sys.argv[1], 'r') as f: + print(json.dumps(migrate(json.loads(f.read())))) diff --git a/library/ix-dev/test/jellyfin/questions.yaml b/library/ix-dev/test/jellyfin/questions.yaml new file mode 100644 index 0000000000..794c9479ff --- /dev/null +++ b/library/ix-dev/test/jellyfin/questions.yaml @@ -0,0 +1,398 @@ +groups: + - name: Jellyfin Configuration + description: Configure Jellyfin + - name: User and Group Configuration + description: Configure User and Group for Jellyfin + - name: Network Configuration + description: Configure Network for Jellyfin + - name: Storage Configuration + description: Configure Storage for Jellyfin + - name: Resources Configuration + description: Configure Resources for Jellyfin + +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: jellyfinConfig + label: "" + group: Jellyfin Configuration + schema: + type: dict + attrs: + - variable: publishServerUrl + label: Published Server URL + description: Optional - The URL that Jellyfin will be advertised. + schema: + type: string + default: "" + - variable: additionalEnvs + label: Additional Environment Variables + description: Configure additional environment variables for Jellyfin. + 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: jellyfinRunAs + label: "" + group: User and Group Configuration + schema: + type: dict + attrs: + - variable: user + label: User ID + description: The user id that Jellyfin will run as. + schema: + type: int + min: 2 + default: 568 + required: true + - variable: group + label: Group ID + description: The group id that Jellyfin will run as. + schema: + type: int + min: 2 + default: 568 + required: true + + - variable: jellyfinNetwork + label: "" + group: Network Configuration + schema: + type: dict + attrs: + - variable: hostNetwork + label: Host Network + description: | + Bind to the host network. While it's recommended to keep this disabled.
+ It's required for autodiscovery to work. + schema: + type: boolean + default: false + - variable: webPort + label: Web Port + description: The port for the Jellyfin Web UI. + schema: + type: int + default: 30013 + show_if: [["hostNetwork", "=", false]] + min: 9000 + max: 65535 + required: true + + - variable: jellyfinStorage + label: "" + group: Storage Configuration + schema: + type: dict + attrs: + - variable: config + label: Jellyfin Config Storage + description: The path to store Jellyfin Configuration. + schema: + type: dict + attrs: + - variable: type + label: Type + description: | + ixVolume: Is dataset created automatically by the system.
+ 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: "config" + $ref: + - "normalize/ixVolume" + - variable: hostPath + label: Host Path + schema: + type: hostpath + show_if: [["type", "=", "hostPath"]] + immutable: true + required: true + - variable: cache + label: Jellyfin Cache Storage + description: The path to store Jellyfin Cache. + schema: + type: dict + attrs: + - variable: type + label: Type + description: | + ixVolume: Is dataset created automatically by the system.
+ 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: "cache" + $ref: + - "normalize/ixVolume" + - variable: hostPath + label: Host Path + schema: + type: hostpath + show_if: [["type", "=", "hostPath"]] + immutable: true + required: true + - variable: transcodes + label: Jellyfin Transcodes Storage + description: The path to store Jellyfin Transcodes. + schema: + type: dict + attrs: + - variable: type + label: Type + description: | + ixVolume: Is dataset created automatically by the system.
+ Host Path: Is a path that already exists on the system.
+ emptyDir: Is a temporary directory that will be created on the disk or in memory. + 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) + - value: "emptyDir" + description: emptyDir (Temporary directory created on the disk or in memory) + - variable: datasetName + label: Dataset Name + schema: + type: string + show_if: [["type", "=", "ixVolume"]] + required: true + hidden: true + immutable: true + default: "transcodes" + $ref: + - "normalize/ixVolume" + - variable: hostPath + label: Host Path + schema: + type: hostpath + show_if: [["type", "=", "hostPath"]] + immutable: true + required: true + - variable: medium + label: emptyDir Medium + description: | + Disk: Creates a temporary directory on the disk.
+ Memory: Creates a temporary directory in memory. + schema: + type: string + show_if: [["type", "=", "emptyDir"]] + default: "" + enum: + - value: "" + description: Disk (Temporary directory created on the disk) + - value: "Memory" + description: Memory (Temporary directory created in memory) + - variable: size + label: emptyDir Size Limit + description: | + The maximum size of the temporary directory.
+ For example: 2Gi + schema: + type: string + show_if: [["type", "=", "emptyDir"]] + default: "2Gi" + + - variable: additionalStorages + label: Additional Storage + description: Additional storage for Jellyfin. + 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.
+ 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) + - value: "smb-pv-pvc" + description: SMB Share (Mounts a persistent volume claim to a SMB share) + - 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: server + label: Server + description: The server for the SMB share. + schema: + type: string + show_if: [["type", "=", "smb-pv-pvc"]] + required: true + - variable: share + label: Share + description: The share name for the SMB share. + schema: + type: string + show_if: [["type", "=", "smb-pv-pvc"]] + required: true + - variable: domain + label: Domain (Optional) + description: The domain for the SMB share. + schema: + type: string + show_if: [["type", "=", "smb-pv-pvc"]] + - variable: username + label: Username + description: The username for the SMB share. + schema: + type: string + show_if: [["type", "=", "smb-pv-pvc"]] + required: true + - variable: password + label: Password + description: The password for the SMB share. + schema: + type: string + show_if: [["type", "=", "smb-pv-pvc"]] + required: true + private: true + - variable: size + label: Size (in Gi) + description: The size of the volume quota. + schema: + type: int + show_if: [["type", "=", "smb-pv-pvc"]] + required: true + min: 1 + default: 1 + - 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 Jellyfin. + 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
+ - Plain Integer - eg. 1
+ - Float - eg. 0.5
+ - Milicpu - eg. 500m + default: "4000m" + required: true + - variable: memory + label: Memory + description: Memory limit for Jellyfin. + 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
+ - Suffixed with E/P/T/G/M/K - eg. 1G
+ - Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi
+ - Plain Integer in bytes - eg. 1024
+ - Exponent - eg. 134e6 + default: "8Gi" + required: true + + - variable: jellyfinGPU + group: Resources Configuration + label: GPU Configuration + schema: + type: dict + $ref: + - "definitions/gpuConfiguration" + attrs: [] diff --git a/library/ix-dev/test/jellyfin/templates/NOTES.txt b/library/ix-dev/test/jellyfin/templates/NOTES.txt new file mode 100644 index 0000000000..ba4e01146c --- /dev/null +++ b/library/ix-dev/test/jellyfin/templates/NOTES.txt @@ -0,0 +1 @@ +{{ include "ix.v1.common.lib.chart.notes" $ }} diff --git a/library/ix-dev/test/jellyfin/templates/_jellyfin.tpl b/library/ix-dev/test/jellyfin/templates/_jellyfin.tpl new file mode 100644 index 0000000000..5e5a374c34 --- /dev/null +++ b/library/ix-dev/test/jellyfin/templates/_jellyfin.tpl @@ -0,0 +1,151 @@ +{{- define "jellyfin.workload" -}} +workload: + jellyfin: + enabled: true + primary: true + type: Deployment + podSpec: + hostNetwork: {{ .Values.jellyfinNetwork.hostNetwork }} + containers: + jellyfin: + enabled: true + primary: true + imageSelector: image + securityContext: + runAsUser: {{ .Values.jellyfinRunAs.user }} + runAsGroup: {{ .Values.jellyfinRunAs.group }} + env: + {{ with .Values.jellyfinConfig.publishedServerUrl }} + JELLYFIN_PublishedServerUrl: {{ . | quote }} + {{ end }} + {{ with .Values.jellyfinConfig.additionalEnvs }} + envList: + {{ range $env := . }} + - name: {{ $env.name }} + values: {{ $env.value }} + {{ end }} + {{ end }} + probes: + liveness: + enabled: true + type: http + port: 8096 + path: /health + readiness: + enabled: true + type: http + port: 8096 + path: /health + startup: + enabled: true + type: http + port: 8096 + path: /health + initContainers: + {{- include "ix.v1.common.app.permissions" (dict "containerName" "01-permissions" + "UID" .Values.jellyfinRunAs.user + "GID" .Values.jellyfinRunAs.group + "mode" "check" + "type" "init") | nindent 8 }} + +{{/* Service */}} +service: + jellyfin: + enabled: true + primary: true + type: NodePort + targetSelector: jellyfin + ports: + webui: + enabled: true + primary: true + port: {{ .Values.jellyfinNetwork.webPort }} + nodePort: {{ .Values.jellyfinNetwork.webPort }} + targetPort: 8096 + targetSelector: jellyfin + +{{/* Persistence */}} +persistence: + config: + enabled: true + type: {{ .Values.jellyfinStorage.config.type }} + datasetName: {{ .Values.jellyfinStorage.config.datasetName | default "" }} + hostPath: {{ .Values.jellyfinStorage.config.hostPath | default "" }} + targetSelector: + jellyfin: + jellyfin: + mountPath: /config + 01-permissions: + mountPath: /mnt/directories/config + cache: + enabled: true + type: {{ .Values.jellyfinStorage.cache.type }} + datasetName: {{ .Values.jellyfinStorage.cache.datasetName | default "" }} + hostPath: {{ .Values.jellyfinStorage.cache.hostPath | default "" }} + targetSelector: + jellyfin: + jellyfin: + mountPath: /cache + 01-permissions: + mountPath: /mnt/directories/cache + transcode: + enabled: true + type: {{ .Values.jellyfinStorage.transcodes.type }} + datasetName: {{ .Values.jellyfinStorage.transcodes.datasetName | default "" }} + hostPath: {{ .Values.jellyfinStorage.transcodes.hostPath | default "" }} + medium: {{ .Values.jellyfinStorage.transcodes.medium | default "" }} + {{/* Size of the emptyDir */}} + size: {{ .Values.jellyfinStorage.transcodes.size | default "" }} + targetSelector: + jellyfin: + jellyfin: + mountPath: /config/transcodes + {{ if ne .Values.jellyfinStorage.transcodes.type "emptyDir" }} + 01-permissions: + mountPath: /mnt/directories/transcodes + {{ end }} + tmp: + enabled: true + type: emptyDir + targetSelector: + jellyfin: + jellyfin: + mountPath: /tmp + {{- range $idx, $storage := .Values.jellyfinStorage.additionalStorages }} + {{ printf "jellyfin-%v" (int $idx) }}: + {{- $size := "" -}} + {{- if $storage.size -}} + {{- $size = (printf "%vGi" $storage.size) -}} + {{- end }} + enabled: true + type: {{ $storage.type }} + datasetName: {{ $storage.datasetName | default "" }} + hostPath: {{ $storage.hostPath | default "" }} + server: {{ $storage.server | default "" }} + share: {{ $storage.share | default "" }} + domain: {{ $storage.domain | default "" }} + username: {{ $storage.username | default "" }} + password: {{ $storage.password | default "" }} + size: {{ $size }} + {{- if eq $storage.type "smb-pv-pvc" }} + mountOptions: + - key: noperm + {{- end }} + targetSelector: + jellyfin: + jellyfin: + mountPath: {{ $storage.mountPath }} + 01-permissions: + mountPath: /mnt/directories{{ $storage.mountPath }} + {{- end }} +{{ with .Values.jellyfinGPU }} +scaleGPU: + {{ range $key, $value := . }} + - gpu: + {{ $key }}: {{ $value }} + targetSelector: + jellyfin: + - jellyfin + {{ end }} +{{ end }} +{{- end -}} diff --git a/library/ix-dev/test/jellyfin/templates/_portal.tpl b/library/ix-dev/test/jellyfin/templates/_portal.tpl new file mode 100644 index 0000000000..c985b5aa83 --- /dev/null +++ b/library/ix-dev/test/jellyfin/templates/_portal.tpl @@ -0,0 +1,16 @@ +{{- define "jellyfin.portal" -}} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: portal +data: + path: "/" + {{- $port := .Values.jellyfinNetwork.webPort -}} + {{- if .Values.jellyfinNetwork.hostNetwork -}} + {{- $port = 8096 -}} + {{- end }} + port: {{ $port | quote }} + protocol: http + host: $node_ip +{{- end -}} diff --git a/library/ix-dev/test/jellyfin/templates/common.yaml b/library/ix-dev/test/jellyfin/templates/common.yaml new file mode 100644 index 0000000000..ee3c3a7796 --- /dev/null +++ b/library/ix-dev/test/jellyfin/templates/common.yaml @@ -0,0 +1,9 @@ +{{- include "ix.v1.common.loader.init" . -}} + +{{/* Merge the templates with Values */}} +{{- $_ := mustMergeOverwrite .Values (include "jellyfin.workload" $ | fromYaml) -}} + +{{/* Create the configmap for portal manually*/}} +{{- include "jellyfin.portal" $ -}} + +{{- include "ix.v1.common.loader.apply" . -}} diff --git a/library/ix-dev/test/jellyfin/upgrade_info.json b/library/ix-dev/test/jellyfin/upgrade_info.json new file mode 100644 index 0000000000..767388094a --- /dev/null +++ b/library/ix-dev/test/jellyfin/upgrade_info.json @@ -0,0 +1 @@ +{"filename": "values.yaml", "keys": ["image"]} diff --git a/library/ix-dev/test/jellyfin/upgrade_strategy b/library/ix-dev/test/jellyfin/upgrade_strategy new file mode 100755 index 0000000000..41e9448b21 --- /dev/null +++ b/library/ix-dev/test/jellyfin/upgrade_strategy @@ -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'[0-9]+\.[0-9]+\.[0-9]+') + + +def newer_mapping(image_tags): + key = list(image_tags.keys())[0] + tags = {t: 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))) diff --git a/library/ix-dev/test/jellyfin/values.yaml b/library/ix-dev/test/jellyfin/values.yaml new file mode 100644 index 0000000000..14e3a28f89 --- /dev/null +++ b/library/ix-dev/test/jellyfin/values.yaml @@ -0,0 +1,33 @@ +image: + repository: jellyfin/jellyfin + pullPolicy: IfNotPresent + tag: '10.8.10' + +resources: + limits: + cpu: 4000m + memory: 8Gi + +jellyfinConfig: + publishedServerUrl: '' + additionalEnvs: [] +jellyfinGPU: {} +jellyfinNetwork: + webPort: 30013 + hostNetwork: false +jellyfinRunAs: + user: 568 + group: 568 +jellyfinStorage: + config: + type: ixVolume + datasetName: config + cache: + type: ixVolume + datasetName: cache + transcodes: + type: ixVolume + datasetName: transcodes + medium: '' + size: '' + additionalStorages: [] diff --git a/library/ix-dev/test/sonarr/Chart.lock b/library/ix-dev/test/sonarr/Chart.lock new file mode 100644 index 0000000000..7178e9efbf --- /dev/null +++ b/library/ix-dev/test/sonarr/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: common + repository: file://../../../common + version: 1.1.1 +digest: sha256:a7dbe3e4d42dbcd4325776e5e01a1d630c7f185f79e7ebf22b1b9cc80f56eed7 +generated: "2023-09-21T15:59:14.078456648+03:00" diff --git a/library/ix-dev/test/sonarr/Chart.yaml b/library/ix-dev/test/sonarr/Chart.yaml new file mode 100644 index 0000000000..9a7d68f970 --- /dev/null +++ b/library/ix-dev/test/sonarr/Chart.yaml @@ -0,0 +1,26 @@ +name: sonarr +description: Sonarr is a PVR for Usenet and BitTorrent users. +annotations: + title: Sonarr +type: application +version: 1.0.16 +apiVersion: v2 +appVersion: '3.0.10.1567' +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://github.com/Sonarr/Sonarr +icon: https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png +sources: + - https://github.com/onedr0p/containers/tree/main/apps/sonarr + - https://github.com/truenas/charts/tree/master/community/sonarr + - https://github.com/Sonarr/Sonarr +keywords: + - media + - series diff --git a/library/ix-dev/test/sonarr/README.md b/library/ix-dev/test/sonarr/README.md new file mode 100644 index 0000000000..f345ff022a --- /dev/null +++ b/library/ix-dev/test/sonarr/README.md @@ -0,0 +1,8 @@ +# Sonarr + +[Sonarr](https://github.com/Sonarr/Sonarr) is a PVR for Usenet and BitTorrent users. It can monitor multiple RSS feeds for new episodes of your favorite shows and will grab, sort and rename them. + +> When application is installed, a container will be launched with **root** privileges. +> This is required in order to apply the correct permissions to the `Sonarr` directories. +> Afterward, the `Sonarr` container will run as a **non**-root user (Default: `568`). +> All mounted storage(s) will be `chown`ed only if the parent directory does not match the configured user. diff --git a/library/ix-dev/test/sonarr/app-readme.md b/library/ix-dev/test/sonarr/app-readme.md new file mode 100644 index 0000000000..f345ff022a --- /dev/null +++ b/library/ix-dev/test/sonarr/app-readme.md @@ -0,0 +1,8 @@ +# Sonarr + +[Sonarr](https://github.com/Sonarr/Sonarr) is a PVR for Usenet and BitTorrent users. It can monitor multiple RSS feeds for new episodes of your favorite shows and will grab, sort and rename them. + +> When application is installed, a container will be launched with **root** privileges. +> This is required in order to apply the correct permissions to the `Sonarr` directories. +> Afterward, the `Sonarr` container will run as a **non**-root user (Default: `568`). +> All mounted storage(s) will be `chown`ed only if the parent directory does not match the configured user. diff --git a/library/ix-dev/test/sonarr/charts/common-1.1.1.tgz b/library/ix-dev/test/sonarr/charts/common-1.1.1.tgz new file mode 100644 index 0000000000..8a94b95393 Binary files /dev/null and b/library/ix-dev/test/sonarr/charts/common-1.1.1.tgz differ diff --git a/library/ix-dev/test/sonarr/ci/basic-values.yaml b/library/ix-dev/test/sonarr/ci/basic-values.yaml new file mode 100644 index 0000000000..886fe58f92 --- /dev/null +++ b/library/ix-dev/test/sonarr/ci/basic-values.yaml @@ -0,0 +1,11 @@ +sonarrNetwork: + webPort: 31000 + +sonarrRunAs: + user: 1000 + group: 1000 + +sonarrStorage: + config: + type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/config diff --git a/library/ix-dev/test/sonarr/ci/extra-values.yaml b/library/ix-dev/test/sonarr/ci/extra-values.yaml new file mode 100644 index 0000000000..2d1d330236 --- /dev/null +++ b/library/ix-dev/test/sonarr/ci/extra-values.yaml @@ -0,0 +1,21 @@ +sonarrConfig: + additionalEnvs: + - name: SONARR__API_KEY + value: some-long-api-key + - name: SONARR__LOG_LEVEL + value: error + +sonarrNetwork: + webPort: 31000 + +sonarrStorage: + config: + type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/config + additionalStorages: + - type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/action_series + mountPath: /action_series + - type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/adventure_series + mountPath: /adventure_series diff --git a/library/ix-dev/test/sonarr/ci/hostNet-values.yaml b/library/ix-dev/test/sonarr/ci/hostNet-values.yaml new file mode 100644 index 0000000000..a23e799a30 --- /dev/null +++ b/library/ix-dev/test/sonarr/ci/hostNet-values.yaml @@ -0,0 +1,8 @@ +sonarrNetwork: + webPort: 30000 + hostNetwork: true + +sonarrStorage: + config: + type: hostPath + hostPath: /mnt/{{ .Release.Namespace }}/config diff --git a/library/ix-dev/test/sonarr/item.yaml b/library/ix-dev/test/sonarr/item.yaml new file mode 100644 index 0000000000..8e971a26f9 --- /dev/null +++ b/library/ix-dev/test/sonarr/item.yaml @@ -0,0 +1,9 @@ +icon_url: https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png +categories: + - media +screenshots: + - https://sonarr.tv/img/features/calendar.png + - https://sonarr.tv/img/features/manualsearch.png + - https://sonarr.tv/img/features/blocklist.png +tags: + - series diff --git a/library/ix-dev/test/sonarr/metadata.yaml b/library/ix-dev/test/sonarr/metadata.yaml new file mode 100644 index 0000000000..c70b059638 --- /dev/null +++ b/library/ix-dev/test/sonarr/metadata.yaml @@ -0,0 +1,8 @@ +runAsContext: + - userName: sonarr + groupName: sonarr + gid: 568 + uid: 568 + description: Sonarr can run as any non-root user. +capabilities: [] +hostMounts: [] diff --git a/library/ix-dev/test/sonarr/migrations/migrate b/library/ix-dev/test/sonarr/migrations/migrate new file mode 100755 index 0000000000..3176f197c3 --- /dev/null +++ b/library/ix-dev/test/sonarr/migrations/migrate @@ -0,0 +1,29 @@ +#!/usr/bin/python3 +import json +import os +import sys + + +def migrate(values): + storageKey = 'sonarrStorage' + storages = ['config'] + + + for storage in storages: + check_val = values.get(storageKey, {}).get(storage, {}) + if not isinstance(check_val, dict) or not check_val or check_val.get('type', 'hostPath') == 'hostPath': + continue + + values[storageKey][storage] = {key: value for key, value in check_val.items() if key != 'hostPath'} + + + return values + + +if __name__ == '__main__': + if len(sys.argv) != 2: + exit(1) + + if os.path.exists(sys.argv[1]): + with open(sys.argv[1], 'r') as f: + print(json.dumps(migrate(json.loads(f.read())))) diff --git a/library/ix-dev/test/sonarr/questions.yaml b/library/ix-dev/test/sonarr/questions.yaml new file mode 100644 index 0000000000..e158867171 --- /dev/null +++ b/library/ix-dev/test/sonarr/questions.yaml @@ -0,0 +1,286 @@ +groups: + - name: Sonarr Configuration + description: Configure Sonarr + - name: User and Group Configuration + description: Configure User and Group for Sonarr + - name: Network Configuration + description: Configure Network for Sonarr + - name: Storage Configuration + description: Configure Storage for Sonarr + - name: Resources Configuration + description: Configure Resources for Sonarr + +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: sonarrConfig + label: "" + group: Sonarr Configuration + schema: + type: dict + attrs: + - variable: instanceName + label: Instance Name + description: The name of the Sonarr instance. + schema: + type: string + default: "Sonarr" + required: true + - variable: additionalEnvs + label: Additional Environment Variables + description: Configure additional environment variables for Sonarr. + 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: sonarrRunAs + label: "" + group: User and Group Configuration + schema: + type: dict + attrs: + - variable: user + label: User ID + description: The user id that Sonarr will run as. + schema: + type: int + min: 2 + default: 568 + required: true + - variable: group + label: Group ID + description: The group id that Sonarr will run as. + schema: + type: int + min: 2 + default: 568 + required: true + + - variable: sonarrNetwork + label: "" + group: Network Configuration + schema: + type: dict + attrs: + - variable: webPort + label: Web Port + description: The port for the Sonarr Web UI. + schema: + type: int + default: 30027 + min: 9000 + max: 65535 + required: true + - variable: hostNetwork + label: Host Network + description: | + Bind to the host network. It's recommended to keep this disabled.
+ schema: + type: boolean + default: false + + - variable: sonarrStorage + label: "" + group: Storage Configuration + schema: + type: dict + attrs: + - variable: config + label: Sonarr Config Storage + description: The path to store Sonarr Configuration. + schema: + type: dict + attrs: + - variable: type + label: Type + description: | + ixVolume: Is dataset created automatically by the system.
+ 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: "config" + $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 Sonarr. + 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.
+ 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) + - value: "smb-pv-pvc" + description: SMB Share (Mounts a persistent volume claim to a SMB share) + - 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: server + label: Server + description: The server for the SMB share. + schema: + type: string + show_if: [["type", "=", "smb-pv-pvc"]] + required: true + - variable: share + label: Share + description: The share name for the SMB share. + schema: + type: string + show_if: [["type", "=", "smb-pv-pvc"]] + required: true + - variable: domain + label: Domain (Optional) + description: The domain for the SMB share. + schema: + type: string + show_if: [["type", "=", "smb-pv-pvc"]] + - variable: username + label: Username + description: The username for the SMB share. + schema: + type: string + show_if: [["type", "=", "smb-pv-pvc"]] + required: true + - variable: password + label: Password + description: The password for the SMB share. + schema: + type: string + show_if: [["type", "=", "smb-pv-pvc"]] + required: true + private: true + - variable: size + label: Size (in Gi) + description: The size of the volume quota. + schema: + type: int + show_if: [["type", "=", "smb-pv-pvc"]] + required: true + min: 1 + default: 1 + + - 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 Sonarr. + 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
+ - Plain Integer - eg. 1
+ - Float - eg. 0.5
+ - Milicpu - eg. 500m + default: "4000m" + required: true + - variable: memory + label: Memory + description: Memory limit for Sonarr. + 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
+ - Suffixed with E/P/T/G/M/K - eg. 1G
+ - Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi
+ - Plain Integer in bytes - eg. 1024
+ - Exponent - eg. 134e6 + default: "8Gi" + required: true diff --git a/library/ix-dev/test/sonarr/templates/NOTES.txt b/library/ix-dev/test/sonarr/templates/NOTES.txt new file mode 100644 index 0000000000..ba4e01146c --- /dev/null +++ b/library/ix-dev/test/sonarr/templates/NOTES.txt @@ -0,0 +1 @@ +{{ include "ix.v1.common.lib.chart.notes" $ }} diff --git a/library/ix-dev/test/sonarr/templates/_portal.tpl b/library/ix-dev/test/sonarr/templates/_portal.tpl new file mode 100644 index 0000000000..88e40c57bc --- /dev/null +++ b/library/ix-dev/test/sonarr/templates/_portal.tpl @@ -0,0 +1,12 @@ +{{- define "sonarr.portal" -}} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: portal +data: + path: "/" + port: {{ .Values.sonarrNetwork.webPort | quote }} + protocol: http + host: $node_ip +{{- end -}} diff --git a/library/ix-dev/test/sonarr/templates/_sonarr.tpl b/library/ix-dev/test/sonarr/templates/_sonarr.tpl new file mode 100644 index 0000000000..3c2b23b868 --- /dev/null +++ b/library/ix-dev/test/sonarr/templates/_sonarr.tpl @@ -0,0 +1,112 @@ +{{- define "sonarr.workload" -}} +workload: + sonarr: + enabled: true + primary: true + type: Deployment + podSpec: + hostNetwork: {{ .Values.sonarrNetwork.hostNetwork }} + containers: + sonarr: + enabled: true + primary: true + imageSelector: image + securityContext: + runAsUser: {{ .Values.sonarrRunAs.user }} + runAsGroup: {{ .Values.sonarrRunAs.group }} + env: + SONARR__PORT: {{ .Values.sonarrNetwork.webPort }} + SONARR__INSTANCE_NAME: {{ .Values.sonarrConfig.instanceName }} + {{ with .Values.sonarrConfig.additionalEnvs }} + envList: + {{ range $env := . }} + - name: {{ $env.name }} + value: {{ $env.value }} + {{ end }} + {{ end }} + probes: + liveness: + enabled: true + type: http + port: "{{ .Values.sonarrNetwork.webPort }}" + path: /ping + readiness: + enabled: true + type: http + port: "{{ .Values.sonarrNetwork.webPort }}" + path: /ping + startup: + enabled: true + type: http + port: "{{ .Values.sonarrNetwork.webPort }}" + path: /ping + initContainers: + {{- include "ix.v1.common.app.permissions" (dict "containerName" "01-permissions" + "UID" .Values.sonarrRunAs.user + "GID" .Values.sonarrRunAs.group + "mode" "check" + "type" "init") | nindent 8 }} + +{{/* Service */}} +service: + sonarr: + enabled: true + primary: true + type: NodePort + targetSelector: sonarr + ports: + webui: + enabled: true + primary: true + port: {{ .Values.sonarrNetwork.webPort }} + nodePort: {{ .Values.sonarrNetwork.webPort }} + targetSelector: sonarr + +{{/* Persistence */}} +persistence: + config: + enabled: true + type: {{ .Values.sonarrStorage.config.type }} + datasetName: {{ .Values.sonarrStorage.config.datasetName | default "" }} + hostPath: {{ .Values.sonarrStorage.config.hostPath | default "" }} + targetSelector: + sonarr: + sonarr: + mountPath: /config + 01-permissions: + mountPath: /mnt/directories/config + tmp: + enabled: true + type: emptyDir + targetSelector: + sonarr: + sonarr: + mountPath: /tmp + {{- range $idx, $storage := .Values.sonarrStorage.additionalStorages }} + {{ printf "sonarr-%v" (int $idx) }}: + {{- $size := "" -}} + {{- if $storage.size -}} + {{- $size = (printf "%vGi" $storage.size) -}} + {{- end }} + enabled: true + type: {{ $storage.type }} + datasetName: {{ $storage.datasetName | default "" }} + hostPath: {{ $storage.hostPath | default "" }} + server: {{ $storage.server | default "" }} + share: {{ $storage.share | default "" }} + domain: {{ $storage.domain | default "" }} + username: {{ $storage.username | default "" }} + password: {{ $storage.password | default "" }} + size: {{ $size }} + {{- if eq $storage.type "smb-pv-pvc" }} + mountOptions: + - key: noperm + {{- end }} + targetSelector: + sonarr: + sonarr: + mountPath: {{ $storage.mountPath }} + 01-permissions: + mountPath: /mnt/directories{{ $storage.mountPath }} + {{- end }} +{{- end -}} diff --git a/library/ix-dev/test/sonarr/templates/common.yaml b/library/ix-dev/test/sonarr/templates/common.yaml new file mode 100644 index 0000000000..23242cb8d3 --- /dev/null +++ b/library/ix-dev/test/sonarr/templates/common.yaml @@ -0,0 +1,9 @@ +{{- include "ix.v1.common.loader.init" . -}} + +{{/* Merge the templates with Values */}} +{{- $_ := mustMergeOverwrite .Values (include "sonarr.workload" $ | fromYaml) -}} + +{{/* Create the configmap for portal manually*/}} +{{- include "sonarr.portal" $ -}} + +{{- include "ix.v1.common.loader.apply" . -}} diff --git a/library/ix-dev/test/sonarr/upgrade_info.json b/library/ix-dev/test/sonarr/upgrade_info.json new file mode 100644 index 0000000000..767388094a --- /dev/null +++ b/library/ix-dev/test/sonarr/upgrade_info.json @@ -0,0 +1 @@ +{"filename": "values.yaml", "keys": ["image"]} diff --git a/library/ix-dev/test/sonarr/upgrade_strategy b/library/ix-dev/test/sonarr/upgrade_strategy new file mode 100755 index 0000000000..3e49862388 --- /dev/null +++ b/library/ix-dev/test/sonarr/upgrade_strategy @@ -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'[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+') + + +def newer_mapping(image_tags): + key = list(image_tags.keys())[0] + tags = {t: 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))) diff --git a/library/ix-dev/test/sonarr/values.yaml b/library/ix-dev/test/sonarr/values.yaml new file mode 100644 index 0000000000..c14da6f89b --- /dev/null +++ b/library/ix-dev/test/sonarr/values.yaml @@ -0,0 +1,24 @@ +image: + repository: ghcr.io/onedr0p/sonarr + pullPolicy: IfNotPresent + tag: '3.0.10.1567' + +resources: + limits: + cpu: 4000m + memory: 8Gi + +sonarrConfig: + instanceName: Sonarr + additionalEnvs: [] +sonarrNetwork: + webPort: 30027 + hostNetwork: false +sonarrRunAs: + user: 568 + group: 568 +sonarrStorage: + config: + type: ixVolume + datasetName: config + additionalStorages: []