From 659ea7c3fb02dbfbccc145d4d271df39d1f23281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 20:53:11 +0200 Subject: [PATCH 01/15] feat: add cron to container --- Dockerfile | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 54c0e01..26fb371 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,13 +3,33 @@ FROM python:3.12-bookworm # Labels LABEL MAINTAINER="Jan-Ole Hübner " +# Install cron +RUN apt-get update && apt-get install -y cron + +# Add the requirements ADD requirements.txt / RUN pip3 install -r /requirements.txt # Environment ENV PYTHONIOENCODING=utf-8 + +# Add the application code ADD . / -# Chmod +# Add the cron job +RUN echo "*/15 * * * * python3 /get_price.py >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price + +# Give execution rights on the cron job +RUN chmod 0644 /etc/cron.d/get_price + +# Apply the cron job +RUN crontab /etc/cron.d/get_price + +# Create the log file to be able to run tail +RUN touch /var/log/cron.log + +# Chmod for your main application script RUN chmod 755 /pulse.py -CMD ["python3","/pulse.py"] \ No newline at end of file + +# Run the command on container startup +CMD cron && tail -f /var/log/cron.log From f889cc763c17ab29c76ed2beaaf56e06d494dae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 21:02:51 +0200 Subject: [PATCH 02/15] fix: pulse not running --- Dockerfile | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 26fb371..72e1dd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,33 +3,23 @@ FROM python:3.12-bookworm # Labels LABEL MAINTAINER="Jan-Ole Hübner " -# Install cron RUN apt-get update && apt-get install -y cron -# Add the requirements ADD requirements.txt / RUN pip3 install -r /requirements.txt -# Environment ENV PYTHONIOENCODING=utf-8 -# Add the application code ADD . / -# Add the cron job RUN echo "*/15 * * * * python3 /get_price.py >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price -# Give execution rights on the cron job RUN chmod 0644 /etc/cron.d/get_price -# Apply the cron job RUN crontab /etc/cron.d/get_price -# Create the log file to be able to run tail RUN touch /var/log/cron.log -# Chmod for your main application script RUN chmod 755 /pulse.py -# Run the command on container startup -CMD cron && tail -f /var/log/cron.log +CMD service cron start && python3 /pulse.py \ No newline at end of file From d89ae07f7b47ac91d1f0b53c70cf26b8adb763b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 21:30:24 +0200 Subject: [PATCH 03/15] add start.sh --- Dockerfile | 5 ++--- start.sh | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 start.sh diff --git a/Dockerfile b/Dockerfile index 72e1dd2..ff0a035 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ FROM python:3.12-bookworm -# Labels LABEL MAINTAINER="Jan-Ole Hübner " RUN apt-get update && apt-get install -y cron @@ -20,6 +19,6 @@ RUN crontab /etc/cron.d/get_price RUN touch /var/log/cron.log -RUN chmod 755 /pulse.py +RUN chmod 755 /pulse.py /start.sh -CMD service cron start && python3 /pulse.py \ No newline at end of file +CMD ["./start.sh"] diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..a7f6c90 --- /dev/null +++ b/start.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Start the cron service +service cron start + +# Run your main application script (pulse.py) in the background +python3 /pulse.py & + +# Keep the container running and output both cron logs and pulse.py output +tail -f /var/log/cron.log & +wait -n From f55ae08e94809ace7250f419bc34eefb9bda3160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 21:31:43 +0200 Subject: [PATCH 04/15] add . to cron path --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ff0a035..926b721 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ ENV PYTHONIOENCODING=utf-8 ADD . / -RUN echo "*/15 * * * * python3 /get_price.py >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price +RUN echo "*/15 * * * * python3 ./get_price.py >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price RUN chmod 0644 /etc/cron.d/get_price From 7ba82aa50925abcef6e3585916cd8bf70a0cd09d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 21:46:40 +0200 Subject: [PATCH 05/15] fix: wrong path --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 926b721..ff0a035 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ ENV PYTHONIOENCODING=utf-8 ADD . / -RUN echo "*/15 * * * * python3 ./get_price.py >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price +RUN echo "*/15 * * * * python3 /get_price.py >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price RUN chmod 0644 /etc/cron.d/get_price From 71a97b6726440df73ccc878fb169b60faff02a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 22:11:15 +0200 Subject: [PATCH 06/15] i hate my life --- Dockerfile | 4 ++-- delay_price.sh | 5 +++++ pulse.py | 7 +++---- 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 delay_price.sh diff --git a/Dockerfile b/Dockerfile index ff0a035..c9cfdac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ ENV PYTHONIOENCODING=utf-8 ADD . / -RUN echo "*/15 * * * * python3 /get_price.py >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price +RUN echo "*/2 * * * * /delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price RUN chmod 0644 /etc/cron.d/get_price @@ -19,6 +19,6 @@ RUN crontab /etc/cron.d/get_price RUN touch /var/log/cron.log -RUN chmod 755 /pulse.py /start.sh +RUN chmod 755 /pulse.py /get_price.py /start.sh /delay_price.sh CMD ["./start.sh"] diff --git a/delay_price.sh b/delay_price.sh new file mode 100644 index 0000000..f806c84 --- /dev/null +++ b/delay_price.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +sleep 2 + +python3 /get_price.py >> /var/log/cron.log 2>&1 \ No newline at end of file diff --git a/pulse.py b/pulse.py index 338a4a1..94d812e 100644 --- a/pulse.py +++ b/pulse.py @@ -1,8 +1,7 @@ -import asyncio + import os import signal import sys -import time import tibber from influxdb_client import InfluxDBClient @@ -25,7 +24,7 @@ ch.setFormatter(formatter) logger.addHandler(ch) logger.setLevel(logging.INFO) -__version__ = "v0.3.4" +__version__ = "v0.3.5_debug" logger.info(__version__) @@ -61,7 +60,7 @@ def stop(home): try: signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(15) - home.start_live_feed(user_agent="pulse.py/0.3.4",exit_condition=stop(home),retries=2,retry_interval=3.0) + home.start_live_feed(user_agent="pulse.py/0.3.5",exit_condition=stop(home),retries=2,retry_interval=3.0) except TypeError: logger.exception("Timeout occurred while executing start_live_feed()") client.close() From 1bfd251502de4c2a6ac72e4b034dbbd15bcfa411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 22:21:01 +0200 Subject: [PATCH 07/15] aaaaaah --- delay_price.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/delay_price.sh b/delay_price.sh index f806c84..89f1baa 100644 --- a/delay_price.sh +++ b/delay_price.sh @@ -1,5 +1,5 @@ #!/bin/bash - +export PYTHONPATH=/usr/local/lib/python3.12/site-packages sleep 2 -python3 /get_price.py >> /var/log/cron.log 2>&1 \ No newline at end of file +/usr/local/bin/python3 /get_price.py >> /var/log/cron.log 2>&1 \ No newline at end of file From 013d2e8ac7b049b71c601eb17eb4e0971619eb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 22:31:45 +0200 Subject: [PATCH 08/15] aaaaaah --- Dockerfile | 2 ++ delay_price.sh | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c9cfdac..1580bcc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,8 @@ ENV PYTHONIOENCODING=utf-8 ADD . / +RUN printenv > /env + RUN echo "*/2 * * * * /delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price RUN chmod 0644 /etc/cron.d/get_price diff --git a/delay_price.sh b/delay_price.sh index 89f1baa..723a14f 100644 --- a/delay_price.sh +++ b/delay_price.sh @@ -1,5 +1,5 @@ #!/bin/bash -export PYTHONPATH=/usr/local/lib/python3.12/site-packages +source /env sleep 2 -/usr/local/bin/python3 /get_price.py >> /var/log/cron.log 2>&1 \ No newline at end of file +python3 /get_price.py >> /var/log/cron.log 2>&1 \ No newline at end of file From c7583fa3ca244eb2b97fc9c360f4e3e8c257b056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 22:43:18 +0200 Subject: [PATCH 09/15] add app dir --- Dockerfile | 15 +++++++-------- delay_price.sh | 4 ++-- start.sh | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1580bcc..a566949 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,18 @@ -FROM python:3.12-bookworm - +FROM python:3.12-bookworm-slim +WORKDIR /app LABEL MAINTAINER="Jan-Ole Hübner " RUN apt-get update && apt-get install -y cron -ADD requirements.txt / +ADD requirements.txt /app RUN pip3 install -r /requirements.txt ENV PYTHONIOENCODING=utf-8 -ADD . / +ADD . /app -RUN printenv > /env -RUN echo "*/2 * * * * /delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price +RUN echo "*/2 * * * * /app/delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price RUN chmod 0644 /etc/cron.d/get_price @@ -21,6 +20,6 @@ RUN crontab /etc/cron.d/get_price RUN touch /var/log/cron.log -RUN chmod 755 /pulse.py /get_price.py /start.sh /delay_price.sh +RUN chmod 755 /app/pulse.py /app/get_price.py /app/start.sh /app/delay_price.sh -CMD ["./start.sh"] +CMD ["/app/start.sh"] diff --git a/delay_price.sh b/delay_price.sh index 723a14f..9f9fde7 100644 --- a/delay_price.sh +++ b/delay_price.sh @@ -1,5 +1,5 @@ #!/bin/bash -source /env +source /app/env sleep 2 -python3 /get_price.py >> /var/log/cron.log 2>&1 \ No newline at end of file +python3 /app/get_price.py >> /var/log/cron.log 2>&1 \ No newline at end of file diff --git a/start.sh b/start.sh index a7f6c90..6e0fa6c 100644 --- a/start.sh +++ b/start.sh @@ -1,5 +1,5 @@ #!/bin/bash - +printenv > /app/env # Start the cron service service cron start From ded79f992947e171d42f201582478ac47a7271ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 22:50:09 +0200 Subject: [PATCH 10/15] wrong image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a566949..fbdff45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12-bookworm-slim +FROM python:3.12-slim-bookworm WORKDIR /app LABEL MAINTAINER="Jan-Ole Hübner " From 36590b4f6235dd66cee6f971c3ee046d9e774704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 22:51:38 +0200 Subject: [PATCH 11/15] wrong image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fbdff45..1533db1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ LABEL MAINTAINER="Jan-Ole Hübner " RUN apt-get update && apt-get install -y cron ADD requirements.txt /app -RUN pip3 install -r /requirements.txt +RUN pip3 install -r /app/requirements.txt ENV PYTHONIOENCODING=utf-8 From 8127f0cb0816a38eb122507ba73dbc43691c37b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 22:55:07 +0200 Subject: [PATCH 12/15] wrong image --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index 6e0fa6c..6632127 100644 --- a/start.sh +++ b/start.sh @@ -4,7 +4,7 @@ printenv > /app/env service cron start # Run your main application script (pulse.py) in the background -python3 /pulse.py & +python3 /app/pulse.py & # Keep the container running and output both cron logs and pulse.py output tail -f /var/log/cron.log & From ad688fbaa54064bc23f6fee143e07000bba66897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 23:16:14 +0200 Subject: [PATCH 13/15] aaaaaaaaaa --- Dockerfile | 2 +- delay_price.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1533db1..586ed88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV PYTHONIOENCODING=utf-8 ADD . /app -RUN echo "*/2 * * * * /app/delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price +RUN echo -e "SHELL=/bin/bash\n* * * * * root /app/delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price RUN chmod 0644 /etc/cron.d/get_price diff --git a/delay_price.sh b/delay_price.sh index 9f9fde7..2515c71 100644 --- a/delay_price.sh +++ b/delay_price.sh @@ -1,5 +1,6 @@ #!/bin/bash source /app/env +printenv sleep 2 python3 /app/get_price.py >> /var/log/cron.log 2>&1 \ No newline at end of file From b9c33cea49ec24ba213b37eec847b0dd5b836672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 23:19:55 +0200 Subject: [PATCH 14/15] aaaaaaaaaa --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 586ed88..a5b6777 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV PYTHONIOENCODING=utf-8 ADD . /app -RUN echo -e "SHELL=/bin/bash\n* * * * * root /app/delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price +RUN echo "SHELL=/bin/bash\n* * * * * /app/delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price RUN chmod 0644 /etc/cron.d/get_price From c889c9f6def8a3dde3ce2a925b8338c021de4767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 23:29:43 +0200 Subject: [PATCH 15/15] aaaaaaaaaa --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a5b6777..dd424f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV PYTHONIOENCODING=utf-8 ADD . /app -RUN echo "SHELL=/bin/bash\n* * * * * /app/delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price +RUN echo "SHELL=/bin/bash\nBASH_ENV=/app/env\n* * * * * root /app/delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price RUN chmod 0644 /etc/cron.d/get_price