1
0
Fork 0
mirror of https://github.com/imtbl/hydrus-server-docker synced 2024-05-17 19:13:42 +12:00

Merge branch 'feature/docker-user-handling' into develop

This commit is contained in:
Michael Serajnik 2020-01-05 21:11:39 +01:00
commit 38fc5b2995
No known key found for this signature in database
GPG key ID: B390A5CBA3ECB74D
5 changed files with 51 additions and 46 deletions

View file

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased] ## [Unreleased]
### Added
+ Added the ability to define custom UID and GID for the Docker container at
container creation
## [3.21.0] - 2020-01-02 ## [3.21.0] - 2020-01-02
### Changed ### Changed

View file

@ -1,35 +1,20 @@
FROM python:3.8-slim-buster FROM python:3.8-slim-buster
ARG HOST_USER_ID=1000
ARG HOST_GROUP_ID=1000
ENV HOST_USER_ID=$HOST_USER_ID
ENV HOST_GROUP_ID=$HOST_GROUP_ID
RUN \
if [ $(getent group ${HOST_GROUP_ID}) ]; then \
useradd -r -u ${HOST_USER_ID} hydrus; \
else \
groupadd -g ${HOST_GROUP_ID} hydrus && \
useradd -r -u ${HOST_USER_ID} -g hydrus hydrus; \
fi
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY ./hydrus . COPY ./hydrus .
COPY ./deb . COPY ./deb .
RUN \ RUN \
chown -R hydrus:hydrus /usr/src/app && \
chmod +x \ chmod +x \
server.py \ server.py \
bin/swfrender_linux \ bin/swfrender_linux \
bin/upnpc_linux && \ bin/upnpc_linux && \
mkdir /data && \ mkdir /data && \
chown -R hydrus:hydrus /data && \
apt-get update && apt-get install --no-install-recommends -y \ apt-get update && apt-get install --no-install-recommends -y \
build-essential \ build-essential \
ffmpeg \ ffmpeg \
gosu \
multiarch-support \ multiarch-support \
wget && \ wget && \
dpkg -i libjpeg8_8d-2_amd64.deb && \ dpkg -i libjpeg8_8d-2_amd64.deb && \
@ -59,7 +44,10 @@ RUN \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint COPY docker-start.sh /usr/local/bin/docker-start
RUN \
chmod +x /usr/local/bin/docker-entrypoint && \
chmod +x /usr/local/bin/docker-start
EXPOSE 45870/tcp 45871/tcp 45872/tcp EXPOSE 45870/tcp 45871/tcp 45872/tcp
@ -69,6 +57,5 @@ HEALTHCHECK --interval=1m --timeout=10s --retries=3 \
VOLUME /data VOLUME /data
USER hydrus
ENTRYPOINT ["docker-entrypoint"] ENTRYPOINT ["docker-entrypoint"]
CMD ["docker-start"]

View file

@ -15,8 +15,9 @@ The latest build runs [hydrus server version 379][hydrus-server-version].
+ [Upgrading from 2.x to 3.x](#upgrading-from-2x-to-3x) + [Upgrading from 2.x to 3.x](#upgrading-from-2x-to-3x)
+ [Upgrading from 1.x to 2.x](#upgrading-from-1x-to-2x) + [Upgrading from 1.x to 2.x](#upgrading-from-1x-to-2x)
+ [Usage](#usage) + [Usage](#usage)
+ [Additional configuration when building](#additional-configuration-when-building) + [Ports](#ports)
+ [UID/GID](#uidgid) + [Storage](#storage)
+ [UID/GID](#uidgid)
+ [Donate](#donate) + [Donate](#donate)
+ [Maintainer](#maintainer) + [Maintainer](#maintainer)
+ [Contribute](#contribute) + [Contribute](#contribute)
@ -87,6 +88,8 @@ making it easier to adapt for future changes/dependencies.
## Usage ## Usage
### Ports
First, you need to bind the exposed ports. This can be done automatically First, you need to bind the exposed ports. This can be done automatically
using `-P` but it is recommended to bind them manually instead since having using `-P` but it is recommended to bind them manually instead since having
changing ports every time you run a new container might be annoying when used changing ports every time you run a new container might be annoying when used
@ -103,6 +106,8 @@ for the server administration service while `45871` and `45872` are used for
repositories. You will generally have two (one for tags and one for files), but repositories. You will generally have two (one for tags and one for files), but
if you add more, you will also need to expose additional ports. if you add more, you will also need to expose additional ports.
### Storage
Per default, hydrus-server-docker stores its databases and media inside the Per default, hydrus-server-docker stores its databases and media inside the
`/data` directory which is a mount point that is persisted as a volume. A new `/data` directory which is a mount point that is persisted as a volume. A new
volume will be created every time a container is created, making it less ideal volume will be created every time a container is created, making it less ideal
@ -113,11 +118,22 @@ mount that over it:
user@local:~$ docker volume create hydrus-server-data user@local:~$ docker volume create hydrus-server-data
``` ```
After creating your named volume, you can run the container. Here is a full ### UID/GID
example with all the options mentioned above:
The user that owns the data and runs the server inside the container has the
UID `1000` and the GID `1000` by default. You can change these by providing the
environment variables `CUSTOM_UID` and `CUSTOM_GID` when creating a container.
This is useful if you want to access the data outside the container with a user
with different IDs without hassle. In such a case, `CUSTOM_UID` and
`CUSTOM_GID` should match the user that is going to access the data on the
host.
Here is a full example for running the container with all the options mentioned
above:
```zsh ```zsh
user@local:~$ docker run -p 45870:45870 -p 45871:45871 -p 45872:45872 -v hydrus-server-data:/data -d mserajnik/hydrus-server-docker user@local:~$ docker run -p 45870:45870 -p 45871:45871 -p 45872:45872 -v hydrus-server-data:/data -e CUSTOM_UID=1000 -e CUSTOM_GID=1000 -d mserajnik/hydrus-server-docker
``` ```
Specifying the same named volume every time a container is created gives each Specifying the same named volume every time a container is created gives each
@ -127,19 +143,6 @@ Of course, using a bind mount instead of a named volume is also possible but
for performance reasons only recommended if you need easy access to the data on for performance reasons only recommended if you need easy access to the data on
the host machine. the host machine.
### Additional configuration when building
#### UID/GID
By default, the user that owns the data and runs the server inside the
container has the UID `1000` and the GID `1000`. You can make a build providing
the arguments `HOST_USER_ID` and `HOST_GROUP_ID` to change these defaults.
This is useful if you want to access the data outside the container with a user
with different ID's without hassle. In such a case, `HOST_USER_ID` and
`HOST_GROUP_ID` should match the user that is going to access the data on the
host.
## Donate ## Donate
If you like hydrus-server-docker and want to buy me a coffee, feel free to If you like hydrus-server-docker and want to buy me a coffee, feel free to

View file

@ -1,13 +1,10 @@
#!/bin/bash #!/bin/bash
. venv/bin/activate USER_ID=${CUSTOM_UID:-1000}
GROUP_ID=${CUSTOM_GID:-1000}
stop() { echo "Setting permissions to UID/GID ${USER_ID}/${GROUP_ID}."
./server.py stop -d="/data" chown ${USER_ID}:${GROUP_ID} -R /usr/src/app
} chown ${USER_ID}:${GROUP_ID} -R /data
trap "stop" SIGTERM exec gosu ${USER_ID}:${GROUP_ID} "$@"
./server.py -d="/data" &
wait $!

13
docker-start.sh Normal file
View file

@ -0,0 +1,13 @@
#!/bin/bash
. venv/bin/activate
stop() {
./server.py stop -d="/data"
}
trap "stop" SIGTERM
./server.py -d="/data" &
wait $!