orztv
commited on
Commit
·
e4fbb50
1
Parent(s):
a926f59
update
Browse files- Dockerfile +82 -0
- README.md +2 -4
- run.sh +39 -0
Dockerfile
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 使用 PostgreSQL 作为基础镜像
|
2 |
+
FROM nikolaik/python-nodejs:python3.12-nodejs20
|
3 |
+
|
4 |
+
# 添加维护者信息
|
5 |
+
LABEL maintainer="ai来事 <https://www.youtube.com/@all.ai.>"
|
6 |
+
|
7 |
+
ARG CACHEBUST=1
|
8 |
+
|
9 |
+
# 设置构建参数,提供默认值
|
10 |
+
ARG WEBHOOK_URL=https://你的hf账户名-空间名.hf.space/
|
11 |
+
ARG POSTGRESDB_PORT=5432
|
12 |
+
|
13 |
+
# 安装系统依赖
|
14 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
15 |
+
curl \
|
16 |
+
unzip \
|
17 |
+
gnupg \
|
18 |
+
build-essential \
|
19 |
+
sudo \
|
20 |
+
vim \
|
21 |
+
git \
|
22 |
+
procps \
|
23 |
+
lsof \
|
24 |
+
net-tools \
|
25 |
+
ca-certificates \
|
26 |
+
openssl \
|
27 |
+
tzdata \
|
28 |
+
htop \
|
29 |
+
jq \
|
30 |
+
&& ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
31 |
+
&& dpkg-reconfigure --frontend noninteractive tzdata \
|
32 |
+
&& apt-get clean \
|
33 |
+
&& rm -rf /var/lib/apt/lists/* \
|
34 |
+
# 创建虚拟环境并安装 Python 依赖
|
35 |
+
&& python3 -m venv $VIRTUAL_ENV \
|
36 |
+
&& $VIRTUAL_ENV/bin/pip install --no-cache-dir --upgrade pip pnpm requests yt-dlp \
|
37 |
+
# 安装 n8n
|
38 |
+
&& npm install -g n8n@latest \
|
39 |
+
&& npm cache clean --force \
|
40 |
+
&& --mount=type=secret,id=POSTGRES_USER,mode=0444,required=true \
|
41 |
+
&& --mount=type=secret,id=POSTGRES_PASSWORD,mode=0444,required=true \
|
42 |
+
&& --mount=type=secret,id=POSTGRES_DB,mode=0444,required=true \
|
43 |
+
&& --mount=type=secret,id=POSTGRESDB_HOST,mode=0444,required=true
|
44 |
+
|
45 |
+
# 设置环境变量
|
46 |
+
ENV WEBHOOK_URL=${WEBHOOK_URL} \
|
47 |
+
N8N_HOST=0.0.0.0 \
|
48 |
+
N8N_PORT=7860 \
|
49 |
+
N8N_PROTOCOL=https \
|
50 |
+
GENERIC_TIMEZONE=Asia/Shanghai \
|
51 |
+
N8N_METRICS=true \
|
52 |
+
QUEUE_HEALTH_CHECK_ACTIVE=true \
|
53 |
+
N8N_PAYLOAD_SIZE_MAX=256 \
|
54 |
+
DB_TYPE=postgresdb \
|
55 |
+
DB_POSTGRESDB_HOST=$(cat /run/secrets/POSTGRESDB_HOST) \
|
56 |
+
DB_POSTGRESDB_PORT=$(cat /run/secrets/POSTGRESDB_PORT) \
|
57 |
+
DB_POSTGRESDB_USER=$(cat /run/secrets/POSTGRES_USER) \
|
58 |
+
DB_POSTGRESDB_PASSWORD=$(cat /run/secrets/POSTGRES_PASSWORD) \
|
59 |
+
DB_POSTGRESDB_DATABASE=$(cat /run/secrets/POSTGRES_DB) \
|
60 |
+
VIRTUAL_ENV=/home/pn/venv \
|
61 |
+
PATH="/home/pn/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
|
62 |
+
|
63 |
+
# 创建工作目录
|
64 |
+
WORKDIR /home/pn/n8n
|
65 |
+
|
66 |
+
# 复制启动脚本# 创建数据目录
|
67 |
+
COPY --chown=pn:pn run.sh ./run.sh
|
68 |
+
RUN chmod +x ./run.sh \
|
69 |
+
&& mkdir -p /home/pn/.n8n \
|
70 |
+
&& chown -R pn:pn /home/pn/.n8n
|
71 |
+
|
72 |
+
# 暴露端口
|
73 |
+
EXPOSE 7860
|
74 |
+
|
75 |
+
# 切换到非 root 用户
|
76 |
+
USER pn
|
77 |
+
|
78 |
+
# 设置数据卷
|
79 |
+
VOLUME ["/home/pn/.n8n"]
|
80 |
+
|
81 |
+
# 启动命令
|
82 |
+
CMD ["./run.sh"]
|
README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: green
|
5 |
colorTo: pink
|
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: ai + n8n
|
3 |
+
emoji: ⚡⚡⚡
|
4 |
colorFrom: green
|
5 |
colorTo: pink
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
---
|
|
|
|
run.sh
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
set -e
|
3 |
+
|
4 |
+
# 添加错误处理
|
5 |
+
trap 'echo "Error on line $LINENO"' ERR
|
6 |
+
|
7 |
+
# 环境变量检查
|
8 |
+
: "${N8N_ENCRYPTION_KEY:?Need to set N8N_ENCRYPTION_KEY}"
|
9 |
+
|
10 |
+
WEBDAV_URL="$WEBDAV_URL"
|
11 |
+
WEBDAV_USER="$WEBDAV_USER"
|
12 |
+
WEBDAV_PASSWORD="$WEBDAV_PASSWORD"
|
13 |
+
|
14 |
+
current_time=$(date +"%Y-%m-%d %H:%M:%S")
|
15 |
+
echo "Starting n8n at $current_time"
|
16 |
+
|
17 |
+
# 设置 N8N 环境变量
|
18 |
+
export N8N_ENCRYPTION_KEY="n8n8n8n"
|
19 |
+
# 允许使用所有内建模块
|
20 |
+
export NODE_FUNCTION_ALLOW_BUILTIN=*
|
21 |
+
# 允许使用外部 npm 模块
|
22 |
+
export NODE_FUNCTION_ALLOW_EXTERNAL=*
|
23 |
+
# Activate automatic data pruning
|
24 |
+
export EXECUTIONS_DATA_PRUNE=true
|
25 |
+
# Number of hours after execution that n8n deletes data
|
26 |
+
export EXECUTIONS_DATA_MAX_AGE=36
|
27 |
+
# Number of executions to store
|
28 |
+
export EXECUTIONS_DATA_PRUNE_MAX_COUNT=1000
|
29 |
+
# Save executions ending in errors
|
30 |
+
export EXECUTIONS_DATA_SAVE_ON_ERROR=all
|
31 |
+
# Save successful executions
|
32 |
+
export EXECUTIONS_DATA_SAVE_ON_SUCCESS=all
|
33 |
+
# Don't save node progress for each execution
|
34 |
+
export EXECUTIONS_DATA_SAVE_ON_PROGRESS=false
|
35 |
+
# Don't save manually launched executions
|
36 |
+
export EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS=false
|
37 |
+
|
38 |
+
# 使用绝对路径调用 n8n,添加日志输出
|
39 |
+
exec n8n start
|