Skip to content

Commit

Permalink
Enable custom settings.ini for Docker containers
Browse files Browse the repository at this point in the history
Fixes #73
  • Loading branch information
reconman committed Nov 20, 2021
1 parent c02cd1b commit d62df4b
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 48 deletions.
27 changes: 20 additions & 7 deletions Docker/PlexAniSync/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@ ENV PLEX_SECTION=Anime \
ANI_USERNAME='' \
ANI_TOKEN='' \
INTERVAL=3600 \
PATH="${PATH}:~/.local/bin"
SETTINGS_FILE=''

ADD ./* /plexanisync/
ADD Docker/PlexAniSync/run/* /plexanisync/
ENV PATH="${PATH}:~/.local/bin"

RUN cd /plexanisync && \
python3 -m pip install -r requirements.txt && \
cd ..
# run this before copying requirements for cache efficiency
RUN pip install --upgrade pip

#set work directory early so remaining paths can be relative
WORKDIR /plexanisync

# Adding requirements file to current directory
# just this file first to cache the pip install step when code changes
# Use copy since we are not getting anything from remote or URL
COPY requirements.txt .
COPY Docker/PlexAniSync/run/. .

# Install dependencies
RUN python3 -m pip install -r requirements.txt

# copy code itself from context to image
COPY . .

LABEL org.opencontainers.image.documentation=https://github.com/RickDB/PlexAniSync/blob/master/Docker/PlexAniSync/README.md

CMD ["/plexanisync/runsync.sh"]
CMD ["/plexanisync/runsync.sh"]
37 changes: 24 additions & 13 deletions Docker/PlexAniSync/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Docker-PlexAniSync
![Docker](https://github.com/rickdb/PlexAniSync/actions/workflows/docker-publish-plexanisync.yml/badge.svg)

## Usage

### docker
### Docker Run

```
docker run -d \
Expand All @@ -21,17 +20,18 @@ docker run -d \

### Environment Variables

| ID | Default | Required | Note |
| --------------------------- | ------------------------ | :------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| PLEX_SECTION | Anime | ✓ | The library where your anime resides |
| PLEX_URL | http://127.0.0.1:32400 | ✓ | The address to your Plex Media Server, for example: http://127.0.0.1:32400 |
| PLEX_TOKEN | - | ✓ | Follow [this guide](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/) |
| ANI_USERNAME | - | ✓ | Your [AniList.co](http://www.anilist.co) username |
| ANI_TOKEN | - | ✓ | Get it [here](https://anilist.co/api/v2/oauth/authorize?client_id=1549&response_type=token) |
| INTERVAL | 3600 | ✕ | The time in between syncs |
| PLEX_EPISODE_COUNT_PRIORITY | - | ✕ | If set to True, Plex episode watched count will take priority over AniList (default = False) |
| SKIP_LIST_UPDATE | - | ✕ | If set to True, it will NOT update your AniList which is useful if you want to do a test run to check if everything lines up properly. (default = False) |
| LOG_FAILED_MATCHES | - | ✕ | If set to True, failed matches will be written to /plexanisync/failed_matches.txt (default = False) |
| ID | Default | Required | Note |
| --------------------------- | ---------------------- | :-------: | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| PLEX_SECTION | Anime | ✓* | The library where your anime resides |
| PLEX_URL | http://127.0.0.1:32400 | ✓* | The address to your Plex Media Server, for example: http://127.0.0.1:32400 |
| PLEX_TOKEN | - | ✓* | Follow [this guide](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/) |
| ANI_USERNAME | - | ✓* | Your [AniList.co](http://www.anilist.co) username |
| ANI_TOKEN | - | ✓* | Get it [here](https://anilist.co/api/v2/oauth/authorize?client_id=1549&response_type=token) |
| PLEX_EPISODE_COUNT_PRIORITY | - | ✕ | If set to True, Plex episode watched count will take priority over AniList (default = False) |
| SKIP_LIST_UPDATE | - | ✕ | If set to True, it will NOT update your AniList which is useful if you want to do a test run to check if everything lines up properly. (default = False) |
| LOG_FAILED_MATCHES | - | ✕ | If set to True, failed matches will be written to /plexanisync/failed_matches.txt (default = False) |
| SETTINGS_FILE | - | ✕ | Location of a custom settings.ini for more advanced configuration. Makes all settings above obsolete. See section below for usage. |
| INTERVAL | 3600 | ✕ | The time in between syncs in seconds |

### Custom mappings

Expand All @@ -42,3 +42,14 @@ In order to provide a [custom_mappings.yaml file](https://github.com/RickDB/Plex
```

You can modify the file on the host system anytime and it will be used during the next run. Restarting the container is not necessary.

### Custom settings.ini

If you want to use other Plex login mechanisms, you can use your own settings.ini file by mapping it into the container and setting the environment variable `SETTINGS_FILE` with the path to the file inside the container.

If the settings file is located at `/docker/plexanisync/settings.ini` and you want to place it to `/config/settings.ini`, use the following volume mapping and environment variable:

```
-v '/docker/plexanisync/settings.ini:/config/settings.ini:ro'
-e 'SETTINGS_FILE=/config/settings.ini'
```
27 changes: 20 additions & 7 deletions Docker/PlexAniSync/run/runsync.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#!/bin/sh
echo "Updating settings.ini"
python /plexanisync/settingsupdater.py
run() {
while true
do
(cd /plexanisync && python PlexAniSync.py)
sleep ${INTERVAL}
done
}

####
# Main body of script
###

if [[ -z "${SETTINGS_FILE}" ]]; then
echo "Updating settings.ini"
python /plexanisync/settingsupdater.py
run
else
echo "Using custom config: "${SETTINGS_FILE}
run
fi

while true
do
(cd /plexanisync && python PlexAniSync.py)
sleep ${INTERVAL}
done
30 changes: 21 additions & 9 deletions Docker/Tautulli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
FROM tautulli/tautulli

RUN apt-get update && \
apt-get install -y build-essential

ENV PLEX_SECTION=Anime \
PLEX_URL=http://127.0.0.1:32400 \
PLEX_TOKEN='' \
ANI_USERNAME='' \
ANI_TOKEN=''
ANI_TOKEN='' \
SETTINGS_FILE=''

ADD ./* /plexanisync/
# run this before copying requirements for cache efficiency
RUN pip install --upgrade pip

RUN apt-get update && \
apt-get install -y build-essential && \
cd /plexanisync && \
python -m pip install -r requirements.txt && \
cd ..
#set work directory early so remaining paths can be relative
WORKDIR /plexanisync

# Adding requirements file to current directory
# just this file first to cache the pip install step when code changes
# Use copy since we are not getting anything from remote or URL
COPY requirements.txt .
COPY Docker/Tautulli/run/start.sh /app/
COPY Docker/Tautulli/run/settingsupdater.py /plexanisync/

# Install dependencies
RUN python3 -m pip install -r requirements.txt

COPY ./* /plexanisync/

LABEL autoheal=true
LABEL org.opencontainers.image.documentation=https://github.com/RickDB/PlexAniSync/blob/master/Docker/Tautulli/README.md

COPY Docker/Tautulli/run/start.sh /app/
COPY Docker/Tautulli/run/settingsupdater.py /plexanisync/
9 changes: 2 additions & 7 deletions Docker/Tautulli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

A combination of [Tautulli](https://github.com/Tautulli/Tautulli) and PlexAniSync.

<div>

![Docker](https://github.com/rickdb/PlexAniSync/actions/workflows/docker-publish-tautulli.yml/badge.svg)

</div>

## Usage

### Docker Command
Expand All @@ -33,6 +27,7 @@ docker run -d \
Since this is a combination of docker images, environment variables of both images have to be configured.

See:

- [Tautulli](https://github.com/Tautulli/Tautulli-Wiki/wiki/Installation#docker)
- [PlexAniSync](https://github.com/RickDB/PlexAniSync/Docker/PlexAniSync/README.md#environment-variables)

Expand All @@ -44,4 +39,4 @@ If you have never configured Tautulli, a setup guide will ask you to set up the

Once the guide is done, follow the instructions [here](https://github.com/RickDB/PlexAniSync/wiki/Tautulli-sync-script) to set up the PlexAniSync notification agent.

Use `/plexanisync` as script folder. Do NOT rename TautulliSyncHelper.py to .pyw, otherwise Tautulli won't be able to start it.
Use `/plexanisync` as script folder. Do NOT rename TautulliSyncHelper.py to .pyw, otherwise Tautulli won't be able to start it.
6 changes: 4 additions & 2 deletions Docker/Tautulli/run/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ usermod -o -u "$PUID" tautulli
chown -R tautulli:tautulli /config
chown -R tautulli:tautulli /plexanisync

echo "Updating settings.ini"
gosu tautulli "python" "/plexanisync/settingsupdater.py"
if [[ -z "${SETTINGS_FILE}" ]]; then
echo "Updating settings.ini"
gosu tautulli "python" "/plexanisync/settingsupdater.py"
fi

echo "Running Tautulli using user tautulli (uid=$(id -u tautulli)) and group tautulli (gid=$(id -g tautulli))"
exec gosu tautulli "$@"
4 changes: 2 additions & 2 deletions PlexAniSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def read_settings(settings_file) -> configparser.ConfigParser:
return settings


SETTINGS_FILE = os.getenv("SETTINGS_FILE", "settings.ini")

if len(sys.argv) > 1:
SETTINGS_FILE = sys.argv[1]
logger.warning(f"Found settings file parameter and using: {SETTINGS_FILE}")
else:
SETTINGS_FILE = "settings.ini"

settings = read_settings(SETTINGS_FILE)
anilist_settings = settings["ANILIST"]
Expand Down
3 changes: 2 additions & 1 deletion TautulliSyncHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def read_settings(settings_file) -> configparser.ConfigParser:
return settings


SETTINGS_FILE = os.getenv("SETTINGS_FILE", "settings.ini")

if len(sys.argv) < 2:
logger.error("No show title specified in arguments so cancelling updating")
sys.exit(1)
Expand All @@ -44,7 +46,6 @@ def read_settings(settings_file) -> configparser.ConfigParser:
# keep legacy method intact
show_title = sys.argv[2]
else:
SETTINGS_FILE = "settings.ini"
show_title = sys.argv[1]

settings = read_settings(SETTINGS_FILE)
Expand Down
1 change: 1 addition & 0 deletions custom-mappings
Submodule custom-mappings added at 3acef0

0 comments on commit d62df4b

Please sign in to comment.