Skip to content

Commit

Permalink
Integrate plugin with postfwd Docker image
Browse files Browse the repository at this point in the history
This commit introduces Dockerfile, which pulls official postfwd Docker
Image v1.37 and installs postfwd geoip anti spam plugin.

Closes #14

Signed-off-by: Ondrej Vasko <[email protected]>
  • Loading branch information
Lirt committed Jan 5, 2019
1 parent 98af7ae commit 92438ab
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM postfwd/postfwd:latest

LABEL maintainer="Postfwd GeoIp Spam Plugin Maintainer <[email protected]>"

ENV PATH="/opt/postfwd/sbin/:${PATH}"
ENV POSTFWD_ANTISPAM_MAIN_CONFIG_PATH=/etc/postfwd/anti-spam.conf
ENV POSTFWD_ANTISPAM_SQL_STATEMENTS_CONFIG_PATH=/etc/postfwd/anti-spam-sql-st.conf

# Install dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libconfig-any-perl \
libconfig-tiny-perl \
libconfig-ini-perl \
libconfig-general-perl \
libdbi-perl \
libdbd-mysql-perl \
libdbd-pg-perl \
libgeo-ip-perl \
libtime-piece-perl \
&& rm -rf /var/lib/apt/lists/*

# Copy binaries into PATH
RUN cp /opt/postfwd/sbin/postfwd1 /opt/postfwd/sbin/postfwd2 /usr/sbin/

# Copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod 750 /usr/local/bin/docker-entrypoint.sh

# Install plugin
COPY --chown=postfw:postfw anti-spam-sql-st.conf /etc/postfwd/anti-spam-sql-st.conf
COPY --chown=postfw:postfw postfwd-anti-spam.plugin /etc/postfwd/postfwd-anti-spam.plugin
RUN chmod 644 \
/etc/postfwd/postfwd-anti-spam.plugin \
/etc/postfwd/anti-spam-sql-st.conf

ENTRYPOINT ["docker-entrypoint.sh", \
"--file", "/etc/postfwd/postfwd.cf", \
"--user", "postfw", "--group", "postfw", \
"--plugins", "/etc/postfwd/postfwd-anti-spam.plugin", \
"--server_socket", "tcp:0.0.0.0:10040", \
"--cache_socket=unix::/var/lib/postfwd/postfwd.cache", \
"--pidfile=/var/lib/postfwd/postfwd.pid", \
"--save_rates=/var/lib/postfwd/postfwd.rates", \
"--stdout", "--nodaemon"]

EXPOSE 10040
CMD ["postfwd2", \
"--cache=60", \
"--noidlestats", \
"--summary=600"]
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ If you are interested in how your users got their mail accounts hacked, check ou

Plugin was tested with _postfwd2 ver. 1.35_ with MySQL and PostgreSQL backend.

## Running with Docker

Prebuilt ready-to-use Docker image is located on DockerHub and can be simply pulled by command:

```bash
docker pull lirt/postfwd-anti-geoip-spam-plugin:latest
```

To run postfwd with geoip-plugin, run docker with configuration files mounted as volumes:

```bash
docker run \
-v </absolute/path/to/anti-spam.conf>:/etc/postfwd/anti-spam.conf \
-v </absolute/path/to/postfwd.cf>:/etc/postfwd/postfwd.cf \
lirt/postfwd-anti-geoip-spam-plugin
```

This will run `postfwd2` with default arguments, reading postfwd rules file from your mounted volume file `postfwd.cf` and using anti-spam configuration from your file `anti-spam.conf`.

## Installation

To install this plugin follow next steps:
Expand Down
31 changes: 31 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -eo pipefail

# If command starts with an option, prepend postfwd2
if [ "${1:0:1}" = '-' ]; then
set -- postfwd2 "$@"
fi

# Check if help, version or manual arguments were used
want_help=
for arg; do
case "$arg" in
--help|-h|--manual|-m|--version|-V)
want_help=1
break
;;
esac
done


if [ "$1" = "postfwd1" ] || [ "$1" = "postfwd2" ] && [ -z "$want_help" ]; then
if [ ! -f /etc/postfwd/anti-spam.conf ]; then
echo >&2 'ERROR: Anti-spam plugin configuration file /etc/postfwd/anti-spam.conf was not found. Perhaps you forgot to mount it using "-v </absolute/path/to/anti-spam.conf>:/etc/postfwd/anti-spam.conf".'
exit 1
fi
chmod -R 644 /etc/postfwd/*
chown -R postfw:postfw /etc/postfwd
fi

exec "$@"

0 comments on commit 92438ab

Please sign in to comment.