Add various environment variables to allow running outside of docker-compose
This commit is contained in:
@@ -6,6 +6,7 @@ import os
|
||||
import tempfile
|
||||
import shlex
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
|
||||
FETCHMAIL = """
|
||||
@@ -18,11 +19,14 @@ RC_LINE = """
|
||||
poll "{host}" proto {protocol} port {port}
|
||||
user "{username}" password "{password}"
|
||||
is "{user_email}"
|
||||
smtphost "smtp"
|
||||
smtphost "{smtphost}"
|
||||
{options}
|
||||
sslproto 'AUTO'
|
||||
"""
|
||||
|
||||
def extract_host_port(host_and_port, default_port):
|
||||
host, _, port = re.match('^(.*)(:([0-9]*))?$', host_and_port).groups()
|
||||
return host, int(port) if port else default_port
|
||||
|
||||
def escape_rc_string(arg):
|
||||
return arg.replace("\\", "\\\\").replace('"', '\\"')
|
||||
@@ -42,6 +46,11 @@ def run(connection, cursor, debug):
|
||||
SELECT user_email, protocol, host, port, tls, username, password, keep
|
||||
FROM fetch
|
||||
""")
|
||||
smtphost, smtpport = extract_host_port(os.environ.get("HOST_SMTP", "smtp"), None)
|
||||
if smtpport is None:
|
||||
smtphostport = smtphost
|
||||
else:
|
||||
smtphostport = "%s/%d" % (smtphost, smtpport)
|
||||
for line in cursor.fetchall():
|
||||
fetchmailrc = ""
|
||||
user_email, protocol, host, port, tls, username, password, keep = line
|
||||
@@ -53,6 +62,7 @@ def run(connection, cursor, debug):
|
||||
protocol=protocol,
|
||||
host=escape_rc_string(host),
|
||||
port=port,
|
||||
smtphost=smtphostport,
|
||||
username=escape_rc_string(username),
|
||||
password=escape_rc_string(password),
|
||||
options=options
|
||||
|
||||
@@ -1 +1 @@
|
||||
servers = "redis";
|
||||
servers = "{{ HOST_REDIS }}";
|
||||
|
||||
@@ -8,7 +8,8 @@ import glob
|
||||
convert = lambda src, dst: open(dst, "w").write(jinja2.Template(open(src).read()).render(**os.environ))
|
||||
|
||||
# Actual startup script
|
||||
os.environ["FRONT_ADDRESS"] = socket.gethostbyname("front")
|
||||
os.environ["FRONT_ADDRESS"] = socket.gethostbyname(os.environ.get("FRONT_ADDRESS", "front"))
|
||||
if "HOST_REDIS" not in os.environ: os.environ["HOST_REDIS"] = "redis"
|
||||
|
||||
for rspamd_file in glob.glob("/conf/*"):
|
||||
convert(rspamd_file, os.path.join("/etc/rspamd/local.d", os.path.basename(rspamd_file)))
|
||||
|
||||
Reference in New Issue
Block a user