File size: 2,669 Bytes
c1e6772
 
 
b5152f1
 
 
 
 
 
 
c1e6772
 
 
 
9546862
c1e6772
 
b5152f1
c1e6772
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b8a16d
c1e6772
 
1aae828
c1e6772
 
7f298d5
ffb1970
7f298d5
c1e6772
 
 
7eb48da
c1e6772
 
 
 
 
 
 
ea99330
e030ef8
c1e6772
 
 
 
 
 
 
 
 
 
 
7eb48da
c1e6772
 
 
 
 
b5152f1
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
# 使用 PostgreSQL 作为基础镜像
FROM postgres:15

# 主要变量,确保为你实际的值,可在HF设置中设置的值
ARG WEBHOOK_URL=https://你的hf账户名-空间名.hf.space/
ARG WEBDAV_URL="https://cfr2.n8n.us.kg/"
ARG WEBDAV_USER="your_username"
ARG WEBDAV_PASSWORD="your_password"

# 一般变量,使用默认即可,可在HF设置中设置的值
ARG POSTGRES_USER=n8n
ARG POSTGRES_PASSWORD=n8n
ARG POSTGRES_DB=n8n
ARG WORKDIR=/app
ARG DB_IMPORT=yes
ARG NODEJS_VER=20

# 设置环境变量,使用默认即可。
ENV POSTGRES_USER=${POSTGRES_USER} \
    POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
    POSTGRES_DB=${POSTGRES_DB} \
    WEBHOOK_URL=${WEBHOOK_URL} \
    DB_IMPORT=${DB_IMPORT} \
    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_HOST=localhost \
    DB_POSTGRESDB_PORT=5432 \
    DB_POSTGRESDB_USER=${POSTGRES_USER} \
    DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} \
    DB_POSTGRESDB_DATABASE=${POSTGRES_DB} \
    VIRTUAL_ENV=$WORKDIR/venv \
    WEBDAV_URL=${WEBDAV_URL} \
    WEBDAV_USER=${WEBDAV_USER} \
    WEBDAV_PASSWORD=${WEBDAV_PASSWORD} \
    WORKDIR=${WORKDIR} \
    PATH="$WORKDIR/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"

COPY requirements.txt ${WORKDIR}/requirements.txt
COPY package.txt ${WORKDIR}/package.txt

RUN apt-get update && apt-get install -y \
    curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
    ca-certificates openssl tzdata python3 python3-venv python3-pip gosu \
    htop jq && \
    curl -fsSL https://deb.nodesource.com/setup_${NODEJS_VER}.x | bash - && \
    apt-get install -y nodejs && \
    ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    dpkg-reconfigure --frontend noninteractive tzdata && \
    apt-get clean && rm -rf /var/lib/apt/lists/* && \
    python3 -m venv $VIRTUAL_ENV && \
    $VIRTUAL_ENV/bin/pip install --upgrade pip && \
    $VIRTUAL_ENV/bin/pip install -r ${WORKDIR}/requirements.txt && \
    npm install -g $(cat ${WORKDIR}/package.txt)

WORKDIR ${WORKDIR}
COPY run.sh ${WORKDIR}/run.sh
COPY import-db.sh ${WORKDIR}/import-db.sh
COPY backup.sh ${WORKDIR}/backup.sh

RUN chmod +x ${WORKDIR}/run.sh ${WORKDIR}/import-db.sh ${WORKDIR}/backup.sh

USER root
RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
    chown -R postgres:postgres /var/lib/postgresql /var/run/postgresql ${WORKDIR} && \
    mkdir -p ${WORKDIR}/backups && chmod -R 775 ${WORKDIR}/backups

USER postgres

EXPOSE 7860

CMD ./run.sh