Move to `skx/rss2email` for RSS-to-email transport

This allows us to move to a more configurable base, driven by service
configuration files (which can be extended by private configuration)
rather than systemd-driven configuration, which wasn't ever as robust as
it should've been.
This commit is contained in:
Alex Palaistras 2024-03-10 15:00:16 +00:00
parent c21deced79
commit e72f1bc607
9 changed files with 43 additions and 88 deletions

View File

@ -212,6 +212,14 @@ storage:
inline: |
TEST_ENV=foobar
# Feed configuration for RSS2Email.
- path: /etc/coreos-home-server/rss2email/service/feeds/test@localhost/feeds.txt
mode: 0644
contents:
inline: |
https://feeds.bbci.co.uk/news/world/rss.xml
https://pluralistic.net/feed/
# Include pre-generated certificates for localhost domain, as we're not using Let's Encrypt in
# generating certificates for the virtual host.
- path: /etc/ssl/private/localhost/fullchain.pem

View File

@ -28,17 +28,13 @@ DOVECOT_DATABASE_USERNAME=dovecot
DOVECOT_DATABASE_PASSWORD=password
# Configuration for Postfix.
POSTFIX_HOST=localhost
POSTFIX_LOCAL_SMTP_USERNAME=noreply@localhost
POSTFIX_HOST=postfix.localhost
POSTFIX_LOCAL_SMTP_USERNAME=noreply@postfix.localhost
POSTFIX_LOCAL_SMTP_PASSWORD=password
# Configuration for rspamd.
RSPAMD_CONTROLLER_PASSWORD=password
# Configuration for RSS2Email.
RSS2EMAIL_FROM=noreply@localhost
RSS2EMAIL_TO=root@localhost
# Configuration for Rclone.
RCLONE_REMOTE_TYPE=local
RCLONE_REMOTE_PATH=/data/rclone

View File

@ -1,18 +1,15 @@
FROM docker.io/debian:bullseye-slim@sha256:c6d9e246479d56687c1a579a7a0336956a5ce6f2bc26bd7925b0c7405e81dbff
ARG VERSION=3.14 # renovate: datasource=github-tags depName=rss2email/rss2email extractVersion=^v(?<version>.*)$
FROM docker.io/golang:1.22-bookworm@sha256:925fe3fa28ba428cf67a7947ae838f8a1523117b40e3e6b5106c378e3f97fa29 AS builder
ARG VERSION=3.2 # renovate: datasource=github-releases depName=skx/rss2email extractVersion=^release-(?<version>.*)$
RUN apt-get update -y && apt-get install -y --no-install-recommends \
ca-certificates git gettext gosu \
python3 python3-setuptools python3-feedparser python3-html2text python3-bs4
RUN GOBIN=/build/usr/bin go install github.com/skx/rss2email@release-${VERSION}
RUN git clone --branch v${VERSION} --depth 1 https://github.com/rss2email/rss2email /tmp/rss2email && \
cd /tmp/rss2email && python3 setup.py install && \
rm -Rf /tmp/rss2email
FROM docker.io/debian:bookworm-slim@sha256:d02c76d82364cedca16ba3ed6f9102406fa9fa8833076a609cabf14270f43dfc
RUN apt-get update -y && apt-get upgrade -y && apt-get install -y --no-install-recommends \
ca-certificates gettext gosu
RUN addgroup --system --gid 10000 rss2email
RUN adduser --system --uid 10000 --ingroup rss2email --home /var/lib/rss2email rss2email
RUN adduser --system --group --uid 10000 --no-create-home rss2email
COPY container/config /etc/rss2email
COPY --from=builder /build /
COPY container/run-rss2email /run-rss2email
ENTRYPOINT ["/run-rss2email"]

View File

@ -1,36 +0,0 @@
[DEFAULT]
from = ${RSS2EMAIL_FROM}
to = ${RSS2EMAIL_TO}
user-agent = rss2email/1.0
use-publisher-email = True
date-header = True
html-mail = True
multipart-html = True
use-css = True
css =
html {
margin: 0 auto;
max-width: 900px;
padding: 1em 0;
}
h1, h2, h3, h4, h5, h6 {
margin: 0.5em 0;
text-decoration: none;
}
img {
max-width: 100%;
}
p, ul, ol {
color: #1d1d1d;
font-family: sans-serif;
line-height: 1.5;
margin-bottom: 1em;
}
email-protocol = smtp
smtp-auth = True
smtp-username = ${RSS2EMAIL_SMTP_USERNAME}
smtp-password = ${RSS2EMAIL_SMTP_PASSWORD}
smtp-server = ${RSS2EMAIL_SMTP_HOST}
smtp-port = ${RSS2EMAIL_SMTP_PORT}
smtp-ssl = False
verbose = info

View File

@ -1,16 +1,19 @@
#!/bin/sh
# Create configuration file from collected templates.
mkdir -p /etc/rss2email
envsubst < /etc/rss2email/rss2email.conf.template > /etc/rss2email/rss2email.conf
set -eu
if test -n "$(ls -A /etc/rss2email/conf.d)"; then
cat /etc/rss2email/conf.d/*.conf >> /etc/rss2email/rss2email.conf
fi
# Common-use variables.
DATA_DIR=/var/lib/rss2email
CONF_DIR=/etc/rss2email/feeds.d
# Correct permissions for data files.
mkdir -p /var/lib/rss2email
chown -R rss2email:rss2email /var/lib/rss2email
# Parse invividual feed configuration directories.
process() {
printf "Processing feeds for %s...\n" "$2"
install -D --owner rss2email --group rss2email --target-directory "$DATA_DIR/feeds/$2/.rss2email" "$1"/*
chown rss2email:rss2email "$DATA_DIR/feeds/$2/.rss2email"
gosu rss2email sh -c "HOME=$DATA_DIR/feeds/$2 rss2email cron -verbose $2"
}
# Run entrypoint under specific user.
gosu rss2email /usr/local/bin/r2e --config /etc/rss2email/rss2email.conf --data /var/lib/rss2email/data.json "$@"
for feed in "$CONF_DIR"/*/feeds.txt; do
process "$(dirname "$feed")" "$(basename "$(dirname "$feed")")"
done

View File

@ -1,9 +1,5 @@
# Options for RSS-to-Email.
RSS2EMAIL_FROM=${RSS2EMAIL_FROM}
RSS2EMAIL_TO=${RSS2EMAIL_TO}
# Options for SMTP delivery mechanism.
RSS2EMAIL_SMTP_HOST=${POSTFIX_HOST}
RSS2EMAIL_SMTP_PORT=587
RSS2EMAIL_SMTP_USERNAME=${POSTFIX_LOCAL_SMTP_USERNAME}
RSS2EMAIL_SMTP_PASSWORD=${POSTFIX_LOCAL_SMTP_PASSWORD}
SMTP_HOST=${POSTFIX_HOST}
SMTP_PORT=587
SMTP_USERNAME=${POSTFIX_LOCAL_SMTP_USERNAME}
SMTP_PASSWORD=${POSTFIX_LOCAL_SMTP_PASSWORD}

View File

@ -0,0 +1,5 @@
# Feed Configuration for RSS2Email
This folder contains feed configuration, each placed under its own folder named after the
destination email address, and each containing (at a minimum) a `feeds.txt` file with the list of
feeds to subscribe to.

View File

@ -1,14 +0,0 @@
[Unit]
Description=RSS Feed Subscription for %I
[Service]
Type=oneshot
RemainAfterExit=true
SyslogIdentifier=%N
ExecStart=/bin/sh -c "V=$(podman volume mount rss2email-feeds) && printf '[feed.%%s]\nurl = %I\n' $(md5sum <<< '%i' | cut -c-32) > $V/%i.conf"
ExecStartPost=/bin/podman volume unmount rss2email-feeds
ExecStop=/bin/sh -c "V=$(podman volume mount rss2email-feeds) && rm -f $V/%i.conf"
ExecStopPost=/bin/podman volume unmount rss2email-feeds
[Install]
WantedBy=multi-user.target

View File

@ -8,9 +8,9 @@ Type=oneshot
SyslogIdentifier=%N
ExecStart=/bin/podman run --replace --rm --name %N --net internal \
--env-file %E/coreos-home-server/%N/%N.env \
--volume %N-feeds:/etc/%N/conf.d:z,ro \
--volume %E/coreos-home-server/%N/service/feeds:/etc/%N/feeds.d:z,ro \
--volume %N:/var/lib/%N:z \
localhost/%N:latest run
localhost/%N:latest
[Install]
WantedBy=multi-user.target