From 14df2e5633c10cfb2345b6cbb20c00f4abafa7a6 Mon Sep 17 00:00:00 2001 From: WrenIX Date: Sat, 22 Feb 2025 01:58:14 +0100 Subject: [PATCH] fix(ocrserver): try language downloader --- ocrserver/Chart.yaml | 2 +- ocrserver/README.md | 22 +++++- ocrserver/templates/deployment.yaml | 30 ++++++-- ocrserver/templates/job.yaml | 96 +++++++++++++++++++++++++ ocrserver/templates/networkpolicy.yaml | 31 ++++++++ ocrserver/templates/pvc.yaml | 32 +++++++++ ocrserver/templates/serviceaccount.yaml | 7 +- ocrserver/values.yaml | 27 +++++++ 8 files changed, 238 insertions(+), 9 deletions(-) create mode 100644 ocrserver/templates/job.yaml create mode 100644 ocrserver/templates/pvc.yaml diff --git a/ocrserver/Chart.yaml b/ocrserver/Chart.yaml index 21e1345..7aca8a9 100644 --- a/ocrserver/Chart.yaml +++ b/ocrserver/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: ocrserver description: Run OCR-Server type: application -version: "0.1.0" +version: "0.2.0" # renovate: image=otiai10/ocrserver appVersion: "1.1.0" maintainers: diff --git a/ocrserver/README.md b/ocrserver/README.md index 7d6311f..2a5c5d3 100644 --- a/ocrserver/README.md +++ b/ocrserver/README.md @@ -7,7 +7,7 @@ description: "Run OCR-Server" # ocrserver -![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.1.0](https://img.shields.io/badge/AppVersion-1.1.0-informational?style=flat-square) +![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.1.0](https://img.shields.io/badge/AppVersion-1.1.0-informational?style=flat-square) Run OCR-Server @@ -73,10 +73,19 @@ helm uninstall ocrserver-release | ingress.hosts[0].paths[0].path | string | `"/"` | | | ingress.hosts[0].paths[0].pathType | string | `"ImplementationSpecific"` | | | ingress.tls | list | `[]` | | +| languagedownloader.enabled | bool | `true` | | +| languagedownloader.languages[0] | string | `"deu"` | | | livenessProbe.httpGet.path | string | `"/status"` | | | livenessProbe.httpGet.port | string | `"http"` | | | nameOverride | string | `""` | This is to override the chart name. | | nodeSelector | object | `{}` | | +| persistence.accessMode | string | `"ReadWriteOnce"` | | +| persistence.annotations | object | `{}` | | +| persistence.enabled | bool | `true` | | +| persistence.existingClaim | string | `nil` | A manually managed Persistent Volume and Claim Requires persistence.enabled: true If defined, PVC must be created manually before volume will be bound | +| persistence.hostPath | string | `nil` | Do not create an PVC, direct use hostPath in Pod | +| persistence.size | string | `"5Gi"` | | +| persistence.storageClass | string | `nil` | Persistent Volume Storage Class If defined, storageClassName: If set to "-", storageClassName: "", which disables dynamic provisioning If undefined (the default) or set to null, no storageClassName spec is set, choosing the default provisioner. (gp2 on AWS, standard on GKE, AWS & OpenStack) | | podAnnotations | object | `{}` | This is for setting Kubernetes Annotations to a Pod. For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ | | podLabels | object | `{}` | This is for setting Kubernetes Labels to a Pod. For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ | | podSecurityContext | object | `{}` | | @@ -98,7 +107,7 @@ helm uninstall ocrserver-release Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs) # ocrserver -![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.1.0](https://img.shields.io/badge/AppVersion-1.1.0-informational?style=flat-square) +![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.1.0](https://img.shields.io/badge/AppVersion-1.1.0-informational?style=flat-square) Run OCR-Server @@ -142,10 +151,19 @@ Run OCR-Server | ingress.hosts[0].paths[0].path | string | `"/"` | | | ingress.hosts[0].paths[0].pathType | string | `"ImplementationSpecific"` | | | ingress.tls | list | `[]` | | +| languagedownloader.enabled | bool | `true` | | +| languagedownloader.languages[0] | string | `"deu"` | | | livenessProbe.httpGet.path | string | `"/status"` | | | livenessProbe.httpGet.port | string | `"http"` | | | nameOverride | string | `""` | This is to override the chart name. | | nodeSelector | object | `{}` | | +| persistence.accessMode | string | `"ReadWriteOnce"` | | +| persistence.annotations | object | `{}` | | +| persistence.enabled | bool | `true` | | +| persistence.existingClaim | string | `nil` | A manually managed Persistent Volume and Claim Requires persistence.enabled: true If defined, PVC must be created manually before volume will be bound | +| persistence.hostPath | string | `nil` | Do not create an PVC, direct use hostPath in Pod | +| persistence.size | string | `"5Gi"` | | +| persistence.storageClass | string | `nil` | Persistent Volume Storage Class If defined, storageClassName: If set to "-", storageClassName: "", which disables dynamic provisioning If undefined (the default) or set to null, no storageClassName spec is set, choosing the default provisioner. (gp2 on AWS, standard on GKE, AWS & OpenStack) | | podAnnotations | object | `{}` | This is for setting Kubernetes Annotations to a Pod. For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ | | podLabels | object | `{}` | This is for setting Kubernetes Labels to a Pod. For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ | | podSecurityContext | object | `{}` | | diff --git a/ocrserver/templates/deployment.yaml b/ocrserver/templates/deployment.yaml index 02aefca..e200d65 100644 --- a/ocrserver/templates/deployment.yaml +++ b/ocrserver/templates/deployment.yaml @@ -19,6 +19,7 @@ spec: {{- end }} labels: {{- include "ocrserver.labels" . | nindent 8 }} + app.kubernetes.io/component: server {{- with .Values.podLabels }} {{- toYaml . | nindent 8 }} {{- end }} @@ -42,6 +43,14 @@ spec: image: "{{ .registry }}/{{ .repository }}:{{ .tag }}" imagePullPolicy: {{ .pullPolicy }} {{- end }} + command: [ "sh" ] + args: + - -c + - | + {{- range $lang := .Values.languagedownloader.languages }} + ln -s /data/{{ $lang }}.traineddata /usr/share/tesseract-ocr/4.00/tessdata/{{ $lang }}.traineddata + {{- end }} + ocrserver ports: - name: http containerPort: 8080 @@ -58,14 +67,27 @@ spec: resources: {{- toYaml . | nindent 12 }} {{- end }} - {{- with .Values.volumeMounts }} volumeMounts: + - mountPath: /data + name: languages + {{- with .Values.volumeMounts }} {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.volumes }} + {{- end }} volumes: + - name: languages + {{- if $.Values.persistence.hostPath }} + hostPath: + type: Directory + path: {{ $.Values.persistence.hostPath | quote }} + {{- else if $.Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ with $.Values.persistence.existingClaim }}{{ . }}{{- else }}{{ template "ocrserver.fullname" $ }}{{- end }} + {{- else }} + emptyDir: {} + {{- end }} + {{- with .Values.volumes }} {{- toYaml . | nindent 8 }} - {{- end }} + {{- end }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/ocrserver/templates/job.yaml b/ocrserver/templates/job.yaml new file mode 100644 index 0000000..eb3ef86 --- /dev/null +++ b/ocrserver/templates/job.yaml @@ -0,0 +1,96 @@ +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "ocrserver.fullname" . }}-downloader + labels: + {{- include "ocrserver.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "5" + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded +spec: + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "ocrserver.labels" . | nindent 8 }} + app.kubernetes.io/component: languages-downloader + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "ocrserver.serviceAccountName" . }} + {{- with .Values.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + restartPolicy: OnFailure + containers: + - name: {{ .Chart.Name }} + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.image }} + image: "{{ .registry }}/{{ .repository }}:{{ .tag }}" + imagePullPolicy: {{ .pullPolicy }} + {{- end }} + command: [ "sh" ] + args: + - -c + - | + apt-get update + apt-get install -y {{- range $lang := .Values.languagedownloader.languages }} tesseract-ocr-{{ $lang }}{{- end }} + {{- with .Values.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + volumeMounts: + - mountPath: /usr/share/tesseract-ocr/4.00/tessdata/ + name: languages + {{- with .Values.volumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + volumes: + - name: languages + {{- if $.Values.persistence.hostPath }} + hostPath: + type: Directory + path: {{ $.Values.persistence.hostPath | quote }} + {{- else if $.Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ with $.Values.persistence.existingClaim }}{{ . }}{{- else }}{{ template "ocrserver.fullname" $ }}{{- end }} + {{- else }} + emptyDir: {} + {{- end }} + {{- with .Values.volumes }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/ocrserver/templates/networkpolicy.yaml b/ocrserver/templates/networkpolicy.yaml index 783cbcd..e5409a8 100644 --- a/ocrserver/templates/networkpolicy.yaml +++ b/ocrserver/templates/networkpolicy.yaml @@ -11,6 +11,7 @@ spec: podSelector: matchLabels: {{- include "ocrserver.selectorLabels" $ | nindent 6 }} + app.kubernetes.io/component: server policyTypes: - Ingress {{- if .egress.enabled }} @@ -25,6 +26,36 @@ spec: {{- toYaml . | nindent 8 }} {{- end }}{{/* end-with .ingress.http */}} + {{- with .egress }} + {{- if .enabled }} + egress: + {{- with .extra }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- end }}{{/* end-if egress.enabled */}} + {{- end }}{{/* end-with .egress */}} +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: {{ include "ocrserver.fullname" $ }}-languagedownloader + labels: + {{- include "ocrserver.labels" $ | nindent 4 }} + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "5" + "helm.sh/hook-delete-policy": hook-failed +spec: + podSelector: + matchLabels: + {{- include "ocrserver.selectorLabels" $ | nindent 6 }} + app.kubernetes.io/component: languages-downloader + policyTypes: + - Ingress + {{- if .egress.enabled }} + - Egress + {{- end }} + {{- with .egress }} {{- if .enabled }} egress: diff --git a/ocrserver/templates/pvc.yaml b/ocrserver/templates/pvc.yaml new file mode 100644 index 0000000..1f97b0e --- /dev/null +++ b/ocrserver/templates/pvc.yaml @@ -0,0 +1,32 @@ +{{- if and + .Values.persistence.enabled + (not .Values.persistence.hostPath) + (not .Values.persistence.existingClaim) +}} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ template "ocrserver.fullname" . }} + labels: + {{- include "ocrserver.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "5" + "helm.sh/hook-delete-policy": hook-failed + {{- with .Values.persistence.annotations }} + {{ toYaml . | indent 4 }} + {{- end }} +spec: + accessModes: + - {{ .Values.persistence.accessMode | quote }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} + {{- with .Values.persistence.storageClass }} + {{- if (eq "-" .) }} + storageClassName: "" + {{- else }} + storageClassName: {{ . | quote }} + {{- end }} + {{- end }} +{{- end -}} diff --git a/ocrserver/templates/serviceaccount.yaml b/ocrserver/templates/serviceaccount.yaml index af5d83b..d03bc6e 100644 --- a/ocrserver/templates/serviceaccount.yaml +++ b/ocrserver/templates/serviceaccount.yaml @@ -5,9 +5,12 @@ metadata: name: {{ include "ocrserver.serviceAccountName" . }} labels: {{- include "ocrserver.labels" . | nindent 4 }} - {{- with .Values.serviceAccount.annotations }} annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "5" + "helm.sh/hook-delete-policy": hook-failed + {{- with .Values.serviceAccount.annotations }} {{- toYaml . | nindent 4 }} - {{- end }} + {{- end }} automountServiceAccountToken: {{ .Values.serviceAccount.automount }} {{- end }} diff --git a/ocrserver/values.yaml b/ocrserver/values.yaml index a748ffd..66ee00c 100644 --- a/ocrserver/values.yaml +++ b/ocrserver/values.yaml @@ -114,6 +114,33 @@ networkPolicy: matchLabels: k8s-app: kube-dns +languagedownloader: + enabled: true + languages: + - "deu" + +persistence: + enabled: true + annotations: {} + # -- Persistent Volume Storage Class + # If defined, storageClassName: + # If set to "-", storageClassName: "", which disables dynamic provisioning + # If undefined (the default) or set to null, no storageClassName spec is + # set, choosing the default provisioner. (gp2 on AWS, standard on + # GKE, AWS & OpenStack) + # + storageClass: + + # -- A manually managed Persistent Volume and Claim + # Requires persistence.enabled: true + # If defined, PVC must be created manually before volume will be bound + existingClaim: + + # -- Do not create an PVC, direct use hostPath in Pod + hostPath: + accessMode: ReadWriteOnce + size: 5Gi + # This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/ autoscaling: enabled: false