添加n8n流程
This commit is contained in:
@@ -4,3 +4,7 @@
|
|||||||
*.log
|
*.log
|
||||||
data/
|
data/
|
||||||
backups/
|
backups/
|
||||||
|
|
||||||
|
# n8n runtime secret and persistent data
|
||||||
|
n8n/.env
|
||||||
|
n8n/data/
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# n8n instance secret. Generate once with: openssl rand -hex 32
|
||||||
|
# Do not change this value after n8n has stored credentials.
|
||||||
|
N8N_ENCRYPTION_KEY=
|
||||||
|
|
||||||
|
# Initial access is through an SSH tunnel, so keep n8n on localhost.
|
||||||
|
N8N_HOST=127.0.0.1
|
||||||
|
N8N_PORT=5678
|
||||||
|
N8N_LISTEN_ADDRESS=127.0.0.1
|
||||||
|
N8N_PROTOCOL=http
|
||||||
|
N8N_EDITOR_BASE_URL=http://127.0.0.1:5678
|
||||||
|
N8N_SECURE_COOKIE=false
|
||||||
|
|
||||||
|
TZ=Asia/Shanghai
|
||||||
|
GENERIC_TIMEZONE=Asia/Shanghai
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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`:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
ssh -L 5678:127.0.0.1:5678 root@YOUR_SERVER_IP
|
||||||
|
```
|
||||||
|
|
||||||
|
## Updating from Gitea
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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.
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
services:
|
||||||
|
n8n:
|
||||||
|
image: docker.n8n.io/n8nio/n8n:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
network_mode: host
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
volumes:
|
||||||
|
- ./data:/home/node/.n8n
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"name": "Daily News Digest - Test PostgreSQL",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"parameters": {},
|
||||||
|
"id": "manual-trigger",
|
||||||
|
"name": "手动执行",
|
||||||
|
"type": "n8n-nodes-base.manualTrigger",
|
||||||
|
"typeVersion": 1,
|
||||||
|
"position": [260, 300]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parameters": {
|
||||||
|
"operation": "executeQuery",
|
||||||
|
"query": "SELECT current_database() AS database_name, NOW() AS checked_at, (SELECT COUNT(*) FROM news_sources) AS source_count, (SELECT COUNT(*) FROM news_articles) AS article_count;",
|
||||||
|
"options": {}
|
||||||
|
},
|
||||||
|
"id": "postgres-check",
|
||||||
|
"name": "检查新闻数据库",
|
||||||
|
"type": "n8n-nodes-base.postgres",
|
||||||
|
"typeVersion": 2.5,
|
||||||
|
"position": [520, 300]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": {
|
||||||
|
"手动执行": {
|
||||||
|
"main": [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"node": "检查新闻数据库",
|
||||||
|
"type": "main",
|
||||||
|
"index": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"active": false,
|
||||||
|
"settings": {},
|
||||||
|
"versionId": "daily-news-digest-test-postgres-v1",
|
||||||
|
"meta": {
|
||||||
|
"templateCredsSetupCompleted": false
|
||||||
|
},
|
||||||
|
"pinData": {},
|
||||||
|
"tags": []
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user