File size: 3,649 Bytes
e4fbb50
 
 
 
 
 
da1bcc5
e4fbb50
 
 
f0cbeae
e4fbb50
b4dd3ad
 
 
 
 
 
 
 
 
 
f0cbeae
b4dd3ad
0069402
 
 
 
 
 
2d97948
 
 
 
3f73fdd
2d97948
 
 
 
b4dd3ad
e4fbb50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad5bc33
0069402
e4fbb50
 
7a4fde2
2d97948
3f73fdd
7a4fde2
 
 
aa0785d
 
 
72eeb27
aa0785d
72eeb27
2d97948
e4fbb50
 
 
 
c52ae5c
e4fbb50
c52ae5c
b4dd3ad
e4fbb50
b4dd3ad
 
 
 
 
59802b0
 
 
 
 
e4fbb50
 
 
 
b4dd3ad
e4fbb50
2d97948
e4fbb50
 
 
 
 
 
 
 
 
 
 
 
 
 
2d97948
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# 使用 PostgreSQL 作为基础镜像
FROM nikolaik/python-nodejs:python3.12-nodejs20

# 添加维护者信息
LABEL maintainer="ai来事 <https://www.youtube.com/@all.ai.>"

ARG CACHEBUST=2

# 设置构建参数,提供默认值
ARG WEBHOOK_URL=https://你的hf账户名-空间名.hf.space/
ARG POSTGRESDB_PORT=5432

# 设置基本环境变量
ENV WEBHOOK_URL=${WEBHOOK_URL} \
    N8N_HOST=0.0.0.0 \
    N8N_PORT=7860 \
    N8N_PROTOCOL=https \
    GENERIC_TIMEZONE=Asia/Shanghai \
    N8N_METRICS=true \
    QUEUE_HEALTH_CHECK_ACTIVE=true \
    N8N_PAYLOAD_SIZE_MAX=256 \
    DB_TYPE=postgresdb \
    DB_POSTGRESDB_PORT=${POSTGRESDB_PORT} \
    VIRTUAL_ENV=/home/pn/venv \
    PATH="/home/pn/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH" \
    # 添加 Redis 配置
    QUEUE_BULL_REDIS_HOST=localhost \
    QUEUE_BULL_REDIS_PORT=6379 \
    QUEUE_BULL_REDIS_DB=0 \
    N8N_QUEUE_BULL_REDIS_PREFIX=n8n:queue \
    EXECUTIONS_MODE=queue \
    # 添加 Qdrant 配置
    QDRANT_HOST=localhost \
    QDRANT_PORT=6333 \
    QDRANT_VERSION=1.12.4 \
    # 添加超时配置
    WAIT_TIMEOUT=30 \
    # 添加日志级别
    N8N_LOG_LEVEL=info

# 安装系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    unzip \
    gnupg \
    build-essential \
    sudo \
    vim \
    git \
    procps \
    lsof \
    net-tools \
    ca-certificates \
    openssl \
    tzdata \
    htop \
    jq \
    netcat-openbsd \
    redis-server \
    && ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && dpkg-reconfigure --frontend noninteractive tzdata \
    # 下载并安装预编译的 Qdrant
    && cd /tmp \
    && curl -L https://github.com/qdrant/qdrant/releases/download/v${QDRANT_VERSION}/qdrant-x86_64-unknown-linux-gnu.tar.gz -o qdrant.tar.gz \
    && tar xvf qdrant.tar.gz \
    && mv qdrant /usr/local/bin/ \
    && rm qdrant.tar.gz \
    # 创建 Qdrant 配置目录和数据目录
    && mkdir -p /home/pn/.n8n/qdrant/storage \
    && mkdir -p /home/pn/.n8n/qdrant/config \
    && mkdir -p /home/pn/.n8n/qdrant/snapshots \
    && chown -R pn:pn /home/pn/.n8n/qdrant \
    && chmod -R 755 /home/pn/.n8n/qdrant \
    # 清理
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    # 创建虚拟环境并安装 Python 依赖
    && python3 -m venv $VIRTUAL_ENV \
    && $VIRTUAL_ENV/bin/pip install --no-cache-dir --upgrade pip requests yt-dlp \
    # 安装 n8n
    && npm install -g n8n@latest pnpm \
    && npm cache clean --force

# 创建环境变量文件
RUN --mount=type=secret,id=POSTGRES_USER,mode=0444,required=true \
    --mount=type=secret,id=POSTGRES_PASSWORD,mode=0444,required=true \
    --mount=type=secret,id=POSTGRES_DB,mode=0444,required=true \
    --mount=type=secret,id=POSTGRESDB_HOST,mode=0444,required=true \
    echo "export DB_POSTGRESDB_HOST=$(cat /run/secrets/POSTGRESDB_HOST)" >> /home/pn/.env && \
    echo "export DB_POSTGRESDB_USER=$(cat /run/secrets/POSTGRES_USER)" >> /home/pn/.env && \
    echo "export DB_POSTGRESDB_PASSWORD=$(cat /run/secrets/POSTGRES_PASSWORD)" >> /home/pn/.env && \
    echo "export DB_POSTGRESDB_DATABASE=$(cat /run/secrets/POSTGRES_DB)" >> /home/pn/.env && \
    chown pn:pn /home/pn/.env

# 创建工作目录
WORKDIR /home/pn/n8n

# 复制启动脚本并创建数据目录
COPY --chown=pn:pn run.sh ./run.sh
COPY --chown=pn:pn config/n8n_env.sh ./config/n8n_env.sh
RUN chmod +x ./run.sh \
    && mkdir -p /home/pn/.n8n \
    && chown -R pn:pn /home/pn/.n8n

# 暴露端口
EXPOSE 7860

# 切换到非 root 用户
USER pn

# 设置数据卷
VOLUME ["/home/pn/.n8n"]

# 启动命令
CMD ["./run.sh"]