Loading Dockerfile +3 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ LABEL org.opencontainers.image.licenses="(EPL-2.0 OR IPL-1.0)" ARG POSTFIX_VERSION=">=3.7.10,<<3.7.11" RUN --mount=source=install.bash,target=/install /install "${POSTFIX_VERSION}" COPY master.cf /etc/postfix/ COPY master.cf /usr/share/postfix/config/ COPY --from=entrypoint /build/entrypoint.bin /bin/entrypoint ENTRYPOINT ["/bin/entrypoint"] ENV MAIL_CONFIG=/etc/postfix entrypoint.py +21 −7 Original line number Diff line number Diff line Loading @@ -12,11 +12,14 @@ from os import environ from os import execv from os import execvp from pathlib import Path from shutil import copytree from subprocess import DEVNULL from subprocess import run from sys import argv MAIN_CONF = Path("/etc/postfix/main.cf") CONFIGS_DIR = Path("/etc/postfix/main.d") RUNTIME_CONFIG = Path("/run/postfix/conf") IMAGE_CONFIG = Path("/usr/share/postfix/config") SOURCE_CONFIG = Path(environ.get("MAIL_CONFIG", "/etc/postfix")) ENCODING = 'utf-8' ERRORS = 'surrogateescape' Loading @@ -35,16 +38,27 @@ def as_arguments(options: dict[str, str]) -> Iterator[str]: yield f"{name}={value}" def check() -> None: """ Run `postconf` to check for config issues """ proc = run(["/usr/sbin/postconf", "-M"], stdout=DEVNULL) if proc.returncode != 0: sys.exit(1) if len(argv) > 1 and not argv[1].startswith("-"): execvp(argv[1], argv[1:]) if (hostname := environ.get("MTA_HOSTNAME")): options["myhostname"] = hostname with MAIN_CONF.open("x", encoding=ENCODING, errors=ERRORS) as conf: for path in CONFIGS_DIR.glob("*.cf"): conf.write(path.read_text(encoding=ENCODING, errors=ERRORS)) conf.write("\n") # Ensure the last line is terminated copytree(IMAGE_CONFIG, RUNTIME_CONFIG, dirs_exist_ok=True) copytree(SOURCE_CONFIG, RUNTIME_CONFIG, dirs_exist_ok=True) environ["MAIL_CONFIG"] = RUNTIME_CONFIG.as_posix() run(["/usr/sbin/postconf", "-v", *as_arguments(options)], check=True) check() run(["/usr/sbin/postconf", *as_arguments(options)]) execv("/usr/lib/postfix/sbin/master", ["master", "-i"] + sys.argv[1:]) install.bash +3 −2 Original line number Diff line number Diff line Loading @@ -12,8 +12,9 @@ done apt update apt satisfy -y "${RESTRICTIONS[*]}" "${PACKAGES[@]}" mkdir -p /usr/share/postfix/config # postinstall, remove most configuration meta_directory=/etc/postfix /etc/postfix/post-install upgrade-package mv /etc/postfix/dynamicmaps.cf /tmp mv /etc/postfix/dynamicmaps.cf /usr/share/postfix/config rm -r /etc/postfix/* mv /tmp/*.cf /etc/postfix Loading
Dockerfile +3 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ LABEL org.opencontainers.image.licenses="(EPL-2.0 OR IPL-1.0)" ARG POSTFIX_VERSION=">=3.7.10,<<3.7.11" RUN --mount=source=install.bash,target=/install /install "${POSTFIX_VERSION}" COPY master.cf /etc/postfix/ COPY master.cf /usr/share/postfix/config/ COPY --from=entrypoint /build/entrypoint.bin /bin/entrypoint ENTRYPOINT ["/bin/entrypoint"] ENV MAIL_CONFIG=/etc/postfix
entrypoint.py +21 −7 Original line number Diff line number Diff line Loading @@ -12,11 +12,14 @@ from os import environ from os import execv from os import execvp from pathlib import Path from shutil import copytree from subprocess import DEVNULL from subprocess import run from sys import argv MAIN_CONF = Path("/etc/postfix/main.cf") CONFIGS_DIR = Path("/etc/postfix/main.d") RUNTIME_CONFIG = Path("/run/postfix/conf") IMAGE_CONFIG = Path("/usr/share/postfix/config") SOURCE_CONFIG = Path(environ.get("MAIL_CONFIG", "/etc/postfix")) ENCODING = 'utf-8' ERRORS = 'surrogateescape' Loading @@ -35,16 +38,27 @@ def as_arguments(options: dict[str, str]) -> Iterator[str]: yield f"{name}={value}" def check() -> None: """ Run `postconf` to check for config issues """ proc = run(["/usr/sbin/postconf", "-M"], stdout=DEVNULL) if proc.returncode != 0: sys.exit(1) if len(argv) > 1 and not argv[1].startswith("-"): execvp(argv[1], argv[1:]) if (hostname := environ.get("MTA_HOSTNAME")): options["myhostname"] = hostname with MAIN_CONF.open("x", encoding=ENCODING, errors=ERRORS) as conf: for path in CONFIGS_DIR.glob("*.cf"): conf.write(path.read_text(encoding=ENCODING, errors=ERRORS)) conf.write("\n") # Ensure the last line is terminated copytree(IMAGE_CONFIG, RUNTIME_CONFIG, dirs_exist_ok=True) copytree(SOURCE_CONFIG, RUNTIME_CONFIG, dirs_exist_ok=True) environ["MAIL_CONFIG"] = RUNTIME_CONFIG.as_posix() run(["/usr/sbin/postconf", "-v", *as_arguments(options)], check=True) check() run(["/usr/sbin/postconf", *as_arguments(options)]) execv("/usr/lib/postfix/sbin/master", ["master", "-i"] + sys.argv[1:])
install.bash +3 −2 Original line number Diff line number Diff line Loading @@ -12,8 +12,9 @@ done apt update apt satisfy -y "${RESTRICTIONS[*]}" "${PACKAGES[@]}" mkdir -p /usr/share/postfix/config # postinstall, remove most configuration meta_directory=/etc/postfix /etc/postfix/post-install upgrade-package mv /etc/postfix/dynamicmaps.cf /tmp mv /etc/postfix/dynamicmaps.cf /usr/share/postfix/config rm -r /etc/postfix/* mv /tmp/*.cf /etc/postfix