hijnu commited on
Commit
6317e8e
·
verified ·
1 Parent(s): e13d45b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +136 -2
README.md CHANGED
@@ -1,10 +1,144 @@
1
  ---
2
  title: N8n
3
- emoji: 🦀
4
  colorFrom: green
5
  colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: N8n
3
+ emoji: 💡🌀✨
4
  colorFrom: green
5
  colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
  ---
9
 
10
+ # Project: Dockerized PostgreSQL with WebDAV Backup and Node.js Integration
11
+
12
+ This Docker image is built on top of **PostgreSQL 15** and provides an integrated environment for running PostgreSQL, performing automated database backups via WebDAV, and executing custom scripts written in **Node.js** and **Python**. This image is tailored for use with **n8n**, an open-source workflow automation tool, and it supports automatic backup management and webhook communication.
13
+
14
+ ## Features
15
+
16
+ - **PostgreSQL Database**: Provides a fully functional PostgreSQL 15 database instance.
17
+ - **Automated Backups**: Includes automated backup functionality to a WebDAV server using custom scripts.
18
+ - **Node.js Environment**: Installs Node.js (default version 20) to allow running workflows or services that depend on Node.js.
19
+ - **Python Integration**: Python 3 is pre-installed, and Python packages can be managed through a virtual environment (`venv`).
20
+ - **Webhook Integration**: Allows interaction with external services via a webhook URL.
21
+ - **Configurable Environment**: Fully customizable through build-time arguments and environment variables.
22
+ - **WebDAV Support**: Automatic interaction with a WebDAV server for file backup and retrieval.
23
+ - **Custom Script Support**: Ships with custom shell scripts to manage database backups and data imports.
24
+
25
+ ## Environment Variables
26
+
27
+ The Docker image uses the following environment variables for configuration. You can modify these variables at runtime to customize behavior:
28
+
29
+ | Variable | Default Value | Description |
30
+ |-----------------------|---------------------------------------|-------------|
31
+ | `POSTGRES_USER` | `n8n` | PostgreSQL user. |
32
+ | `POSTGRES_PASSWORD` | `n8n` | PostgreSQL password. |
33
+ | `POSTGRES_DB` | `n8n` | PostgreSQL database name. |
34
+ | `WEBHOOK_URL` | `https://aigenai-db.hf.space/` | Webhook URL for external communication. |
35
+ | `DB_IMPORT` | `yes` | If set to `yes`, imports the database on startup. |
36
+ | `NODEJS_VER` | `20` | Version of Node.js to install. |
37
+ | `WEBDAV_URL` | `https://cfr2.n8n.us.kg/` | URL of the WebDAV server for backups. |
38
+ | `WEBDAV_USER` | `your_username` | WebDAV username for authentication. |
39
+ | `WEBDAV_PASSWORD` | `your_password` | WebDAV password for authentication. |
40
+ | `N8N_PORT` | `7860` | Port on which n8n will be accessible. |
41
+ | `GENERIC_TIMEZONE` | `Asia/Shanghai` | Timezone for the Docker container. |
42
+ | `DB_TYPE` | `postgresdb` | Specifies the database type. |
43
+ | `DB_POSTGRESDB_HOST` | `localhost` | Hostname for the PostgreSQL database. |
44
+ | `DB_POSTGRESDB_PORT` | `5432` | Port for PostgreSQL. |
45
+ | `VIRTUAL_ENV` | `/app/venv` | Location of the Python virtual environment. |
46
+
47
+ ## Build-Time Arguments
48
+
49
+ These build-time arguments can be provided during the image build to customize the resulting Docker image:
50
+
51
+ | Argument | Default Value | Description |
52
+ |--------------------|-----------------------------------------|-------------|
53
+ | `DUMP_URL` | `""` | URL for the initial database dump (optional). |
54
+ | `DUMP_PASSWORD` | `""` | Password for accessing the database dump (if necessary). |
55
+ | `POSTGRES_USER` | `n8n` | PostgreSQL user. |
56
+ | `POSTGRES_PASSWORD`| `n8n` | PostgreSQL password. |
57
+ | `POSTGRES_DB` | `n8n` | PostgreSQL database name. |
58
+ | `WEBHOOK_URL` | `https://aigenai-db.hf.space/` | Webhook URL for external services. |
59
+ | `NODEJS_VER` | `20` | Node.js version to install. |
60
+ | `WEBDAV_URL` | `https://cfr2.n8n.us.kg/` | WebDAV URL for backups. |
61
+ | `WEBDAV_USER` | `your_username` | WebDAV user. |
62
+ | `WEBDAV_PASSWORD` | `your_password` | WebDAV password. |
63
+
64
+ ## Usage
65
+
66
+ ### Build the Docker Image
67
+
68
+ To build the Docker image, use the following command, passing in any custom arguments as needed:
69
+
70
+ ```bash
71
+ docker build --build-arg POSTGRES_USER=myuser \
72
+ --build-arg POSTGRES_PASSWORD=mypassword \
73
+ --build-arg WEBDAV_URL=https://mywebdavserver.com \
74
+ --build-arg WEBDAV_USER=mywebdavuser \
75
+ --build-arg WEBDAV_PASSWORD=mywebdavpassword \
76
+ -t custom-postgres-n8n:latest .
77
+ ```
78
+
79
+ ### Run the Docker Container
80
+
81
+ To run the container with customized environment variables:
82
+
83
+ ```bash
84
+ docker run -d \
85
+ -e POSTGRES_USER=n8n \
86
+ -e POSTGRES_PASSWORD=n8n \
87
+ -e POSTGRES_DB=n8n \
88
+ -e WEBHOOK_URL=https://your-webhook.url/ \
89
+ -e WEBDAV_URL=https://your-webdav.url/ \
90
+ -e WEBDAV_USER=your_username \
91
+ -e WEBDAV_PASSWORD=your_password \
92
+ -p 7860:7860 \
93
+ custom-postgres-n8n:latest
94
+ ```
95
+
96
+ ### Backup and Restore
97
+
98
+ The image includes scripts for backing up and restoring the PostgreSQL database to and from a WebDAV server:
99
+
100
+ - **Backup**: The `backup.sh` script uploads a PostgreSQL database dump to the WebDAV server.
101
+ - **Import**: The `import-db.sh` script retrieves the latest database dump from the WebDAV server and imports it into PostgreSQL.
102
+
103
+ To manually trigger a backup or import, connect to the running container:
104
+
105
+ ```bash
106
+ docker exec -it <container_id> bash
107
+ ```
108
+
109
+ Then run:
110
+
111
+ ```bash
112
+ # Backup the database
113
+ ./backup.sh
114
+
115
+ # Import the database
116
+ ./import-db.sh
117
+ ```
118
+
119
+ ### Webhook Integration
120
+
121
+ The `WEBHOOK_URL` can be configured to send and receive webhooks. This can be useful for triggering automated workflows or notifying external systems about database changes.
122
+
123
+ ### Python and Node.js Environment
124
+
125
+ This image includes both **Python** and **Node.js**. Python packages are managed through a `requirements.txt` file, and Node.js packages through `package.txt`. You can install and run additional scripts using either Python or Node.js.
126
+
127
+ ### Exposed Port
128
+
129
+ - **n8n**: Accessible on port `7860` by default.
130
+
131
+ ## Custom Scripts
132
+
133
+ Three key scripts are provided:
134
+ - `run.sh`: Main entry point script.
135
+ - `import-db.sh`: Handles database imports from WebDAV.
136
+ - `backup.sh`: Manages automated backups to WebDAV.
137
+
138
+ ## License
139
+
140
+ This project is licensed under the MIT License. See the LICENSE file for details.
141
+
142
+ ---
143
+
144
+ This setup is ideal for environments where database management, automation, and cloud backups are required. It is especially suited for **n8n** users who want a robust and flexible system for managing their PostgreSQL database in conjunction with other automation workflows.