Skip to content

Commit be60e91

Browse files
authored
feat(nextcloud): add support of imaginary an externalPreviewProvider #622
2 parents 1f793b5 + 9b7a468 commit be60e91

File tree

11 files changed

+346
-35
lines changed

11 files changed

+346
-35
lines changed

.github/tests/test_job.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: test-nextcloud
6+
namespace: nextcloud
7+
spec:
8+
template:
9+
metadata:
10+
name: test-nextcloud
11+
spec:
12+
initContainers:
13+
- name: 05-create-nextcloud-file
14+
image: curlimages/curl
15+
command:
16+
- /bin/sh
17+
- -c
18+
- |
19+
set -e
20+
echo "download image:"
21+
curl -s "https://upload.wikimedia.org/wikipedia/commons/d/df/Open_data.png" -o test_upload.png
22+
echo "upload to nextcloud:"
23+
curl \
24+
-s \
25+
-w "%{http_code}" \
26+
-u admin:changeme \
27+
-T test_upload.png \
28+
"http://nextcloud.nextcloud.svc.cluster.local:8080/remote.php/dav/files/admin/test_upload.png" || exit 1;
29+
echo "done"
30+
- name: 10-generate-preview
31+
image: docker.io/library/nextcloud:latest
32+
command:
33+
- /bin/sh
34+
- -c
35+
- |
36+
set -e
37+
echo "fetch preview:"
38+
OUTPUT=$(curl \
39+
-s \
40+
-w "%{http_code}" \
41+
-u admin:changeme \
42+
"http://nextcloud.nextcloud.svc.cluster.local:8080/index.php/core/preview.png?file=test_upload.png&x=128&y=128&mimeFallback=true&a=0" \
43+
-o - | file -)
44+
echo "${OUTPUT}";
45+
if ! echo "${OUTPUT}" | grep -q "PNG"; then
46+
echo "PNG was not detected"
47+
exit 1;
48+
fi
49+
if ! echo "${OUTPUT}" | grep -q "256 x 256"; then
50+
echo "Image size is incorrect"
51+
exit 1;
52+
fi
53+
echo "done"
54+
containers:
55+
- name: final
56+
image: curlimages/curl
57+
command:
58+
- /bin/sh
59+
- -c
60+
- |
61+
set -e
62+
echo "All tests run successfull (initContainer in given order)"
63+
restartPolicy: Never

.github/tests/test_upload_job.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/lint-test.yaml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ jobs:
8888
# we need to skip the clean up so we can test adding a file
8989
helm_args: |
9090
--namespace nextcloud --skip-clean-up --helm-extra-set-args "--values charts/nextcloud/test-values/s3-as-primary-storage.yaml"
91+
test: true
92+
93+
# test the helm chart with imaginary
94+
- name: Imaginary Enabled
95+
helm_args: --namespace nextcloud --skip-clean-up --helm-extra-set-args "--create-namespace --values charts/nextcloud/test-values/imaginary.yaml"
96+
test: true
9197

9298
steps:
9399
- name: Checkout
@@ -140,18 +146,20 @@ jobs:
140146
if: steps.list-changed.outputs.changed == 'true'
141147
run: ct install --target-branch ${{ github.event.repository.default_branch }} ${{ matrix.test_cases.helm_args }}
142148

143-
- name: Try adding a file to Nextcloud
144-
if: matrix.test_cases.name == 'S3 Enabled as Primary Storage'
149+
- name: Run test for Nextcloud
150+
if: matrix.test_cases.test
145151
# applies a kubernetes job that uploads a file and then checks log of finished pod
146152
run: |
153+
EXIT=0
147154
kubectl config set-context --current --namespace=nextcloud && \
148-
kubectl apply -f ./.github/tests/test_upload_job.yaml --wait=true && \
155+
kubectl apply -f ./.github/tests/test_job.yaml --wait=true && \
149156
sleep 2 && \
150-
kubectl wait --for=condition=Complete --timeout=2m job/create-nextcloud-file && \
151-
echo "Here's the logs from the job:" && \
152-
kubectl logs --tail=-1 -f -l batch.kubernetes.io/job-name=create-nextcloud-file && \
153-
echo "Here's the logs from the nextcloud pod:" && \
154-
kubectl logs -l app.kubernetes.io/name=nextcloud
157+
kubectl wait --for=condition=Complete --timeout=2m job/test-nextcloud || EXIT=1
158+
echo "Here's the logs from the job:"
159+
kubectl logs --ignore-errors --prefix --tail=-1 --all-containers=true -l batch.kubernetes.io/job-name=test-nextcloud
160+
echo "Here's the logs from the nextcloud pod:"
161+
kubectl logs --ignore-errors --prefix -l app.kubernetes.io/name=nextcloud
162+
exit $EXIT
155163
156164
summary:
157165
runs-on: ubuntu-latest-low

charts/nextcloud/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: nextcloud
3-
version: 6.4.1
3+
version: 6.5.0
44
appVersion: 30.0.4
55
description: A file sharing server that puts the control and security of your own data back into your hands.
66
keywords:

charts/nextcloud/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ helm install my-release nextcloud/nextcloud
2828
* [Headers set on NGINX](#headers-set-on-nginx)
2929
* [Probes Configurations](#probes-configurations)
3030
* [Collabora Configuration](#collabora-configuration)
31+
* [Imaginary](#imaginary)
3132
* [Cron jobs](#cron-jobs)
3233
* [Using the nextcloud docker image auto-configuration via env vars](#using-the-nextcloud-docker-image-auto-configuration-via-env-vars)
3334
* [Multiple config.php file](#multiple-configphp-file)
@@ -530,6 +531,42 @@ This section provides options to enable and configure the Collabora Online serve
530531
>
531532
> For more information, please check the [Collabora documentation](https://sdk.collaboraonline.com/docs/installation/index.html).
532533

534+
### Imaginary
535+
536+
We include an optional external preview provider from [h2non/imaginary](https://github.com/h2non/imaginary).
537+
538+
| Parameter | Description | Default |
539+
|----------------------------------------|-----------------------------------------------------------------------------------------|-------------------|
540+
| `imaginary.enabled` | Start Imaginary | `false` |
541+
| `imaginary.replicaCount` | Number of imaginary pod replicas to deploy | `1` |
542+
| `imaginary.image.registry` | Imaginary image name | `docker.io` |
543+
| `imaginary.image.repository` | Imaginary image name | `h2non/imaginary` |
544+
| `imaginary.image.tag` | Imaginary image tag | `1.2.4` |
545+
| `imaginary.image.pullPolicy` | Imaginary image pull policy | `IfNotPresent` |
546+
| `imaginary.image.pullSecrets` | Imaginary image pull secrets | `nil` |
547+
| `imaginary.podAnnotations` | Additional annotations for imaginary | `{}` |
548+
| `imaginary.podLabels` | Additional labels for imaginary | `{}` |
549+
| `imaginary.resources` | imaginary resources | `{}` |
550+
| `imaginary.securityContext` | Optional security context for the Imaginary container | `nil` |
551+
| `imaginary.podSecurityContext` | Optional security context for the Imaginary pod (applies to all containers in the pod) | `nil` |
552+
| `imaginary.service.type` | Imaginary: Kubernetes Service type | `ClusterIP` |
553+
| `imaginary.service.loadBalancerIP` | Imaginary: LoadBalancerIp for service type LoadBalancer | `nil` |
554+
| `imaginary.service.nodePort` | Imaginary: NodePort for service type NodePort | `nil` |
555+
| `imaginary.service.annotations` | Additional annotations for service imaginary | `{}` |
556+
| `imaginary.service.labels` | Additional labels for service imaginary | `{}` |
557+
558+
559+
> [!Note]
560+
> You also need to setup nextcloud, to use imaginary
561+
```yaml
562+
nextcloud:
563+
defaultConfigs:
564+
imaginary.config.php: true
565+
566+
imaginary:
567+
enabled: true
568+
```
569+
533570
## Cron jobs
534571

535572
To execute [background tasks](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/background_jobs_configuration.html) by using system cron instead of default Ajax cron, set `cronjob.enabled` parameter to `true`. Background jobs are important for tasks that do not necessarily need user intervention, but still need to be executed frequently (cleaning up, sending some notifications, pulling RSS feeds, etc.).
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
$CONFIG = array (
3+
'preview_imaginary_url' => 'http://{{ template "nextcloud.fullname" . }}-imaginary',
4+
'enable_previews' => true,
5+
'enabledPreviewProviders' => array (
6+
'OC\Preview\Imaginary',
7+
'OC\Preview\ImaginaryPDF',
8+
/*
9+
defaults:
10+
https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#enabledpreviewproviders
11+
*/
12+
'OC\Preview\BMP',
13+
// 'OC\Preview\GIF',
14+
// 'OC\Preview\JPEG',
15+
'OC\Preview\Krita',
16+
'OC\Preview\MarkDown',
17+
'OC\Preview\MP3',
18+
'OC\Preview\OpenDocument',
19+
// 'OC\Preview\PNG',
20+
'OC\Preview\TXT',
21+
'OC\Preview\XBitmap',
22+
),
23+
);
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{{- if .Values.imaginary.enabled }}
2+
---
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
name: {{ template "nextcloud.fullname" . }}-imaginary
7+
labels:
8+
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
9+
helm.sh/chart: {{ include "nextcloud.chart" . }}
10+
app.kubernetes.io/instance: {{ .Release.Name }}
11+
app.kubernetes.io/managed-by: {{ .Release.Service }}
12+
app.kubernetes.io/component: imaginary
13+
spec:
14+
replicas: {{ .Values.imaginary.replicaCount }}
15+
selector:
16+
matchLabels:
17+
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
18+
app.kubernetes.io/instance: {{ .Release.Name }}
19+
app.kubernetes.io/component: imaginary
20+
template:
21+
metadata:
22+
annotations:
23+
{{- toYaml .Values.imaginary.podAnnotations | nindent 8 }}
24+
labels:
25+
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
26+
app.kubernetes.io/instance: {{ .Release.Name }}
27+
app.kubernetes.io/component: imaginary
28+
{{- with .Values.imaginary.podLabels }}
29+
{{- toYaml . | nindent 8 }}
30+
{{- end }}
31+
spec:
32+
{{- with .Values.imaginary.image.pullSecrets }}
33+
imagePullSecrets:
34+
{{- range . }}
35+
- name: {{ . }}
36+
{{- end}}
37+
{{- end }}
38+
containers:
39+
- name: imaginary
40+
{{- with .Values.imaginary.image }}
41+
image: "{{ .registry }}/{{ .repository }}:{{ .tag }}"
42+
imagePullPolicy: {{ .pullPolicy }}
43+
{{- end }}
44+
env:
45+
- name: PORT
46+
value: "9000"
47+
ports:
48+
- name: http
49+
containerPort: 9000
50+
{{- with .Values.imaginary.readinessProbe }}
51+
{{- if .enabled }}
52+
readinessProbe:
53+
httpGet:
54+
path: /health
55+
port: http
56+
scheme: HTTP
57+
failureThreshold: {{ .failureThreshold }}
58+
successThreshold: {{ .successThreshold }}
59+
periodSeconds: {{ .periodSeconds }}
60+
timeoutSeconds: {{ .timeoutSeconds }}
61+
{{- end }}
62+
{{- end }}
63+
{{- with .Values.imaginary.livenessProbe }}
64+
{{- if .enabled }}
65+
livenessProbe:
66+
httpGet:
67+
path: /health
68+
port: http
69+
scheme: HTTP
70+
failureThreshold: {{ .failureThreshold }}
71+
successThreshold: {{ .successThreshold }}
72+
periodSeconds: {{ .periodSeconds }}
73+
timeoutSeconds: {{ .timeoutSeconds }}
74+
{{- end }}
75+
{{- end }}
76+
{{- with .Values.imaginary.resources }}
77+
resources:
78+
{{- toYaml . | nindent 12 }}
79+
{{- end }}
80+
{{- with .Values.imaginary.securityContext }}
81+
securityContext:
82+
{{- toYaml . | nindent 12 }}
83+
{{- end }}
84+
{{- with .Values.imaginary.podSecurityContext }}
85+
securityContext:
86+
{{- toYaml . | nindent 12 }}
87+
{{- end }}
88+
{{- end }}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{{- if .Values.imaginary.enabled }}
2+
---
3+
apiVersion: v1
4+
kind: Service
5+
metadata:
6+
name: {{ template "nextcloud.fullname" . }}-imaginary
7+
labels:
8+
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
9+
helm.sh/chart: {{ include "nextcloud.chart" . }}
10+
app.kubernetes.io/instance: {{ .Release.Name }}
11+
app.kubernetes.io/managed-by: {{ .Release.Service }}
12+
app.kubernetes.io/component: imaginary
13+
{{- with .Values.imaginary.service.labels }}
14+
{{- toYaml . | nindent 4 }}
15+
{{- end }}
16+
{{- with .Values.imaginary.service.annotations }}
17+
annotations:
18+
{{- toYaml . | nindent 4 }}
19+
{{- end }}
20+
spec:
21+
type: {{ .Values.imaginary.service.type }}
22+
{{- with .Values.imaginary.service.loadBalancerIP }}
23+
loadBalancerIP: {{ . }}
24+
{{- end }}
25+
ports:
26+
- name: http
27+
port: 80
28+
targetPort: http
29+
{{- with .Values.imaginary.service.nodePort }}
30+
nodePort: {{ . }}
31+
{{- end }}
32+
selector:
33+
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
34+
app.kubernetes.io/instance: {{ .Release.Name }}
35+
app.kubernetes.io/component: imaginary
36+
{{- end }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fullnameOverride: nextcloud
2+
3+
nextcloud:
4+
host: nextcloud
5+
trustedDomains:
6+
- 'nextcloud.nextcloud.svc.cluster.local'
7+
- 'nextcloud'
8+
defaultConfigs:
9+
imaginary.config.php: true
10+
11+
imaginary:
12+
enabled: true

charts/nextcloud/test-values/s3-as-primary-storage.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ nginx:
88

99
nextcloud:
1010
host: nextcloud
11+
trustedDomains:
12+
- 'nextcloud.nextcloud.svc.cluster.local'
13+
- 'nextcloud'
1114
objectStore:
1215
s3:
1316
enabled: true

0 commit comments

Comments
 (0)