Skip to content

Commit da86713

Browse files
sepo83codingPF
andauthored
Add docker support for standalone database (#189)
* initial commit for docker supported standalone database * Rename dockerfile to Dockerfile * move init-script from docker volume to container startup; add RUN_ON_STARTUP * update README regarding RUN_ON_STARTUP * increase number of lines shown in Log * remove flags from mvupdate call * change default cron timespec * README: add recommendation how to disable binlog * change default cron timespec * Update Dockerfile added editor vi * Update README.md Align cron in sample docker run command Co-authored-by: codingPF <j-doo@gmx.de>
1 parent c4e83c6 commit da86713

3 files changed

Lines changed: 185 additions & 0 deletions

File tree

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM linuxserver/mariadb
2+
3+
# fill variables from linuxserver/mariadb with mediathekview default (https://docs.linuxserver.io/images/docker-mariadb)
4+
ENV MYSQL_DATABASE='mediathekview'
5+
ENV MYSQL_USER='mediathekview'
6+
ENV MYSQL_PASSWORD='mediathekview'
7+
ENV MYSQL_ROOT_PASSWORD='mediathekview_root'
8+
9+
# custom variables
10+
ENV CRON_TIMESPEC="0 4-22/1 * * *"
11+
ENV RUN_ON_STARTUP='no'
12+
13+
# install dependencies
14+
RUN apt update -y && \
15+
apt install python3-pip cron vim -y && \
16+
apt autoclean -y && \
17+
apt autoremove -y
18+
19+
RUN pip3 install mysql-connector-python
20+
21+
#cop mediathekview plugin
22+
WORKDIR /plugin.video.mediathekview
23+
ADD * ./
24+
ADD resources/ ./resources/
25+
26+
#add a script that configures and starts cronjob
27+
ADD docker/95_mediathekview_db /etc/cont-init.d/
28+
29+
#CMD and ENTRYPOINT are set by base image

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,63 @@ optional arguments:
200200
````
201201

202202

203+
Docker Container (mit interner MYSQL Datenbank)
204+
-----------------------------------------------
205+
Die Standalone Datenbank inkl. regelmäßiger Aktualisierung (Cronjob) über `mvupdate3` kann in einem Docker Container gehalten werden. Das Image basiert auf auf dem mariadb Container von linuxserver.io (siehe https://docs.linuxserver.io/images/docker-mariadb).
206+
207+
208+
**Container bauen:**
209+
210+
Zunächst muss das Repository als zip heruntergeladen und enpackt oder via git clone auf den Rechner mit installierten docker gebracht werden. Danach in das Verseichnis `plugin.video.mediathekview` gehen und das Container Image erstellen:
211+
212+
````
213+
docker build -t mediathekview-kodi-db .
214+
````
215+
216+
217+
**Container Konfiguration:**
218+
219+
| Umgebungsvariable | Standard Wert | Erklärung |
220+
| ----------------- | -------------- | --------------- |
221+
| PUID | 1000 | für UserID; siehe auch Erklärung auf linuxserver.io|
222+
| GUID | 1000 | für GroupID; siehe auch Erklärung auf linuxserver.io|
223+
| TZ | Europe/London | verwendete Zeitzone im Container |
224+
| MYSQL_DATABASE | mediathekview | Name der MYSQL Datenbank; diese Datenbank wird beim ersten Starten des Containers angelegt|
225+
| MYSQL_USER | mediathekview | Superuser-Benutzer der o.g. MYSQLS Datenbank|
226+
| MYSQL_PASSWORD | mediathekview | Passwort für MYSQL_USER (minimum 4 Zeichen); sollte in ein sicheres Passwort geändert werden |
227+
| MYSQL_ROOT_PASSWORD | mediathekview_root | Root Passwort für die MYSQL Datenbank (minimal 4 Zeichen); sollte in ein sicheres Passwort geändert werden|
228+
| CRON_TIMESPEC | 0 4-22/1 * * * | Zeitausdruck im Cron-Format, der angibt wann die Datenbank per `mvupdate3` aktualisiert werden soll (Default: zu jeder vollen Stunde zwischen 4 und 22 Uhr). Ein Generator für diese Ausdrücke findet sich bspw. hier: https://crontab.guru/|
229+
| RUN_ON_STARTUP | no | wenn 'yes', damm wird `mvupdate3` bei starten des Containers ausgeführt
230+
231+
232+
Um mit Kodi auf die Datenbank zugreifen zu können, muss der `Port 3306` nach außen geleitet werden. Bei mehereren Containern mit MYSQL Datenbank empfiehlt es sich den MYSQL-Port 3306 auf einen freien Port umzuleiten (z.B.: `-p 49153:3306`). *Achtung:* Innerhalb des Containers gilt weiterhin der Port 3306 (z.B. für den Aufruf von `mvupdate3`). Außerhalb bzw. in Kodi muss dann der konfigurierte Port (im Beispiel 49153) verwendet werden.
233+
234+
Die Datenbank selbst sowie weitere Konfigurationsdaten werden im Ordner `/config` gespeichert. Dieser ist als Docker-Volume konfiguriert (`-v path_to_data:/config`) und seine Daten bleiben auch beim Neuaufsetzen des Containers erhalten.
235+
236+
237+
**Container Starten (Beispielkonfiguration):**
238+
````
239+
docker run -d \
240+
--name mediathekview-kodi-db \
241+
-e PUID=1000 \
242+
-e GUID=1000 \
243+
-e TZ='Europe/Berlin' \
244+
-e MYSQL_DATABASE='mediathekview' \
245+
-e MYSQL_USER='mediathekview' \
246+
-e MYSQL_PASSWORD='mediathekview' \
247+
-e MYSQL_ROOT_PASSWORD='mediathekview_root' \
248+
-e CRON_TIMESPEC='0 4-22/1 * * *' \
249+
-p 3306:3306 \
250+
-v path_to_data:/config \
251+
mediathekview-kodi-db
252+
````
253+
254+
255+
**Hinweise:**
256+
* Die Log-Ausgabe von `mvupdate3` wird im Docker-Log teilweise erst nach Abschluss der Aktualisierung angezeigt.
257+
* Um Speicherplatz zu sparen kann das binlog der maria-db abgeschaltet werden. Dazu in `/config/custom.cnf` die Zeile `log_bin = /config/log/mysql/mariadb-bin` durch `skip-log-bin` ersetzen. Weitere Informationen zum Thema binlog gibt es [hier](https://mariadb.com/kb/en/binary-log/).
258+
259+
203260
English Version
204261
===============
205262

@@ -383,6 +440,65 @@ optional arguments:
383440

384441

385442

443+
Docker Container (with internal MYSQL database)
444+
-----------------------------------------------
445+
The standalone database inkl. regular update (cronjob) via `mvupdate3` can be run inside a docker container. The image is based on the mariadb container from linuxserver.io (see https://docs.linuxserver.io/images/docker-mariadb).
446+
447+
448+
**Build Container:**
449+
450+
Download the repository via zip (+ unpack) or git clone to the computer with installed docker. Then go to `plugin.video.mediathekview` and build the Image :
451+
452+
````
453+
docker build -t mediathekview-kodi-db .
454+
````
455+
456+
457+
**Container Configuration:**
458+
459+
| Env | Default Value | Function |
460+
| ----------------- | -------------- | --------------- |
461+
| PUID | 1000 | for UserID; also see explanation on linuxserver.io|
462+
| GUID | 1000 | for GroupID; also see explanation on linuxserver.io|
463+
| TZ | Europe/London | used timezone in the Container |
464+
| MYSQL_DATABASE | mediathekview | name of the MYSQL database; this database will be created during first startup of the Container|
465+
| MYSQL_USER | mediathekview | superuser of the MYSQL database|
466+
| MYSQL_PASSWORD | mediathekview | password for MYSQL_USER (minimum 4 characters); should be changed to a secure password |
467+
| MYSQL_ROOT_PASSWORD | mediathekview_root | root password for the MYSQL database (minimum 4 characters); should be changed to a secure password|
468+
| CRON_TIMESPEC | 0 4-22/1 * * * | time specification for cronjob; specifies when database is updated using `mvupdate3` (default: hourly between 4am and 10pm). A generator for cron time specification can be found for example here: https://crontab.guru/|
469+
| RUN_ON_STARTUP | no | if 'yes', `mvupdate3` will be executed on container startup
470+
471+
472+
473+
In order to access the database from outside the container (e.g. by Kodi addon) the `port 3306` has to be exposed. However, if using several MYSQL Containers this port should be forwarded to a free port (e.g. `-p 49153:3306`). *Remark:* Inside the container the usual port 3306 is used (e.g. when executing `mvupdate3`). Outside the container resp. in Kodi the configured port (49153 in the example) hast to be used.
474+
475+
The database itselve as well as other configuration data is stored in the folder `/config`. This folder is configured as docker volume (`-v path_to_data:/config`) and its content is persistent even if re-initialize the container.
476+
477+
478+
**Start the container (exemplaric):**
479+
````
480+
docker run -d \
481+
--name mediathekview-kodi-db \
482+
-e PUID=1000 \
483+
-e GUID=1000 \
484+
-e TZ='Europe/Berlin' \
485+
-e MYSQL_DATABASE='mediathekview' \
486+
-e MYSQL_USER='mediathekview' \
487+
-e MYSQL_PASSWORD='mediathekview' \
488+
-e MYSQL_ROOT_PASSWORD='mediathekview_root' \
489+
-e CRON_TIMESPEC='0 4-22/1 * * *' \
490+
-p 3306:3306 \
491+
-v path_to_data:/config \
492+
mediathekview-kodi-db
493+
````
494+
495+
496+
**Remarks:**
497+
* The log output of `mvupdate3` might be shown with a delay in the docker log.
498+
* In order to safe memory maria-db binlog can be disabled by editing `/config/custom.cnf`: Replace `log_bin = /config/log/mysql/mariadb-bin` with `skip-log-bin`. Further information about binlog can be found [here](https://mariadb.com/kb/en/binary-log/).
499+
500+
501+
386502
Versione Italiana
387503
=================
388504

docker/95_mediathekview_db

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
echo "[mediathekview_db] Export environment for use in crontab"
4+
declare -p | grep -Ev 'BASHOPTS|BASH_VERSINFO|EUID|PPID|SHELLOPTS|UID' > /container.env
5+
6+
CRON_CMD="python3 /plugin.video.mediathekview/mvupdate3 mysql -v -d $MYSQL_DATABASE -u $MYSQL_USER -p $MYSQL_PASSWORD"
7+
CRONTAB="$CRON_TIMESPEC $CRON_CMD"
8+
echo "[mediathekview_db] Install crontab: $CRONTAB"
9+
echo "SHELL=/bin/bash
10+
BASH_ENV=/container.env
11+
$CRONTAB > /tmp/stdout 2> /tmp/stderr
12+
# This extra line makes it a valid cron
13+
" | crontab -
14+
15+
echo "[mediathekview_db] Create custom stdout and stderr named pipes"
16+
if [ ! -p /tmp/stdout ]; then
17+
mkfifo /tmp/stdout
18+
chmod 0666 /tmp/stdout
19+
fi
20+
21+
if [ ! -p /tmp/stderr ]; then
22+
mkfifo /tmp/stderr
23+
chmod 0666 /tmp/stderr
24+
fi
25+
26+
# Have the main Docker process tail the files to produce stdout and stderr
27+
# for the main process that Docker will actually show in docker logs.
28+
tail -f -n 300 /tmp/stdout &
29+
tail -f -n 300 /tmp/stderr >&2 &
30+
31+
#run on startup, if configured
32+
if [ "$RUN_ON_STARTUP" = "yes" ]; then
33+
echo "[mediathekview_db] Schedule run on startup in 10s"
34+
sleep 10 && echo "[mediathekview_db] Run on startup: $CRON_CMD" && $CRON_CMD &
35+
else
36+
echo "[mediathekview_db] Do not run on startup"
37+
fi
38+
39+
echo "[mediathekview_db] Start cron"
40+
/usr/sbin/cron -f -L 1 &

0 commit comments

Comments
 (0)