diff --git a/library/ix-dev/charts/nextcloud/templates/_nextcloud.tpl b/library/ix-dev/charts/nextcloud/templates/_nextcloud.tpl new file mode 100644 index 0000000000..025bdc7897 --- /dev/null +++ b/library/ix-dev/charts/nextcloud/templates/_nextcloud.tpl @@ -0,0 +1,97 @@ +{{- define "nextcloud.workload" -}} +workload: + nextcloud: + enabled: true + primary: true + type: Deployment + podSpec: + hostNetwork: false + containers: + nextcloud: + enabled: true + primary: true + imageSelector: image + securityContext: + runAsUser: 0 + runAsGroup: 0 + runAsNonRoot: false + readOnlyRootFilesystem: false + capabilities: + add: + - CHOWN + - DAC_OVERRIDE + - FOWNER + - NET_BIND_SERVICE + - NET_RAW + {{ with .Values.ncConfig.additionalEnvs }} + envList: + {{ range $env := . }} + - name: {{ $env.name }} + value: {{ $env.value }} + {{ end }} + {{ end }} + probes: + liveness: + enabled: true + type: http + port: 80 + path: /status.php + httpHeaders: + Host: localhost + readiness: + enabled: true + type: http + port: 80 + path: /status.php + httpHeaders: + Host: localhost + startup: + enabled: true + {{- include "nextcloud.validate-commands" $ -}} + {{- $cmds := .Values.ncConfig.commands | mustUniq -}} + {{- if not $cmds }} + type: http + port: 80 + path: /status.php + httpHeaders: + Host: localhost + {{- else }} + type: exec + command: + - /bin/sh + - -c + - | + check_commands={{ join " " $cmds }} + for comm in $check_commands; do + if ! command -v $comm /dev/null 2>&1; then + echo "Command $comm not found" + exit 1 + fi + done + {{- end }} + lifecycle: + postStart: + type: exec + command: + - /bin/sh + - -c + - | + echo "Installing {{ join " " $cmds }}..." + apt update && apt install -y --no-install-recommends \ + {{ join " " $cmds }} || echo "Failed to install binary/binaries..." + echo "Finished." + initContainers: + {{- include "ix.v1.common.app.postgresWait" (dict "name" "postgres-wait" + "secretName" "postgres-creds") | nindent 8 }} +{{- end -}} + + +{{- define "nextcloud.validate-commands" -}} + {{- $allowedCommmads := list "ffmpeg" "smbclient" -}} + + {{- range $c := .Values.ncConfig.commands | mustUniq -}} + {{- if not (mustHas $c $allowedCommmads) -}} + {{- fail (printf "Nextcloud - Expected command to be one of [%s], but got [%s]" (join ", " $allowedCommmads) $c) -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/library/ix-dev/charts/nextcloud/templates/_nginx.tpl b/library/ix-dev/charts/nextcloud/templates/_nginx.tpl new file mode 100644 index 0000000000..6e0c42cd36 --- /dev/null +++ b/library/ix-dev/charts/nextcloud/templates/_nginx.tpl @@ -0,0 +1,76 @@ +{{- define "nginx.workload" -}} +workload: + nginx: + enabled: true + type: Deployment + podSpec: + hostNetwork: false + containers: + nginx: + enabled: true + primary: true + imageSelector: nginxImage + securityContext: + runAsUser: 0 + runAsGroup: 0 + runAsNonRoot: false + readOnlyRootFilesystem: false + capabilities: + add: + - CHOWN + - DAC_OVERRIDE + - FOWNER + - NET_BIND_SERVICE + - NET_RAW + {{ with .Values.ncConfig.additionalEnvs }} + envList: + {{ range $env := . }} + - name: {{ $env.name }} + value: {{ $env.value }} + {{ end }} + {{ end }} + probes: + liveness: + enabled: true + type: https + port: {{ .Values.ncNetwork.webPort }} + path: /status.php + httpHeaders: + Host: localhost + readiness: + enabled: true + type: https + port: {{ .Values.ncNetwork.webPort }} + path: /status.php + httpHeaders: + Host: localhost + startup: + enabled: true + type: https + port: {{ .Values.ncNetwork.webPort }} + path: /status.php + httpHeaders: + Host: localhost + {{- $fullname := (include "ix.v1.common.lib.chart.names.fullname" $) -}} + {{- $ncUrl := printf "http://%s:80" $fullname }} + {{- if .Values.ncNetwork.certificateID -}} + {{- $ncUrl = printf "https://%s:%s" $fullname .Values.ncNetwork.webPort -}} + {{- end }} + initContainers: + 01-wait-server: + enabled: true + type: init + imageSelector: bashImage + command: + - bash + args: + - -c + - | + echo "Waiting for [{{ $ncUrl }}]"; + until wget --spider --quiet --timeout=3 --tries=1 {{ $ncUrl }}/status.php; + do + echo "Waiting for [{{ $ncUrl }}]"; + sleep 2; + done + echo "API is up: {{ $ncUrl }}"; +{{- end -}} diff --git a/library/ix-dev/charts/nextcloud/templates/_service.tpl b/library/ix-dev/charts/nextcloud/templates/_service.tpl index 39df465ed6..11165ee8be 100644 --- a/library/ix-dev/charts/nextcloud/templates/_service.tpl +++ b/library/ix-dev/charts/nextcloud/templates/_service.tpl @@ -3,17 +3,38 @@ service: nextcloud: enabled: true primary: true + {{- if not .Values.ncNetwork.certificateID -}} type: NodePort + {{- else }} + type: ClusterIP + {{- end }} targetSelector: nextcloud ports: webui: enabled: true primary: true + {{- if not .Values.ncNetwork.certificateID }} + nodePort: {{ .Values.ncNetwork.webPort }} + port: {{ .Values.ncNetwork.webPort }} + {{- else -}} + port: 80 + {{- end }} + targetPort: 80 + targetSelector: nextcloud + {{- if .Values.ncNetwork.certificateID -}} + nextcloud-nginx: + enabled: true + primary: true + type: NodePort + targetSelector: nginx + ports: + webui-tls: + enabled: true port: {{ .Values.ncNetwork.webPort }} nodePort: {{ .Values.ncNetwork.webPort }} - {{- if not .Values.ncNetwork.certificateID }} - targetPort: 80 - {{- end }} - targetSelector: nextcloud + targetPort: {{ .Values.ncNetwork.webPort }} + targetSelector: nginx + {{- end }} + {{- include "ix.v1.common.app.postgresService" $ | nindent 2 }} {{- end -}} diff --git a/library/ix-dev/charts/nextcloud/templates/common.yaml b/library/ix-dev/charts/nextcloud/templates/common.yaml index c41850e095..12374b9430 100644 --- a/library/ix-dev/charts/nextcloud/templates/common.yaml +++ b/library/ix-dev/charts/nextcloud/templates/common.yaml @@ -4,6 +4,7 @@ {{/* Merge the templates with Values */}} {{- $_ := mustMergeOverwrite .Values (include "nextcloud.workload" $ | fromYaml) -}} +{{- $_ := mustMergeOverwrite .Values (include "nginx.workload" $ | fromYaml) -}} {{- $_ := mustMergeOverwrite .Values (include "postgres.workload" $ | fromYaml) -}} {{- $_ := mustMergeOverwrite .Values (include "nextcloud.service" $ | fromYaml) -}} {{- $_ := mustMergeOverwrite .Values (include "nextcloud.persistence" $ | fromYaml) -}} diff --git a/library/ix-dev/charts/nextcloud/values.yaml b/library/ix-dev/charts/nextcloud/values.yaml index b0dbbaecfd..407ce1d85b 100644 --- a/library/ix-dev/charts/nextcloud/values.yaml +++ b/library/ix-dev/charts/nextcloud/values.yaml @@ -17,3 +17,17 @@ resources: limits: cpu: 4000m memory: 8Gi + +podOptions: + dnsConfig: + options: [] + +ncConfig: + additionalEnvs: [] + commands: + - ffmpeg + - smbclient + +ncNetwork: + webPort: 9001 + certificateID: