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

Added entrypoint hooks for your own custom scripts #1964

Merged
merged 7 commits into from
Jun 22, 2023

Conversation

dvaerum
Copy link
Contributor

@dvaerum dvaerum commented Apr 4, 2023

I what looking around to see if there was anyway to execute custom script(s) when Nextcloud is installed/initiated the first time or whenever it is upgraded.

Sadly, this feature doesn't exist, but I can see there has been talked about it in #820 (comment), and I can also see that there are 2 pull requests for adding an environment variable tell the container to install extra apps doing Nextcloud installation/initialization.

This entrypoint hooks for custom scripts would allow for people to easily add these features themselves, plus other features like "add support for oauth in docker image" (#1023)

I am open for feedback because I think this would give a lot of flexibility with the Nextcloud container 😁

@dvaerum dvaerum force-pushed the master branch 3 times, most recently from a9ca8bc to 4fd6e70 Compare May 12, 2023 17:29
@dvaerum dvaerum requested a review from J0WI May 12, 2023 17:36
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
docker-entrypoint.sh Outdated Show resolved Hide resolved
@J0WI
Copy link
Contributor

J0WI commented Jun 13, 2023

/rebase

dvaerum and others added 6 commits June 13, 2023 15:41
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
- Only execute shell-scripts (mening files ending with .sh)
- Sort the files before executing them, had forgotten 😅
- Added a message when a hook script finish
- Added prefix arror to message to show the are related

Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
Co-authored-by: J0WI <J0WI@users.noreply.github.com>
Signed-off-by: Dennis Værum <6872940+dvaerum@users.noreply.github.com>
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
@J0WI
Copy link
Contributor

J0WI commented Jun 13, 2023

The build fails: sh: 1: /docker-entrypoint-hooks.d/pre-installation/*.sh: not found

@dvaerum
Copy link
Contributor Author

dvaerum commented Jun 14, 2023

The build fails: sh: 1: /docker-entrypoint-hooks.d/pre-installation/*.sh: not found

aaahhh, that is true, I forgot that this can be a problem. If there are no files in the folder for filling the glob-criteria (*.sh) one gets this error, one reasons to use find.

but, I will add something like this to test if the folder is empty, when I get home from work or one of their days 😁

[ -z "$(ls -A test_folder)" ] && echo "Empty" || echo "Not Empty"

…as empty

Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
@dvaerum
Copy link
Contributor Author

dvaerum commented Jun 14, 2023

Hey @J0WI, I have fixed the bug, hopefully there are no more stupid mistake 😅 will you approve the workflow? 😁

@J0WI J0WI merged commit d325146 into nextcloud:master Jun 22, 2023
@J0WI
Copy link
Contributor

J0WI commented Jun 22, 2023

Thanks!

@Nils98Ar
Copy link

Thank you for this feature!

The log says:
==> The script "/docker-entrypoint-hooks.d/post-installation/bootstrap.sh" in the folder "/docker-entrypoint-hooks.d/post-installation" was skipping, because it didn't have the executable flag

I have this in my Dockerfile:

COPY ./docker-entrypoint-hooks.d/post-installation/bootstrap.sh /docker-entrypoint-hooks.d/post-installation
RUN chmod +x /docker-entrypoint-hooks.d/post-installation/bootstrap.sh && chown www-data:root /docker-entrypoint-hooks.d/post-installation/bootstrap.sh

Any idea?

@dvaerum
Copy link
Contributor Author

dvaerum commented Jul 14, 2023

Thank you for this feature!

The log says: ==> The script "/docker-entrypoint-hooks.d/post-installation/bootstrap.sh" in the folder "/docker-entrypoint-hooks.d/post-installation" was skipping, because it didn't have the executable flag

I have this in my Dockerfile:

COPY ./docker-entrypoint-hooks.d/post-installation/bootstrap.sh /docker-entrypoint-hooks.d/post-installation
RUN chmod +x /docker-entrypoint-hooks.d/post-installation/bootstrap.sh && chown www-data:root /docker-entrypoint-hooks.d/post-installation/bootstrap.sh

Any idea?

🤯 that is a good question 🤔 From what I can see, what you do should work.

If you make a zip-file with your environment and the commands you run, I will debug it 🙂 because if you have found a bug I want to fix it

@Nils98Ar
Copy link

Beginners mistake: I had imagePullPolicy: IfNotPresent configured for the container in K8S 🙂

This works as well:
COPY --chmod=775 --chown=www-data:root ./docker-entrypoint-hooks.d/post-installation/bootstrap.sh /docker-entrypoint-hooks.d/post-installation.

@dvaerum
Copy link
Contributor Author

dvaerum commented Jul 14, 2023

Beginners mistake: I had imagePullPolicy: IfNotPresent configured for the container in K8S slightly_smiling_face

This works as well: COPY --chmod=775 --chown=www-data:root ./docker-entrypoint-hooks.d/post-installation/bootstrap.sh /docker-entrypoint-hooks.d/post-installation.

Awesome, happy to hear that you solved the problem :D. Furthermore, just for reference, you don't have to change the ownership as long that anyone can execute the file 😉

AkashiSN added a commit to AkashiSN/nextcloud-docker that referenced this pull request Jul 26, 2023
AkashiSN added a commit to AkashiSN/nextcloud-docker that referenced this pull request Jul 26, 2023
Signed-off-by: AkashiSN <btorntireinvynriy@gmail.com>
@CheariX
Copy link

CheariX commented Jul 31, 2023

I'm trying to add some packages (inotify-tools) to my installation. Since I do not want to built my own Docker image, i thought it would be a good idea to put the apt install code into the /docker-entrypoint-hooks.d/before-starting folder.

However, this is not working:

nextcloud_web  | E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
nextcloud_web  | E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

It seems that the scripts are executed with the www-data user since I am using the docker-compose.yml from this repository with the Apache setup.
Can anyone point me to how this is supposed to work? The README.md is only providing very rough information on this.

@dvaerum
Copy link
Contributor Author

dvaerum commented Aug 3, 2023

First of, this was never meant to solve the problem of installing missing packages, this was meant to configure Nextcloud by running commands commands like php occ app:install <APP> and yes the scripts in /docker-entrypoint-hooks.d/before-starting are being executed as the www-data user.

In my opinion you should make a new image, I don’t know how you start your image, but it is pretty straightforward to make small adjustments to the image using docker-compose.

But, if you want to make the changes/Install the package when the container start, you can change the entrypoint, to be something like this apt update && apt install —yes <package> && /entrypoint.sh. That would give you a root shell to install your package(s).

Hopes this helps/point you in the right direction.

Also, what documentation are you missing? because I can try to add it, if you have something specific 😁

@CheariX
Copy link

CheariX commented Aug 18, 2023

Thanks for the clarification. Your idea with the entryhooks works great for me.
Just for the record, the docker-compose.yml entry is:

entrypoint: ["/bin/bash", "-c" , "apt-get update && apt-get install curl -y && /entrypoint.sh apache2-foreground"]

ananace pushed a commit to ananace/docker-nextcloud that referenced this pull request May 10, 2024
* Added entrypoint hooks for your own custom scripts

Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>

* Small changes:
- Only execute shell-scripts (mening files ending with .sh)
- Sort the files before executing them, had forgotten 😅
- Added a message when a hook script finish
- Added prefix arror to message to show the are related

Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>

* Show in the search msg that it only searches for '*.sh' files

Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>

* Fixed spelling mistake

Co-authored-by: J0WI <J0WI@users.noreply.github.com>
Signed-off-by: Dennis Værum <6872940+dvaerum@users.noreply.github.com>

* Updated the `README.md` file

Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>

* change from using find to using a for-loop to located the `.sh` files

Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>

* Fix bug - that would make docker-entrypoint.sh failed, hook folders was empty

Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>

---------

Signed-off-by: Dennis Vestergaard Værum <github@varum.dk>
Signed-off-by: Dennis Værum <6872940+dvaerum@users.noreply.github.com>
Co-authored-by: J0WI <J0WI@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants