Quellcode durchsuchen

NAS-120567 / None / Add qBittorrent Community App (#1012)

* Add qbittorrent to community train

* add item.yaml

* dummy commit

* Add update strategy and update readme(s)

* update common

* switch to differnt permission logic
Stavros Kois vor 2 Jahren
Ursprung
Commit
fccf8800ab

+ 6 - 0
library/ix-dev/community/qbittorrent/Chart.lock

@@ -0,0 +1,6 @@
+dependencies:
+- name: common
+  repository: file://../../../common
+  version: 1.0.1
+digest: sha256:ec8784f128039af68613a8268208bde360d5b178f811c4a16c79a1650ca8be92
+generated: "2023-04-03T17:54:32.688255209+03:00"

+ 26 - 0
library/ix-dev/community/qbittorrent/Chart.yaml

@@ -0,0 +1,26 @@
+name: qbittorrent
+description: The qBittorrent project aims to provide an open-source software alternative to µTorrent.
+annotations:
+  title: qBittorrent
+type: application
+version: 1.0.0
+apiVersion: v2
+appVersion: '4.5.2'
+kubeVersion: '>=1.16.0-0'
+maintainers:
+  - name: truenas
+    url: https://www.truenas.com/
+dependencies:
+- name: common
+  repository: file://../../../common
+  version: 1.0.1
+home: https://www.qbittorrent.org/
+icon: https://upload.wikimedia.org/wikipedia/commons/9/9e/Qbittorrent_logo.png
+sources:
+- https://github.com/onedr0p/containers/tree/main/apps/qbittorrent
+- https://github.com/truenas/charts/tree/master/community/qbittorrent
+- https://www.qbittorrent.org/
+keywords:
+- media
+- torrent
+- download

+ 7 - 0
library/ix-dev/community/qbittorrent/README.md

@@ -0,0 +1,7 @@
+# qBittorrent
+
+The [qBittorrent](https://www.qbittorrent.org/) project aims to provide an open-source software alternative to µTorrent.
+
+> When application is installed, a container will be launched with **root** privileges.
+> This is required in order to apply the correct permissions to the qBittorrent directories.
+> Afterward, the `qBittorrent` container will run as a **non**-root user (Default: `568`).

+ 7 - 0
library/ix-dev/community/qbittorrent/app-readme.md

@@ -0,0 +1,7 @@
+# qBittorrent
+
+The [qBittorrent](https://www.qbittorrent.org/) project aims to provide an open-source software alternative to µTorrent.
+
+> When application is installed, a container will be launched with **root** privileges.
+> This is required in order to apply the correct permissions to the qBittorrent directories.
+> Afterward, the `qBittorrent` container will run as a **non**-root user (Default: `568`).

BIN
library/ix-dev/community/qbittorrent/charts/common-1.0.1.tgz


+ 17 - 0
library/ix-dev/community/qbittorrent/ci/basic-values.yaml

@@ -0,0 +1,17 @@
+qbitNetwork:
+  webPort: 31000
+  btPort: 32444
+
+qbitRunAs:
+  user: 1000
+  group: 1000
+
+qbitStorage:
+  downloads:
+    type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/downloads
+    datasetName: ""
+  config:
+    type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/config
+    datasetName: ""

+ 20 - 0
library/ix-dev/community/qbittorrent/ci/extra-env-values.yaml

@@ -0,0 +1,20 @@
+qbitConfig:
+  additionalEnvs:
+    - name: "TESTVAR"
+      value: "SOMEVALUE"
+    - name: "TESTVAR2"
+      value: "SOMEVALUE2"
+
+qbitNetwork:
+  webPort: 31000
+  btPort: 32444
+
+qbitStorage:
+  downloads:
+    type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/downloads
+    datasetName: ""
+  config:
+    type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/config
+    datasetName: ""

+ 14 - 0
library/ix-dev/community/qbittorrent/ci/hostNet-values.yaml

@@ -0,0 +1,14 @@
+qbitNetwork:
+  webPort: 30000
+  btPort: 32555
+  hostNetwork: true
+
+qbitStorage:
+  downloads:
+    type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/downloads
+    datasetName: ""
+  config:
+    type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/config
+    datasetName: ""

+ 5 - 0
library/ix-dev/community/qbittorrent/item.yaml

@@ -0,0 +1,5 @@
+icon_url: https://upload.wikimedia.org/wikipedia/commons/9/9e/Qbittorrent_logo.png
+categories:
+  - media
+  - torrent
+  - download

+ 209 - 0
library/ix-dev/community/qbittorrent/questions.yaml

@@ -0,0 +1,209 @@
+groups:
+  - name: qBittorrent Configuration
+    description: Configure qBittorrent
+  - name: User and Group Configuration
+    description: Configure User and Group for qBittorrent
+  - name: Network Configuration
+    description: Configure Network for qBittorrent
+  - name: Storage Configuration
+    description: Configure Storage for qBittorrent
+  - name: Resources Configuration
+    description: Configure Resources for qBittorrent
+
+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: qbitConfig
+    label: ""
+    group: qBittorrent Configuration
+    schema:
+      type: dict
+      attrs:
+        - variable: additionalEnvs
+          label: Additional Environment Variables
+          description: Configure additional environment variables for qBittorrent.
+          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: qbitRunAs
+    label: ""
+    group: User and Group Configuration
+    schema:
+      type: dict
+      attrs:
+        - variable: user
+          label: User ID
+          description: The user id that qBittorrent will run as.
+          schema:
+            type: int
+            min: 1
+            default: 568
+            required: true
+        - variable: group
+          label: Group ID
+          description: The group id that qBittorrent will run as.
+          schema:
+            type: int
+            min: 1
+            default: 568
+            required: true
+
+  - variable: qbitNetwork
+    label: ""
+    group: Network Configuration
+    schema:
+      type: dict
+      attrs:
+        - variable: webPort
+          label: Web Port
+          description: The port for the qBittorrent Web UI.
+          schema:
+            type: int
+            default: 30000
+            min: 9000
+            max: 65535
+            required: true
+        - variable: btPort
+          label: BT Port
+          description: The port for the qBittorrent BitTorrent protocol. Both TCP and UDP
+          schema:
+            type: int
+            default: 50413
+            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: qbitStorage
+    label: ""
+    group: Storage Configuration
+    schema:
+      type: dict
+      attrs:
+        - variable: downloads
+          label: qBittorrent Downloads Storage
+          description: The path to store qBittorrent Downloads.
+          schema:
+            type: dict
+            attrs:
+              - variable: type
+                label: Type
+                schema:
+                  type: string
+                  required: true
+                  default: ixVolume
+                  enum:
+                    - value: hostPath
+                      description: Host Path
+                    - value: ixVolume
+                      description: ixVolume
+              - variable: datasetName
+                label: Dataset Name
+                schema:
+                  type: string
+                  show_if: [["type", "=", "ixVolume"]]
+                  required: true
+                  hidden: true
+                  immutable: true
+                  default: downloads
+                  $ref:
+                    - "normalize/ixVolume"
+              - variable: hostPath
+                label: Host Path
+                schema:
+                  type: hostpath
+                  show_if: [["type", "=", "hostPath"]]
+                  immutable: true
+                  required: true
+        - variable: config
+          label: qBittorrent Config Storage
+          description: The path to store qBittorrent Configuration.
+          schema:
+            type: dict
+            attrs:
+              - variable: type
+                label: Type
+                schema:
+                  type: string
+                  required: true
+                  default: ixVolume
+                  enum:
+                    - value: hostPath
+                      description: Host Path
+                    - value: ixVolume
+                      description: ixVolume
+              - 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: resources
+    label: Resources Configuration
+    group: Resources Configuration
+    schema:
+      type: dict
+      attrs:
+        - variable: limits
+          label: Limits
+          schema:
+            type: dict
+            attrs:
+              - variable: cpu
+                label: CPU
+                description: CPU limit for qBittorrent.
+                schema:
+                  type: string
+                  default: 4000m
+                  required: true
+              - variable: memory
+                label: Memory
+                description: Memory limit for qBittorrent.
+                schema:
+                  type: string
+                  default: 8Gi
+                  required: true

+ 1 - 0
library/ix-dev/community/qbittorrent/templates/NOTES.txt

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

+ 11 - 0
library/ix-dev/community/qbittorrent/templates/_configuration.tpl

@@ -0,0 +1,11 @@
+{{- define "qbittorrent.configuration" -}}
+
+{{/* Configmaps */}}
+configmap:
+  qbit-config:
+    enabled: true
+    data:
+      QBITTORRENT__BT_PORT: {{ .Values.qbitNetwork.btPort | quote }}
+      QBITTORRENT__PORT: {{ .Values.qbitNetwork.webPort | quote }}
+
+{{- end -}}

+ 12 - 0
library/ix-dev/community/qbittorrent/templates/_portal.tpl

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

+ 138 - 0
library/ix-dev/community/qbittorrent/templates/_qbittorrent.tpl

@@ -0,0 +1,138 @@
+{{- define "qbittorrent.workload" -}}
+workload:
+  qbittorrent:
+    enabled: true
+    primary: true
+    type: Deployment
+    podSpec:
+      hostNetwork: {{ .Values.qbitNetwork.hostNetwork }}
+      containers:
+        qbittorrent:
+          enabled: true
+          primary: true
+          imageSelector: image
+          securityContext:
+            runAsUser: {{ .Values.qbitRunAs.user }}
+            runAsGroup: {{ .Values.qbitRunAs.group }}
+          {{ with .Values.qbitConfig.additionalEnvs }}
+          env:
+            {{ range $env := . }}
+            {{ $env.name }}: {{ $env.value }}
+            {{ end }}
+          {{ end }}
+          envFrom:
+            - configMapRef:
+                name: qbit-config
+          probes:
+            liveness:
+              enabled: true
+              type: http
+              port: "{{ .Values.qbitNetwork.webPort }}"
+              path: /
+            readiness:
+              enabled: true
+              type: http
+              port: "{{ .Values.qbitNetwork.webPort }}"
+              path: /
+            startup:
+              enabled: true
+              type: http
+              port: "{{ .Values.qbitNetwork.webPort }}"
+              path: /
+      initContainers:
+        check-permissions:
+          enabled: true
+          type: init
+          imageSelector: bashImage
+          resources:
+            limits:
+              cpu: 1000m
+              memory: 512Mi
+          securityContext:
+            runAsUser: 0
+            runAsGroup: 0
+            runAsNonRoot: false
+            readOnlyRootFilesystem: false
+            capabilities:
+              add:
+                - CHOWN
+          command: bash
+          args:
+            - -c
+            - |
+              for dir in /mnt/directories/*; do
+                if [ ! -d "$dir" ]; then
+                  echo "[$dir] is not a directory, skipping"
+                  continue
+                fi
+
+                if [ $(stat -c %u "$dir") -eq {{ .Values.qbitRunAs.user }} ] && [ $(stat -c %g "$dir") -eq {{ .Values.qbitRunAs.group }} ]; then
+                  echo "Permissions on ["$dir"] are correct"
+                else
+                  echo "Permissions on ["$dir"] are incorrect"
+                  echo "Changing ownership to {{ .Values.qbitRunAs.user }}:{{ .Values.qbitRunAs.group }} on the following directories: ["$dir"]"
+                  chown -R {{ .Values.qbitRunAs.user }}:{{ .Values.qbitRunAs.group }} "$dir"
+                  echo "Finished changing ownership"
+                  echo "Permissions after changing ownership:"
+                  stat -c "%u %g" "$dir"
+                fi
+              done
+
+{{/* Service */}}
+service:
+  qbittorrent:
+    enabled: true
+    primary: true
+    type: NodePort
+    targetSelector: qbittorrent
+    ports:
+      webui:
+        enabled: true
+        primary: true
+        port: {{ .Values.qbitNetwork.webPort }}
+        nodePort: {{ .Values.qbitNetwork.webPort }}
+        targetSelector: qbittorrent
+  qbittorrent-bt:
+    enabled: true
+    type: NodePort
+    targetSelector: qbittorrent
+    ports:
+      bt-tcp:
+        enabled: true
+        primary: true
+        port: {{ .Values.qbitNetwork.btPort }}
+        nodePort: {{ .Values.qbitNetwork.btPort }}
+        targetSelector: qbittorrent
+      bt-upd:
+        enabled: true
+        primary: true
+        port: {{ .Values.qbitNetwork.btPort }}
+        nodePort: {{ .Values.qbitNetwork.btPort }}
+        protocol: udp
+        targetSelector: qbittorrent
+
+{{/* Persistence */}}
+persistence:
+  config:
+    enabled: true
+    type: {{ .Values.qbitStorage.config.type }}
+    datasetName: {{ .Values.qbitStorage.config.datasetName | default "" }}
+    hostPath: {{ .Values.qbitStorage.config.hostPath | default "" }}
+    targetSelector:
+      qbittorrent:
+        qbittorrent:
+          mountPath: /config
+        check-permissions:
+          mountPath: /mnt/directories/config
+  downloads:
+    enabled: true
+    type: {{ .Values.qbitStorage.downloads.type }}
+    datasetName: {{ .Values.qbitStorage.downloads.datasetName | default "" }}
+    hostPath: {{ .Values.qbitStorage.downloads.hostPath | default "" }}
+    targetSelector:
+      qbittorrent:
+        qbittorrent:
+          mountPath: /downloads
+        check-permissions:
+          mountPath: /mnt/directories/downloads
+{{- end -}}

+ 10 - 0
library/ix-dev/community/qbittorrent/templates/common.yaml

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

+ 31 - 0
library/ix-dev/community/qbittorrent/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)))

+ 34 - 0
library/ix-dev/community/qbittorrent/values.yaml

@@ -0,0 +1,34 @@
+image:
+  repository: ghcr.io/onedr0p/qbittorrent
+  pullPolicy: IfNotPresent
+  tag: "4.5.2"
+
+resources:
+  limits:
+    cpu: 4000m
+    memory: 8Gi
+
+qbitConfig:
+  additionalEnvs: []
+qbitNetwork:
+  webPort: 30000
+  btPort: 50413
+  hostNetwork: false
+qbitRunAs:
+  user: 568
+  group: 568
+qbitStorage:
+  downloads:
+    type: ixVolume
+    hostPath: ""
+    datasetName: downloads
+  config:
+    type: ixVolume
+    hostPath: ""
+    datasetName: config
+
+notes:
+  custom: |
+    Default credentials:
+    -  username: admin
+    -  password: adminadmin