diff --git a/Dockerfile b/Dockerfile index e1c53a83..d6f89cd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM debian:buster-slim # default UID and GID -ENV USER=pi USER_ID=1000 USER_GID=1000 +ENV USER=pi USER_ID=1000 USER_GID=1000 TZ=Europe/London PORT=20211 # Todo, figure out why using a workdir instead of full paths don't work # Todo, do we still need all these packages? I can already see sudo which isn't needed @@ -28,12 +28,11 @@ RUN groupadd --gid "${USER_GID}" "${USER}" && \ COPY . /home/pi/pialert # Pi.Alert -RUN python /home/pi/pialert/back/pialert.py update_vendors \ - && sed -ie 's/= 80/= 20211/g' /etc/lighttpd/lighttpd.conf \ +RUN sed -ie "s|TIMEZONE|${TZ}|g" /home/pi/pialert/install/pialert.cron \ + && python /home/pi/pialert/back/pialert.py update_vendors \ + && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - -EXPOSE 20211 - # it's easy for permissions set in Git to be overridden, so doing it manually RUN chmod -R a+rxw /home/pi/pialert/ diff --git a/docker-compose.yml b/docker-compose.yml index 81157c91..f629723b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3" services: pialert: build: . - container_name: pialert_dev + container_name: pialert network_mode: "host" restart: always volumes: @@ -10,6 +10,7 @@ services: - ${APP_DATA_LOCATION}/pialert/db/pialert.db:/home/pi/pialert/db/pialert.db - ${LOGS_LOCATION}/tmp:/home/pi/pialert/log environment: - - TZ=France/Paris - - HOST_USER_ID=1036 + - TZ=Europe/London + - PORT=20211 + - HOST_USER_ID=1000 - HOST_USER_GID=1000 diff --git a/dockerfiles/README.md b/dockerfiles/README.md index df0886d4..b6acbfe6 100644 --- a/dockerfiles/README.md +++ b/dockerfiles/README.md @@ -15,8 +15,8 @@ The source :page_facing_up: Dockerfile is available [here](https://github.com/jo Network - You will have to probably run the container on the host network, e.g: `sudo docker run --rm --net=host jokobsk/pi.alert` -Port - - The container runs on the port `:20211`. +Default Port + - The app is accessible on the port `:20211`. > Please note - the cronjob is executed every 1, 5 and 15 minutes so wait that long for all of the scans to run. @@ -34,6 +34,7 @@ Port * Automated copy The docker image copies the DB once every 30 min to `/home/pi/pialert/config/pialert.db_bak`. If you have a backup already available, make sure you rename this file if you want to keep older backups before starting a new container. To restore the DB run: `cp /home/pi/pialert/config/pialert.db_bak /home/pi/pialert/db/pialert.db` 6. The container supports mapping to local User nad Group IDs. Specify the enviroment variables `HOST_USER_ID` and `HOST_USER_GID` if needed. +7. You can override the port by specifying the `PORT` env variable. Config examples can be found below. @@ -56,8 +57,9 @@ services: - ${APP_DATA_LOCATION}/pialert/db/pialert.db:/home/pi/pialert/db/pialert.db - ${LOGS_LOCATION}/:/home/pi/pialert/log environment: - - TZ=France/Paris - - HOST_USER_ID=1036 + - TZ=Europe/London + - PORT=20211 + - HOST_USER_ID=1000 - HOST_USER_GID=1000 ``` diff --git a/dockerfiles/start.sh b/dockerfiles/start.sh index 01d1674e..3ab58572 100755 --- a/dockerfiles/start.sh +++ b/dockerfiles/start.sh @@ -1,8 +1,14 @@ #!/bin/sh /home/pi/pialert/dockerfiles/user-mapping.sh +# if custom variables not set we do not need to do anything +if [ -n "${TZ}" ]; then + sed -ie "s|Europe/London|${TZ}|g" /home/pi/pialert/install/pialert.cron + crontab < /home/pi/pialert/install/pialert.cron +fi +if [ -n "${PORT}" ]; then + sed -ie 's/= 20211/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf +fi -#chmod -R 755 /var/www/html/pialert -#chmod -R o+w /home/pi/pialert/db /etc/init.d/lighttpd start cron -f diff --git a/install/pialert.cron b/install/pialert.cron index ccf434d5..9c479ee3 100644 --- a/install/pialert.cron +++ b/install/pialert.cron @@ -7,8 +7,10 @@ # Puche 2021 pi.alert.application@gmail.com GNU GPLv3 #------------------------------------------------------------------------------- -0 3 * * 1 python /home/pi/pialert/back/pialert.py update_vendors >/home/pi/pialert/log/pialert.vendors.log 2>&1 -*/1 * * * * python /home/pi/pialert/back/pialert.py internet_IP >/home/pi/pialert/log/pialert.IP.log 2>&1 -*/5 * * * * python /home/pi/pialert/back/pialert.py 1 >/home/pi/pialert/log/pialert.1.log 2>&1 -*/15 * * * * python /home/pi/pialert/back/pialert.py 15 >/home/pi/pialert/log/pialert.15.log 2>&1 -*/30 * * * * cp /home/pi/pialert/db/pialert.db /home/pi/pialert/config/pialert.db_bak +TZ=TIMEZONE + +0 3 * * 1 python /home/pi/pialert/back/pialert.py update_vendors >/home/pi/pialert/log/pialert.vendors.log 2>&1 +*/1 * * * * python /home/pi/pialert/back/pialert.py internet_IP >/home/pi/pialert/log/pialert.IP.log 2>&1 +*/5 * * * * python /home/pi/pialert/back/pialert.py 1 >/home/pi/pialert/log/pialert.1.log 2>&1 +*/15 * * * * python /home/pi/pialert/back/pialert.py 15 >/home/pi/pialert/log/pialert.15.log 2>&1 +*/30 * * * * cp /home/pi/pialert/db/pialert.db /home/pi/pialert/config/pialert.db_bak