forked from bokysan/docker-postfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
68 lines (53 loc) · 2.95 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# syntax=docker/dockerfile:1.2
ARG BASE_IMAGE=alpine:latest
# ARG BASE_IMAGE=ubuntu:jammy
FROM ${BASE_IMAGE} AS build-scripts
COPY ./build-scripts ./build-scripts
# ============================ INSTALL BASIC SERVICES ============================
FROM ${BASE_IMAGE} AS base
ARG TARGETPLATFORM
# Install supervisor, postfix
# Install postfix first to get the first account (101)
# Install opendkim second to get the second account (102)
# --mount=type=cache,target=/var/cache/apk,sharing=locked,id=var-cache-apk-$TARGETPLATFORM \
# --mount=type=cache,target=/etc/apk/cache,sharing=locked,id=etc-apk-cache-$TARGETPLATFORM \
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=var-cache-apt-$TARGETPLATFORM \
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=var-lib-apt-$TARGETPLATFORM \
--mount=type=tmpfs,target=/var/cache/apk \
--mount=type=tmpfs,target=/tmp \
--mount=type=bind,from=build-scripts,source=/build-scripts,target=/build-scripts \
sh /build-scripts/postfix-install.sh
# ============================ BUILD SASL XOAUTH2 ============================
FROM base AS sasl
ARG TARGETPLATFORM
ARG SASL_XOAUTH2_REPO_URL=https://github.com/tarickb/sasl-xoauth2.git
ARG SASL_XOAUTH2_GIT_REF=release-0.18
# --mount=type=cache,target=/var/cache/apk,sharing=locked,id=var-cache-apk-$TARGETPLATFORM \
# --mount=type=cache,target=/etc/apk/cache,sharing=locked,id=etc-apk-cache-$TARGETPLATFORM \
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=var-cache-apt-$TARGETPLATFORM \
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=var-lib-apt-$TARGETPLATFORM \
--mount=type=tmpfs,target=/etc/apk/cache \
--mount=type=tmpfs,target=/var/cache/apk \
--mount=type=tmpfs,target=/tmp \
--mount=type=tmpfs,target=/sasl-xoauth2 \
--mount=type=bind,from=build-scripts,source=/build-scripts,target=/build-scripts \
sh /build-scripts/sasl-build.sh
# ============================ Prepare main image ============================
FROM sasl
LABEL maintainer="Bojan Cekrlic - https://github.com/bokysan/docker-postfix/"
# Set up configuration
COPY /configs/supervisord.conf /etc/supervisord.conf
COPY /configs/rsyslog*.conf /etc/
COPY /configs/opendkim.conf /etc/opendkim/opendkim.conf
COPY /configs/smtp_header_checks /etc/postfix/smtp_header_checks
COPY /configs/master.cf /etc/postfix/master.cf
COPY /scripts/* /scripts/
RUN chmod +x /scripts/*
# Set up volumes
VOLUME [ "/var/spool/postfix", "/etc/postfix", "/etc/opendkim/keys" ]
# Run supervisord
USER root
WORKDIR /tmp
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 CMD printf "EHLO healthcheck\n" | nc 127.0.0.1 587 | grep -qE "^220.*ESMTP Postfix"
EXPOSE 587
CMD [ "/bin/sh", "-c", "/scripts/run.sh" ]