From ef94550b64620f2507584d56620598aef635c9ae Mon Sep 17 00:00:00 2001 From: stratholme Date: Fri, 14 Aug 2020 23:48:12 +0200 Subject: [PATCH] Forward environment to cron via crontab file --- Dockerfile | 8 +++----- files/{crontab => crontab.tpl} | 0 files/entrypoint.sh | 14 ++++++++++++++ files/main.py | 5 +++-- 4 files changed, 20 insertions(+), 7 deletions(-) rename files/{crontab => crontab.tpl} (100%) create mode 100755 files/entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 8c23cbb..fbde88e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,7 @@ RUN \ apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ADD files/main.py /main.py +ADD files/entrypoint.sh /entrypoint.sh +ADD files/crontab.tpl /crontab.tpl -ADD files/crontab /etc/cron.d/assembly-cron -RUN chmod 0644 /etc/cron.d/assembly-cron -RUN crontab /etc/cron.d/assembly-cron - -CMD ["cron", "-f"] +ENTRYPOINT ["/entrypoint.sh"] diff --git a/files/crontab b/files/crontab.tpl similarity index 100% rename from files/crontab rename to files/crontab.tpl diff --git a/files/entrypoint.sh b/files/entrypoint.sh new file mode 100755 index 0000000..19bac2b --- /dev/null +++ b/files/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Create crontab with current environment variables +( + printenv + echo + cat /crontab.tpl +) > /etc/cron.d/assembly-cron + +# Install crontab +crontab /etc/cron.d/assembly-cron + +# Run cron daemon +exec cron -f diff --git a/files/main.py b/files/main.py index 7847ba1..b232c2b 100755 --- a/files/main.py +++ b/files/main.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# vim: sw=2:ts=2:noet # -*- coding: utf-8 -*- # #### Assemble the Undead ##### @@ -55,8 +56,8 @@ smtp_from = os.getenv('SMTP_FROM') smtp_user = os.getenv('SMTP_USER') smtp_password = os.getenv('SMTP_PASSWORD') mail_subject = os.getenv('MAIL_SUBJECT') -mail_header = os.getenv('MAIL_HEADER') -mail_footer = os.getenv('MAIL_FOOTER') +mail_header = os.getenv('MAIL_HEADER').replace("\\n","\n") +mail_footer = os.getenv('MAIL_FOOTER').replace("\\n","\n") def main(args):