Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom skeleton environmental variable #1831

Closed
NorskNoobing opened this issue Oct 1, 2022 · 10 comments
Closed

Custom skeleton environmental variable #1831

NorskNoobing opened this issue Oct 1, 2022 · 10 comments
Labels
enhancement feature: auto config (environment variables) Auto configuring via environment variables needs review Needs confirmation this is still happening or relevant

Comments

@NorskNoobing
Copy link

Description

I would want an environmental variable in the docker image that allows you to set the skeletondirectory property in the config.php file.
This would work by implementing the same property as described in the config.php parameters documentation.

Examples

The following are examples of how this feature could be implemented.
Example 1:
Disable skeleton directory

environment:
      - SKELETON_DIRECTORY=false

Which would add the following to the config.php file.

'skeletondirectory' => false,

Example 2:
Define a custom skeleton directory path

environment:
      - SKELETON_DIRECTORY=/path/to/nextcloud/core/skeleton

Which would add the following to the config.php file.

'skeletondirectory' => '/path/to/nextcloud/core/skeleton',
@Leptopoda
Copy link
Member

hi there,
I don't see the NC docker team adding anything like this in the future as there are just too many options available.
Also some are dynamicly changed by the server so they shouldn't be loaded from a static env-var. Also there are just to many apps exposing thier own settings that adding all of them won't realistically be possible.

You can always add your own ones using a custom dockerfile. You can get an inspiration by the files that are currently bundled into the docker image here.
We run our stack with something like:

<?php
$CONFIG = array (
  'trashbin_retention_obligation' => getenv('TRASH_RETENTION'),
);

You can see the use of the function getenv. You can than do something like:

FROM nextcloud:fpm-alpine

COPY config/my-cool-custom-config.config.php /usr/src/nextcloud/config/

Please note that the nextcloud docker file only copies the config files once. This means the first run of the container will copy the files from /usr/src/nextcloud/config/ to /var/www/html/config. Subsequent runs won't do that so you'd have to manually do so.

Than build your own docker image or let compose do so and you're good to go. If you don't need a custom docker image that can reproduicably be used to setup your NC instance you can also just add the custom config.php into the config directory and don't need to build your own image.

@NorskNoobing
Copy link
Author

Oh, I don't really know much about this other than the pretty easy work-around to change one line in the config.php file that I get from a persistent volume. Then as mentioned earlier I set the following line:

'skeletondirectory' => false,

This is exactly how the other env variables work too. They just change a string in the config.php. That's why I though it was an easy task.

@Leptopoda
Copy link
Member

Leptopoda commented Oct 19, 2022

Configuring the server through the config.php is an expected task and not a workarround. It's fully normal to do so.

The Nextcloud image supports auto configuration via environment variables. You can preconfigure everything that is asked on the install page on first run.

The readme says that configuration through env's is only implemented for some basic configuration options.
As mentioned in my first reply there is an endless amount of options an admin can define thus the docker image can't easily account for all of them. This is the reason why only a limited set for the most basic setup is present.

If you only need this for one deployment just edit the config.php as this is the normal way to do so. If you ceed a reproduicible way to automatically setup the serer config (maybe some automation or so) you should use a custom Dockerfile ;)

here's also a comment by a dev:

I'm just afraid of adding a new ENV for every setting that was ever implemented by Nextcloud. You can already use environment variables with the NC_ prefix for simple settings.

@k0dard
Copy link

k0dard commented Oct 20, 2022

Judging by this nextcloud/server#3966 it should be possible to configure settings from config.php through environment variables by prefixing with NC_
I'm also trying to remove skeleton directory but setting NC_SKELETONDIRECTORY= doesn't work... :/

@k0dard
Copy link

k0dard commented Oct 20, 2022

And also I don't really understand what's the point of having default skeleton directory provided by next cloud? The chance is that 99% of people will either want to put their own skeleton directories or start without any files. Having some random pictures and videos is just annoying... Wouldn't it be more natural to start off with empty directory by default with possibility to specify your own skeleton directory if needed ?

@joshtrichards joshtrichards added enhancement feature: auto config (environment variables) Auto configuring via environment variables labels Oct 21, 2023
@joshtrichards joshtrichards added the needs review Needs confirmation this is still happening or relevant label Jun 18, 2024
@joshtrichards joshtrichards changed the title Feature request: Custom skeleton environmental variable Custom skeleton environmental variable Jun 20, 2024
@joshtrichards
Copy link
Member

Direct support is not going to get added to the image because there are already plenty of ways to set additional config parameters these days:

  • manually in config.php (conventional Nextcloud)
  • using auto-configuration hooks (see the README; any occ command can be executed therefore most any sys or app value set as well)
  • the NC_ method
  • extending the image yourself (see the README)

@joshtrichards joshtrichards closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2024
@NorskNoobing
Copy link
Author

Direct support is not going to get added to the image because there are already plenty of ways to set additional config parameters these days:

* manually in `config.php` (conventional Nextcloud)

* using auto-configuration hooks (see the README; any `occ` command can be executed therefore most any sys _or_ app value set as well)

* the `NC_` method

* extending the image yourself (see the README)

Like @k0dard mentioned earlier:

I'm also trying to remove skeleton directory but setting NC_SKELETONDIRECTORY= doesn't work... :/

I just tried both using uppercase NC_SKELETONDIRECTORY=false and lowercase NC_skeletondirectory=false, but this doesn't add anything regarding skeletondirectory in the config.php file. So the NC_ env var doesn't seem to be working correctly, or not for this setting in particular. Please correct me if I did anything wrong.

Workaround

I managed to workaround this problem by using the auto-config hooks like @joshtrichards mentioned. This was done by:

  1. Adding the following to my composefile (note that "pre-installation" won't work, because the php occ command isn't installed yet.):
volumes:
      #available options: pre-installation,post-installation,pre-upgrade,post-upgrade,before-starting
      - PATH_TO_SCRIPT/disableSkeletonPath.sh:/docker-entrypoint-hooks.d/before-starting/disableSkeletonPath.sh
  1. Running the following commands to create the script, and set the executable flag:
echo 'php occ config:system:set skeletondirectory --value="" --type=string' | sudo tee PATH_TO_SCRIPT/disableSkeletonPath.sh
sudo chmod +x PATH_TO_SCRIPT/disableSkeletonPath.sh

An important thing to note is that this isn't applied for the default admin account, as it seems like it gets all the skeletonfiles during installation of nextcloud. However, all the users that are created after the initial installation seems to not have any skeletonfiles, like expected.

Resources

@joshtrichards
Copy link
Member

joshtrichards commented Jun 26, 2024

Thanks, @NorskNoobing, for following up on this.

I just tried both using uppercase NC_SKELETONDIRECTORY=false and lowercase NC_skeletondirectory=false, but this doesn't add anything regarding skeletondirectory in the config.php file. So the NC_ env var doesn't seem to be working correctly, or not for this setting in particular. Please correct me if I did anything wrong.

NC_skeletondirectory= (an empty value) works for me and that seems to match what the Server docs prefer for what you're trying to accomplish.

e.g.

docker run -d -p 58080:80 -e NC_skeletondirectory= nextcloud

Results in, after visiting the web installer url, an install w/o my initial admin account have the default skeleton contents from /core/skeleton that would typically get pulled in.

Note that it won't appear in your config.php. The NC_* variables are used in place of whatever is in config.php. I don't believe they show up anywhere, including even occ config:list system at present unfortunately. (P.S. Going to look into this because from a quick look at the code I would expect them to Found the cause. Upstream fix pending for the NC_ overrides to start being shown in occ config:system list: nextcloud/server#46140).

P.S. Let's try to boost the documentation a bit in this area:

@NorskNoobing
Copy link
Author

Oh, I see. It works more like a override, rather than writing to the config file, like how I thought it was working.

I just tried with uppercase NC_SKELETONDIRECTORY and lowercase NC_skeletondirectory= again in my composefile, and it seems like it's case-sensitive. This explains why @k0dard didn't get it working previously. Only the lowercase one works, but this works better than using hooks. It seemed like I couldn't prevent the default admin user from getting the skeletonfiles when using the hook-script, but the default admin user doesn't get any skeletonfiles when using with the env-var.

The composefile would then be:

...
environment:
  - NC_skeletondirectory=
...

I tried both using the default admin account and a manually created account, and both of them are missing the skeletonfiles, as expected. Thanks to everyone for the contribtion in this issue!

@joshtrichards Did you want me to create and provide some docs on this, or was it just to cross-reference the issues?

@joshtrichards
Copy link
Member

joshtrichards commented Jun 26, 2024

Yeah I believe the case sensitivity (which probably feels a little odd if standing next to the Docker image handled environment variables) is because the NC_blah ones are basically loaded straight into Nextcloud's config cache after stripping the NC_ prefix.

Glad to hear you got it working better for you!

Did you want me to create and provide some docs on this, or was it just to cross-reference the issues?

A bit of both. :-) So, yes, to your first question: if want to get the ball rolling that would really be helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature: auto config (environment variables) Auto configuring via environment variables needs review Needs confirmation this is still happening or relevant
Projects
None yet
Development

No branches or pull requests

4 participants