Files

n8n deployment

This directory runs n8n separately from the news web service. The n8n data directory and .env stay on the server and must not be committed to Gitea.

First deployment on the server

cd /projects/daily-news-digest/n8n
cp .env.example .env
openssl rand -hex 32
nano .env
chmod 600 .env
mkdir -p data
sudo chown -R 1000:1000 data
docker compose up -d
docker compose ps
docker compose logs --tail=50 n8n

The generated value must be copied to N8N_ENCRYPTION_KEY and must not be changed later. n8n listens only on the server's loopback address. From a local computer, create an SSH tunnel and open http://127.0.0.1:5678:

ssh -L 5678:127.0.0.1:5678 root@YOUR_SERVER_IP

Updating from Gitea

cd /projects/daily-news-digest
git pull
cd n8n
docker compose up -d

Do not overwrite n8n/.env or n8n/data during updates.

PostgreSQL credential

In n8n, create a PostgreSQL credential for the existing application database. Because n8n uses host networking and PostgreSQL is on the same host, use the host's local PostgreSQL address (127.0.0.1), port 5432, your database/user/ password, and disable SSL when the server reports that it does not support SSL.

The first workflow in workflows/01-test-postgres.json only checks this connection. It does not fetch news or send email.

RSS ingestion workflow

Run db/migrations/004_n8n_ingestion.sql in DBeaver first. It creates the idempotent database ingestion function and adds a verified starter set of RSS sources. It is safe to run the whole file again.

Then import workflows/02-fetch-news-to-web.json into n8n and select the same PostgreSQL credential on both PostgreSQL nodes. Keep the workflow inactive for the first test and click Execute workflow. The workflow:

  • loads every enabled row from news_sources;
  • reads RSS feeds and keeps entries from the last 14 days;
  • classifies entries with local keyword rules, without an AI API;
  • upserts articles and publishes today's web report;
  • does not send email.

After the manual test succeeds and the web page shows today's report, activate the workflow. Its schedule is 07:30 in Asia/Shanghai.

New RSS sources can be added later with an INSERT into news_sources; the workflow reads that table on every run, so the workflow itself does not need to be edited. Set enabled = FALSE to pause a source without deleting it.