Pārlūkot izejas kodu

NAS-122990 / 23.10 / Add `searxng` to `community` train (#1362)

* Add `searxng` to `community` train

* add tempaltes

* add UI and metadata

* update readme

* remove non-existent option

* bump
Stavros Kois 2 gadi atpakaļ
vecāks
revīzija
0ef9035e82

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

@@ -0,0 +1,6 @@
+dependencies:
+- name: common
+  repository: file://../../../common
+  version: 1.0.12
+digest: sha256:debd30721d09ae8293b1cbdd9d0115981d40b47908be3035fc3cf657c9d5eedb
+generated: "2023-07-15T23:16:41.80942906+03:00"

+ 25 - 0
library/ix-dev/community/searxng/Chart.yaml

@@ -0,0 +1,25 @@
+name: searxng
+description: SearXNG is a privacy-respecting, hackable metasearch engine
+annotations:
+  title: SearXNG
+type: application
+version: 1.0.0
+apiVersion: v2
+appVersion: 2023.7.7
+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.0.12
+home: https://github.com/searxng/searxng
+icon: https://raw.githubusercontent.com/searxng/searxng/master/src/brand/searxng.svg
+sources:
+  - https://hub.docker.com/r/searxng/searxng
+  - https://github.com/truenas/charts/tree/master/library/ix-dev/community/searxng
+  - https://github.com/searxng/searxng
+keywords:
+  - search

+ 3 - 0
library/ix-dev/community/searxng/README.md

@@ -0,0 +1,3 @@
+# SearXNG
+
+[SearXNG](https://github.com/searxng/searxng) is a privacy-respecting, hackable metasearch engine

+ 3 - 0
library/ix-dev/community/searxng/app-readme.md

@@ -0,0 +1,3 @@
+# SearXNG
+
+[SearXNG](https://github.com/searxng/searxng) is a privacy-respecting, hackable metasearch engine

BIN
library/ix-dev/community/searxng/charts/common-1.0.12.tgz


+ 10 - 0
library/ix-dev/community/searxng/ci/basic-values.yaml

@@ -0,0 +1,10 @@
+searxngConfig:
+  instanceName: SearXNG-Test
+
+searxngNetwork:
+  webPort: 31000
+
+searxngStorage:
+  config:
+    type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/config

+ 14 - 0
library/ix-dev/community/searxng/ci/extra-values.yaml

@@ -0,0 +1,14 @@
+searxngNetwork:
+  webPort: 31000
+
+searxngStorage:
+  config:
+    type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/config
+  additionalStorages:
+  - type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/data1
+    mountPath: /data1
+  - type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/data2
+    mountPath: /data2

+ 8 - 0
library/ix-dev/community/searxng/ci/hostNet-values.yaml

@@ -0,0 +1,8 @@
+searxngNetwork:
+  webPort: 30000
+  hostNetwork: true
+
+searxngStorage:
+  config:
+    type: hostPath
+    hostPath: /mnt/{{ .Release.Namespace }}/config

+ 6 - 0
library/ix-dev/community/searxng/item.yaml

@@ -0,0 +1,6 @@
+icon_url: https://raw.githubusercontent.com/searxng/searxng/master/src/brand/searxng.svg
+categories:
+  - productivity
+screenshots: []
+tags:
+  - search

+ 12 - 0
library/ix-dev/community/searxng/metadata.yaml

@@ -0,0 +1,12 @@
+runAsContext:
+  - userName: searxng
+    groupName: searxng
+    gid: 0
+    uid: 0
+    description: SearXNG requires root privileges to start it's sub-processes.
+capabilities:
+  - name: SETUID
+    description: SearXNG requires this ability to switch user for sub-processes.
+  - name: SETGID
+    description: SearXNG requires this ability to switch group for sub-processes.
+hostMounts: []

+ 215 - 0
library/ix-dev/community/searxng/questions.yaml

@@ -0,0 +1,215 @@
+groups:
+  - name: SearXNG Configuration
+    description: Configure SearXNG
+  - name: Network Configuration
+    description: Configure Network for SearXNG
+  - name: Storage Configuration
+    description: Configure Storage for SearXNG
+  - name: Resources Configuration
+    description: Configure Resources for SearXNG
+
+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: searxngConfig
+    label: ""
+    group: SearXNG Configuration
+    schema:
+      type: dict
+      attrs:
+        - variable: instanceName
+          label: Instance Name
+          description: The name of the SearXNG instance.
+          schema:
+            type: string
+            default: "SearXNG"
+            required: true
+        - variable: additionalEnvs
+          label: Additional Environment Variables
+          description: Configure additional environment variables for SearXNG.
+          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: searxngNetwork
+    label: ""
+    group: Network Configuration
+    schema:
+      type: dict
+      attrs:
+        - variable: webPort
+          label: Web Port
+          description: The port for the SearXNG Web UI.
+          schema:
+            type: int
+            default: 30053
+            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: searxngStorage
+    label: ""
+    group: Storage Configuration
+    schema:
+      type: dict
+      attrs:
+        - variable: config
+          label: SearXNG Config Storage
+          description: The path to store SearXNG Configuration.
+          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: "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 SearXNG.
+          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 SearXNG.
+                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 SearXNG.
+                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

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

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

+ 34 - 0
library/ix-dev/community/searxng/templates/_persistence.tpl

@@ -0,0 +1,34 @@
+{{- define "searxng.persistence" -}}
+persistence:
+  config:
+    enabled: true
+    type: {{ .Values.searxngStorage.config.type }}
+    datasetName: {{ .Values.searxngStorage.config.datasetName | default "" }}
+    hostPath: {{ .Values.searxngStorage.config.hostPath | default "" }}
+    targetSelector:
+      searxng:
+        searxng:
+          mountPath: /etc/searxng
+        01-permissions:
+          mountPath: /mnt/directories/searxng
+  tmp:
+    enabled: true
+    type: emptyDir
+    targetSelector:
+      searxng:
+        searxng:
+          mountPath: /tmp
+  {{- range $idx, $storage := .Values.searxngStorage.additionalStorages }}
+  {{ printf "searxng-%v" (int $idx) }}:
+    enabled: true
+    type: {{ $storage.type }}
+    datasetName: {{ $storage.datasetName | default "" }}
+    hostPath: {{ $storage.hostPath | default "" }}
+    targetSelector:
+      searxng:
+        searxng:
+          mountPath: {{ $storage.mountPath }}
+        01-permissions:
+          mountPath: /mnt/directories{{ $storage.mountPath }}
+  {{- end }}
+{{- end -}}

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

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

+ 48 - 0
library/ix-dev/community/searxng/templates/_searxng.tpl

@@ -0,0 +1,48 @@
+{{- define "searxng.workload" -}}
+workload:
+  searxng:
+    enabled: true
+    primary: true
+    type: Deployment
+    podSpec:
+      hostNetwork: {{ .Values.searxngNetwork.hostNetwork }}
+      containers:
+        searxng:
+          enabled: true
+          primary: true
+          imageSelector: image
+          securityContext:
+            runAsUser: 0
+            runAsGroup: 0
+            runAsNonRoot: false
+            capabilities:
+              add:
+                - SETUID
+                - SETGID
+          env:
+            BIND_ADDRESS: {{ printf "0.0.0.0:%v" .Values.searxngNetwork.webPort }}
+            INSTANCE_NAME: {{ .Values.searxngConfig.instanceName }}
+          {{ with .Values.searxngConfig.additionalEnvs }}
+          envList:
+            {{ range $env := . }}
+            - name: {{ $env.name }}
+              value: {{ $env.value }}
+            {{ end }}
+          {{ end }}
+          probes:
+            liveness:
+              enabled: true
+              type: http
+              port: "{{ .Values.searxngNetwork.webPort }}"
+              path: /healthz
+            readiness:
+              enabled: true
+              type: http
+              port: "{{ .Values.searxngNetwork.webPort }}"
+              path: /healthz
+            startup:
+              enabled: true
+              type: http
+              port: "{{ .Values.searxngNetwork.webPort }}"
+              path: /healthz
+{{- end -}}

+ 15 - 0
library/ix-dev/community/searxng/templates/_service.tpl

@@ -0,0 +1,15 @@
+{{- define "searxng.service" -}}
+service:
+  searxng:
+    enabled: true
+    primary: true
+    type: NodePort
+    targetSelector: searxng
+    ports:
+      webui:
+        enabled: true
+        primary: true
+        port: {{ .Values.searxngNetwork.webPort }}
+        nodePort: {{ .Values.searxngNetwork.webPort }}
+        targetSelector: searxng
+{{- end -}}

+ 11 - 0
library/ix-dev/community/searxng/templates/common.yaml

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

+ 1 - 0
library/ix-dev/community/searxng/upgrade_info.json

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

+ 31 - 0
library/ix-dev/community/searxng/upgrade_strategy

@@ -0,0 +1,31 @@
+#!/usr/bin/python3
+import json
+import re
+import sys
+
+from catalog_update.upgrade_strategy import datetime_versioning
+
+
+RE_STABLE_VERSION = re.compile(r'\d{4}.\d{1,2}.\d{1,2}-.+')
+
+
+def newer_mapping(image_tags):
+    key = list(image_tags.keys())[0]
+    tags = {t.split('-')[0]: t for t in image_tags[key] if RE_STABLE_VERSION.fullmatch(t)}
+    version = datetime_versioning(list(tags), '%Y.%m.%d')
+    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)))

+ 23 - 0
library/ix-dev/community/searxng/values.yaml

@@ -0,0 +1,23 @@
+image:
+  repository: searxng/searxng
+  pullPolicy: IfNotPresent
+  tag: 2023.7.7-cada89ee
+
+resources:
+  limits:
+    cpu: 4000m
+    memory: 8Gi
+
+searxngConfig:
+  instanceName: SearXNG
+  additionalEnvs: []
+
+searxngNetwork:
+  webPort: 30053
+  hostNetwork: false
+
+searxngStorage:
+  config:
+    type: ixVolume
+    datasetName: config
+  additionalStorages: []