Skip to content

Commit

Permalink
Add default S3 object storage config from nextcloud/docker
Browse files Browse the repository at this point in the history
Signed-off-by: jessebot <[email protected]>
  • Loading branch information
jessebot committed Nov 8, 2023
1 parent 815be01 commit 6acdb33
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 39 deletions.
2 changes: 1 addition & 1 deletion charts/nextcloud/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: nextcloud
version: 4.4.0
version: 4.4.1
appVersion: 27.1.3
description: A file sharing server that puts the control and security of your own data back into your hands.
keywords:
Expand Down
88 changes: 74 additions & 14 deletions charts/nextcloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ helm install my-release nextcloud/nextcloud
* [Persistence Configurations](#persistence-configurations)
* [Metrics Configurations](#metrics-configurations)
* [Cron jobs](#cron-jobs)
* [Using the nextcloud docker image auto-configuration via env vars](#using-the-nextcloud-docker-image-auto-configuration-via-env-vars)
* [Multiple config.php file](#multiple-configphp-file)
* [Using nginx](#using-nginx)
* [Preserving Source IP](#preserving-source-ip)
Expand All @@ -31,6 +32,7 @@ helm install my-release nextcloud/nextcloud
* [Backups](#backups)
* [Upgrades](#upgrades)


## Introduction

This chart bootstraps an [nextcloud](https://hub.docker.com/_/nextcloud/) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.
Expand Down Expand Up @@ -128,6 +130,7 @@ The following table lists the configurable parameters of the nextcloud chart and
| `nextcloud.defaultConfigs.apps\.config\.php` | Default configuration for apps | `true` |
| `nextcloud.defaultConfigs.autoconfig\.php` | Default auto-configuration for databases | `true` |
| `nextcloud.defaultConfigs.smtp\.config\.php` | Default configuration for smtp | `true` |
| `nextcloud.defaultConfigs.s3\.config\.php` | Default configuration for S3 as primary Object Storage | `true` |
| `nextcloud.strategy` | specifies the strategy used to replace old Pods by new ones | `type: Recreate` |
| `nextcloud.extraEnv` | specify additional environment variables | `{}` |
| `nextcloud.extraSidecarContainers` | specify additional sidecar containers | `[]` |
Expand Down Expand Up @@ -337,31 +340,88 @@ To execute [background tasks](https://docs.nextcloud.com/server/latest/admin_man
Enabling this option will create a sidecar container in the Nextcloud pod, which will start a [`crond` daemon](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/background_jobs_configuration.html#cron) responsible for running the Nextcloud cron.php script. At first launch, the background jobs mode in your Nextcloud basic settings will automatically be set to ***Cron***.
## Using the nextcloud docker image auto-configuration via env vars
The [nextcloud/docker](https://github.com/nextcloud/docker/tree/master) image provides an auto-configuration via environment variables. See [their docs](https://github.com/nextcloud/docker/tree/master#auto-configuration-via-environment-variables) for more info.
For example, if you want to enable S3 as your primary object storage, you can set the following environment variables:
```yaml
# To use an external S3 compatible object store as primary storage, set the following variables:
nextcloud:
extraEnv:
- name: "OBJECTSTORE_S3_HOST"
valueFrom:
secretKeyRef:
name: my-existing-kubernetes-secret
key: S3_HOSTNAME
- name: "OBJECTSTORE_S3_BUCKET"
valueFrom:
secretKeyRef:
name: my-existing-kubernetes-secret
key: S3_BUCKET
- name: "OBJECTSTORE_S3_KEY"
valueFrom:
secretKeyRef:
name: my-existing-kubernetes-secret
key: S3_USER
- name: "OBJECTSTORE_S3_SECRET"
valueFrom:
secretKeyRef:
name: my-existing-kubernetes-secret
key: S3_PASSWORD
- name: "OBJECTSTORE_S3_PORT"
value: "443"
- name: "OBJECTSTORE_S3_SSL"
value: "true"
- name: "OBJECTSTORE_S3_REGION"
value: "eu-west-1"
- name: "OBJECTSTORE_S3_USEPATH_STYLE"
value: "true"
- name: "OBJECTSTORE_S3_SSE_C_KEY"
valueFrom:
secretKeyRef:
name: my-existing-kubernetes-secret
key: S3_ENCRYPTION_KEY
```
## Multiple config.php file
Nextcloud supports loading configuration parameters from multiple files.
You can add arbitrary files ending with `.config.php` in the `config/` directory.
See [documentation](https://docs.nextcloud.com/server/15/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-config-php-file).
See [documentation](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-config-php-file). For example, to enable image and document previews:
For example, following config will configure Nextcloud with [S3 as primary storage](https://docs.nextcloud.com/server/13/admin_manual/configuration_files/primary_storage.html#simple-storage-service-s3) by creating file `/var/www/html/config/s3.config.php`:
```yaml
nextcloud:
configs:
s3.config.php: |-
previews.config.php: |-
<?php
$CONFIG = array (
'objectstore' => array(
'class' => '\\OC\\Files\\ObjectStore\\S3',
'arguments' => array(
'bucket' => 'my-bucket',
'autocreate' => true,
'key' => 'xxx',
'secret' => 'xxx',
'region' => 'us-east-1',
'use_ssl' => true
)
)
'enable_previews' => true,
'enabledPreviewProviders' => array (
'OC\Preview\Movie',
'OC\Preview\PNG',
'OC\Preview\JPEG',
'OC\Preview\GIF',
'OC\Preview\BMP',
'OC\Preview\XBitmap',
'OC\Preview\MP3',
'OC\Preview\MP4',
'OC\Preview\TXT',
'OC\Preview\MarkDown',
'OC\Preview\PDF'
),
);
```
Expand Down
50 changes: 50 additions & 0 deletions charts/nextcloud/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,55 @@ data:
);
}
{{- end }}
{{- if index .Values.nextcloud.defaultConfigs "smtp.config.php" }}
s3.config.php: |-
<?php
if (getenv('OBJECTSTORE_S3_BUCKET')) {
$use_ssl = getenv('OBJECTSTORE_S3_SSL');
$use_path = getenv('OBJECTSTORE_S3_USEPATH_STYLE');
$use_legacyauth = getenv('OBJECTSTORE_S3_LEGACYAUTH');
$autocreate = getenv('OBJECTSTORE_S3_AUTOCREATE');
$CONFIG = array(
'objectstore' => array(
'class' => '\OC\Files\ObjectStore\S3',
'arguments' => array(
'bucket' => getenv('OBJECTSTORE_S3_BUCKET'),
'region' => getenv('OBJECTSTORE_S3_REGION') ?: '',
'hostname' => getenv('OBJECTSTORE_S3_HOST') ?: '',
'port' => getenv('OBJECTSTORE_S3_PORT') ?: '',
'objectPrefix' => getenv("OBJECTSTORE_S3_OBJECT_PREFIX") ? getenv("OBJECTSTORE_S3_OBJECT_PREFIX") : "urn:oid:",
'autocreate' => (strtolower($autocreate) === 'false' || $autocreate == false) ? false : true,
'use_ssl' => (strtolower($use_ssl) === 'false' || $use_ssl == false) ? false : true,
// required for some non Amazon S3 implementations
'use_path_style' => $use_path == true && strtolower($use_path) !== 'false',
// required for older protocol versions
'legacy_auth' => $use_legacyauth == true && strtolower($use_legacyauth) !== 'false'
)
)
);
if (getenv('OBJECTSTORE_S3_SSE_C_KEY_FILE') && file_exists(getenv('OBJECTSTORE_S3_SSE_C_KEY_FILE'))) {
$CONFIG['objectstore']['arguments']['sse_c_key'] = trim(file_get_contents(getenv('OBJECTSTORE_S3_SSE_C_KEY_FILE'));
} elseif (getenv('OBJECTSTORE_S3_SSE_C_KEY')) {
$CONFIG['objectstore']['arguments']['sse_c_key'] = getenv('OBJECTSTORE_S3_SSE_C_KEY');
}
if (getenv('OBJECTSTORE_S3_KEY_FILE') && file_exists(getenv('OBJECTSTORE_S3_KEY_FILE'))) {
$CONFIG['objectstore']['arguments']['key'] = trim(file_get_contents(getenv('OBJECTSTORE_S3_KEY_FILE')));
} elseif (getenv('OBJECTSTORE_S3_KEY')) {
$CONFIG['objectstore']['arguments']['key'] = getenv('OBJECTSTORE_S3_KEY');
} else {
$CONFIG['objectstore']['arguments']['key'] = '';
}
if (getenv('OBJECTSTORE_S3_SECRET_FILE') && file_exists(getenv('OBJECTSTORE_S3_SECRET_FILE'))) {
$CONFIG['objectstore']['arguments']['secret'] = trim(file_get_contents(getenv('OBJECTSTORE_S3_SECRET_FILE')));
} elseif (getenv('OBJECTSTORE_S3_SECRET')) {
$CONFIG['objectstore']['arguments']['secret'] = getenv('OBJECTSTORE_S3_SECRET');
} else {
$CONFIG['objectstore']['arguments']['secret'] = '';
}
}
{{- end }}
{{- end }}
{{- end }}
51 changes: 27 additions & 24 deletions charts/nextcloud/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ nextcloud:
# PHP Configuration files
# Will be injected in /usr/local/etc/php/conf.d for apache image and in /usr/local/etc/php-fpm.d when nginx.enabled: true
phpConfigs: {}
# Default config files
# Default config files that utilize environment variables:

Check failure on line 107 in charts/nextcloud/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test

107:61 [trailing-spaces] trailing spaces
# see: https://github.com/nextcloud/docker/tree/master#auto-configuration-via-environment-variables
# IMPORTANT: Will be used only if you put extra configs, otherwise default will come from nextcloud itself
# Default confgurations can be found here: https://github.com/nextcloud/docker/tree/master/16.0/apache/config
# Default confgurations can be found here: https://github.com/nextcloud/docker/tree/master/.config
defaultConfigs:
# To protect /var/www/html/config
.htaccess: true
Expand All @@ -120,31 +121,33 @@ nextcloud:
apps.config.php: true
# Used for auto configure database
autoconfig.php: true
# SMTP default configuration
# SMTP default configuration via environment variables
smtp.config.php: true
# S3 Object Storage as primary storage
s3.config.php: true

# Extra config files created in /var/www/html/config/
# ref: https://docs.nextcloud.com/server/15/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-config-php-file
# ref: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-config-php-file
configs: {}

# For example, to use S3 as primary storage
# ref: https://docs.nextcloud.com/server/13/admin_manual/configuration_files/primary_storage.html#simple-storage-service-s3
#
# configs:
# s3.config.php: |-
# <?php
# $CONFIG = array (
# 'objectstore' => array(
# 'class' => '\\OC\\Files\\ObjectStore\\S3',
# 'arguments' => array(
# 'bucket' => 'my-bucket',
# 'autocreate' => true,
# 'key' => 'xxx',
# 'secret' => 'xxx',
# 'region' => 'us-east-1',
# 'use_ssl' => true
# )
# )
# );
# For example, to enable image and text file previews:
# previews.config.php: |-
# <?php
# $CONFIG = array (
# 'enable_previews' => true,
# 'enabledPreviewProviders' => array (
# 'OC\Preview\Movie',
# 'OC\Preview\PNG',
# 'OC\Preview\JPEG',
# 'OC\Preview\GIF',
# 'OC\Preview\BMP',
# 'OC\Preview\XBitmap',
# 'OC\Preview\MP3',
# 'OC\Preview\MP4',
# 'OC\Preview\TXT',
# 'OC\Preview\MarkDown',
# 'OC\Preview\PDF'
# ),
# );

## Strategy used to replace old pods
## IMPORTANT: use with care, it is suggested to leave as that for upgrade purposes
Expand Down

0 comments on commit 6acdb33

Please sign in to comment.