From 004a431e978f573d65defc9f1904200711434c75 Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Thu, 24 Jan 2019 16:14:33 +0200 Subject: [PATCH] Change to mailustart functions --- core/dovecot/Dockerfile | 5 +---- core/nginx/Dockerfile | 4 ++-- core/nginx/config.py | 19 +++++-------------- core/postfix/Dockerfile | 5 +---- core/postfix/start.py | 4 ++-- services/rspamd/Dockerfile | 5 +---- services/unbound/Dockerfile | 4 ++-- services/unbound/start.py | 7 +------ webmails/rainloop/Dockerfile | 4 +++- webmails/rainloop/start.py | 11 +++-------- webmails/roundcube/Dockerfile | 4 +++- webmails/roundcube/start.py | 7 +------ 12 files changed, 25 insertions(+), 54 deletions(-) diff --git a/core/dovecot/Dockerfile b/core/dovecot/Dockerfile index b37fe4d7..02c9e49d 100644 --- a/core/dovecot/Dockerfile +++ b/core/dovecot/Dockerfile @@ -4,10 +4,7 @@ RUN apk add --no-cache \ python3 py3-pip git \ && pip3 install --upgrade pip # Shared layer between rspamd, postfix, dovecot, unbound and nginx -RUN pip3 install jinja2 \ - && pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart -# Shared layer between rspamd, postfix, dovecot -RUN pip3 install tenacity +RUN pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart # Image specific layers under this line RUN apk add --no-cache \ dovecot dovecot-pigeonhole-plugin rspamd-client bash \ diff --git a/core/nginx/Dockerfile b/core/nginx/Dockerfile index 6afa8301..9bc4c745 100644 --- a/core/nginx/Dockerfile +++ b/core/nginx/Dockerfile @@ -1,10 +1,10 @@ FROM alpine:3.8 # python3 shared with most images RUN apk add --no-cache \ - python3 py3-pip \ + python3 py3-pip git \ && pip3 install --upgrade pip # Shared layer between rspamd, postfix, dovecot, unbound and nginx -RUN pip3 install jinja2 +RUN pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart # Image specific layers under this line RUN apk add --no-cache certbot nginx nginx-mod-mail openssl curl \ && pip3 install idna requests watchdog diff --git a/core/nginx/config.py b/core/nginx/config.py index 79370508..82b02519 100755 --- a/core/nginx/config.py +++ b/core/nginx/config.py @@ -1,32 +1,23 @@ #!/usr/bin/python3 -import jinja2 import os import logging as log import sys +from mailustart import resolve, convert args = os.environ.copy() log.basicConfig(stream=sys.stderr, level=args.get("LOG_LEVEL", "WARNING")) -def convert(src, dst, args): - logger = log.getLogger("convert()") - logger.debug("Source: %s, Destination: %s", src, dst) - open(dst, "w").write(jinja2.Template(open(src).read()).render(**args)) - # Get the first DNS server with open("/etc/resolv.conf") as handle: content = handle.read().split() args["RESOLVER"] = content[content.index("nameserver") + 1] -if "HOST_WEBMAIL" not in args: - args["HOST_WEBMAIL"] = "webmail" -if "HOST_ADMIN" not in args: - args["HOST_ADMIN"] = "admin" -if "HOST_WEBDAV" not in args: - args["HOST_WEBDAV"] = "webdav:5232" -if "HOST_ANTISPAM" not in args: - args["HOST_ANTISPAM"] = "antispam:11334" +args["HOST_WEBMAIL"] = resolve(args.get("HOST_WEBMAIL", "webmail")) +args["HOST_ADMIN"] = resolve(args.get("HOST_ADMIN", "admin")) +args["HOST_WEBDAV"] = resolve(args.get("HOST_WEBDAV", "webdav:5232")) +args["HOST_ANTISPAM"] = resolve(args.get("HOST_ANTISPAM", "antispam:11334")) # TLS configuration cert_name = os.getenv("TLS_CERT_FILENAME", default="cert.pem") diff --git a/core/postfix/Dockerfile b/core/postfix/Dockerfile index 5a9bef40..4b6c4aee 100644 --- a/core/postfix/Dockerfile +++ b/core/postfix/Dockerfile @@ -4,10 +4,7 @@ RUN apk add --no-cache \ python3 py3-pip git \ && pip3 install --upgrade pip # Shared layer between rspamd, postfix, dovecot, unbound and nginx -RUN pip3 install jinja2 \ - && pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart -# Shared layer between rspamd, postfix, dovecot -RUN pip3 install tenacity +RUN pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart # Image specific layers under this line RUN apk add --no-cache postfix postfix-pcre rsyslog \ diff --git a/core/postfix/start.py b/core/postfix/start.py index f113dddb..95c97fde 100755 --- a/core/postfix/start.py +++ b/core/postfix/start.py @@ -28,8 +28,8 @@ def start_podop(): # Actual startup script os.environ["FRONT_ADDRESS"] = resolve(os.environ.get("FRONT_ADDRESS", "front")) os.environ["ADMIN_ADDRESS"] = resolve(os.environ.get("ADMIN_ADDRESS", "admin")) -os.environ["HOST_ANTISPAM"] = os.environ.get("HOST_ANTISPAM", "antispam:11332") -os.environ["HOST_LMTP"] = os.environ.get("HOST_LMTP", "imap:2525") +os.environ["HOST_ANTISPAM"] = resolve(os.environ.get("HOST_ANTISPAM", "antispam:11332")) +os.environ["HOST_LMTP"] = resolve(os.environ.get("HOST_LMTP", "imap:2525")) for postfix_file in glob.glob("/conf/*.cf"): convert(postfix_file, os.path.join("/etc/postfix", os.path.basename(postfix_file))) diff --git a/services/rspamd/Dockerfile b/services/rspamd/Dockerfile index 57196a4d..32e93fac 100644 --- a/services/rspamd/Dockerfile +++ b/services/rspamd/Dockerfile @@ -4,10 +4,7 @@ RUN apk add --no-cache \ python3 py3-pip git \ && pip3 install --upgrade pip # Shared layer between rspamd, postfix, dovecot, unbound and nginx -RUN pip3 install jinja2 \ - && pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart -# Shared layer between rspamd, postfix, dovecot -RUN pip3 install tenacity +RUN pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart # Image specific layers under this line RUN apk add --no-cache rspamd rspamd-controller rspamd-proxy rspamd-fuzzy ca-certificates curl diff --git a/services/unbound/Dockerfile b/services/unbound/Dockerfile index dbf8a3a9..9d40b691 100644 --- a/services/unbound/Dockerfile +++ b/services/unbound/Dockerfile @@ -1,10 +1,10 @@ FROM alpine:3.8 # python3 shared with most images RUN apk add --no-cache \ - python3 py3-pip \ + python3 py3-pip git \ && pip3 install --upgrade pip # Shared layer between rspamd, postfix, dovecot, unbound and nginx -RUN pip3 install jinja2 +RUN pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart # Image specific layers under this line RUN apk add --no-cache unbound curl bind-tools \ && curl -o /etc/unbound/root.hints https://www.internic.net/domain/named.cache \ diff --git a/services/unbound/start.py b/services/unbound/start.py index 4dd5f3be..6216e783 100755 --- a/services/unbound/start.py +++ b/services/unbound/start.py @@ -1,17 +1,12 @@ #!/usr/bin/python3 -import jinja2 import os import logging as log import sys +from mailustart import convert log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING")) -def convert(src, dst): - logger = log.getLogger("convert()") - logger.debug("Source: %s, Destination: %s", src, dst) - open(dst, "w").write(jinja2.Template(open(src).read()).render(**os.environ)) - convert("/unbound.conf", "/etc/unbound/unbound.conf") os.execv("/usr/sbin/unbound", ["-c /etc/unbound/unbound.conf"]) diff --git a/webmails/rainloop/Dockerfile b/webmails/rainloop/Dockerfile index 224fe457..c20f1975 100644 --- a/webmails/rainloop/Dockerfile +++ b/webmails/rainloop/Dockerfile @@ -1,7 +1,7 @@ FROM php:7.2-apache #Shared layer between rainloop and roundcube RUN apt-get update && apt-get install -y \ - python3 curl \ + python3 curl python3-pip git \ && rm -rf /var/lib/apt/lists \ && echo "ServerSignature Off" >> /etc/apache2/apache2.conf @@ -21,6 +21,8 @@ RUN apt-get update && apt-get install -y \ && chown -R www-data: * \ && apt-get purge -y unzip \ && rm -rf /var/lib/apt/lists + + RUN pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart COPY include.php /var/www/html/include.php COPY php.ini /php.ini diff --git a/webmails/rainloop/start.py b/webmails/rainloop/start.py index e2b917bf..495eb376 100755 --- a/webmails/rainloop/start.py +++ b/webmails/rainloop/start.py @@ -1,21 +1,16 @@ #!/usr/bin/python3 -import jinja2 import os import shutil import logging as log import sys +from mailustart import resolve, convert log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING")) -def convert(src, dst): - logger = log.getLogger("convert()") - logger.debug("Source: %s, Destination: %s", src, dst) - open(dst, "w").write(jinja2.Template(open(src).read()).render(**os.environ)) - # Actual startup script -os.environ["FRONT_ADDRESS"] = os.environ.get("FRONT_ADDRESS", "front") -os.environ["IMAP_ADDRESS"] = os.environ.get("IMAP_ADDRESS", "imap") +os.environ["FRONT_ADDRESS"] = resolve(os.environ.get("FRONT_ADDRESS", "front")) +os.environ["IMAP_ADDRESS"] = resolve(os.environ.get("IMAP_ADDRESS", "imap")) os.environ["MAX_FILESIZE"] = str(int(int(os.environ.get("MESSAGE_SIZE_LIMIT"))*0.66/1048576)) diff --git a/webmails/roundcube/Dockerfile b/webmails/roundcube/Dockerfile index 1c5d82c4..cecf009b 100644 --- a/webmails/roundcube/Dockerfile +++ b/webmails/roundcube/Dockerfile @@ -1,7 +1,7 @@ FROM php:7.2-apache #Shared layer between rainloop and roundcube RUN apt-get update && apt-get install -y \ - python3 curl \ + python3 curl python3-pip git \ && rm -rf /var/lib/apt/lists \ && echo "ServerSignature Off" >> /etc/apache2/apache2.conf @@ -23,6 +23,8 @@ RUN apt-get update && apt-get install -y \ && chown -R www-data: logs temp \ && rm -rf /var/lib/apt/lists + RUN pip3 install git+https://github.com/usrpro/MailuStart.git#egg=mailustart + COPY php.ini /php.ini COPY config.inc.php /var/www/html/config/ COPY start.py /start.py diff --git a/webmails/roundcube/start.py b/webmails/roundcube/start.py index 4effd965..c0e52883 100755 --- a/webmails/roundcube/start.py +++ b/webmails/roundcube/start.py @@ -1,17 +1,12 @@ #!/usr/bin/python3 import os -import jinja2 import logging as log import sys +from mailustart import convert log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING")) -def convert(src, dst): - logger = log.getLogger("convert()") - logger.debug("Source: %s, Destination: %s", src, dst) - open(dst, "w").write(jinja2.Template(open(src).read()).render(**os.environ)) - os.environ["MAX_FILESIZE"] = str(int(int(os.environ.get("MESSAGE_SIZE_LIMIT"))*0.66/1048576)) convert("/php.ini", "/usr/local/etc/php/conf.d/roundcube.ini")