Update Dockerfile
Browse files- Dockerfile +95 -0
Dockerfile
CHANGED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 使用 PostgreSQL 作为基础镜像
|
2 |
+
FROM postgres:15
|
3 |
+
|
4 |
+
# 设置构建时变量,确保为每个变量提供默认值
|
5 |
+
ARG DUMP_URL=""
|
6 |
+
ARG DUMP_PASSWORD=""
|
7 |
+
ARG POSTGRES_USER=n8n
|
8 |
+
ARG POSTGRES_PASSWORD=n8n
|
9 |
+
ARG POSTGRES_DB=n8n
|
10 |
+
ARG WEBHOOK_URL=https://aigenai-db.hf.space/
|
11 |
+
ARG WORKDIR=/app
|
12 |
+
ARG DB_IMPORT=no
|
13 |
+
ARG NODEJS_VER=20
|
14 |
+
ARG PYTHON_PACKAGES="requirements.txt"
|
15 |
+
ARG NODE_PACKAGES="package.json"
|
16 |
+
ARG WEBDAV_URL="https://cfr2.n8n.us.kg/"
|
17 |
+
ARG WEBDAV_USER="your_username"
|
18 |
+
ARG WEBDAV_PASSWORD="your_password"
|
19 |
+
|
20 |
+
# 设置环境变量
|
21 |
+
ENV POSTGRES_USER=${POSTGRES_USER} \
|
22 |
+
POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
|
23 |
+
POSTGRES_DB=${POSTGRES_DB} \
|
24 |
+
WEBHOOK_URL=${WEBHOOK_URL} \
|
25 |
+
DB_IMPORT=${DB_IMPORT} \
|
26 |
+
N8N_HOST=0.0.0.0 \
|
27 |
+
N8N_PORT=7860 \
|
28 |
+
N8N_PROTOCOL=https \
|
29 |
+
GENERIC_TIMEZONE=Asia/Shanghai \
|
30 |
+
N8N_METRICS=true \
|
31 |
+
QUEUE_HEALTH_CHECK_ACTIVE=true \
|
32 |
+
N8N_PAYLOAD_SIZE_MAX=256 \
|
33 |
+
DB_TYPE=postgresdb \
|
34 |
+
DB_POSTGRESDB_HOST=localhost \
|
35 |
+
DB_POSTGRESDB_PORT=5432 \
|
36 |
+
DB_POSTGRESDB_USER=${POSTGRES_USER} \
|
37 |
+
DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} \
|
38 |
+
DB_POSTGRESDB_DATABASE=${POSTGRES_DB} \
|
39 |
+
VIRTUAL_ENV=$WORKDIR/venv \
|
40 |
+
ENV WEBDAV_URL=${WEBDAV_URL} \
|
41 |
+
WEBDAV_USER=${WEBDAV_USER} \
|
42 |
+
WEBDAV_PASSWORD=${WEBDAV_PASSWORD} \
|
43 |
+
PATH="$WORKDIR/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
|
44 |
+
|
45 |
+
# 安装必要的软件包、Node.js,Python,并设置时区,清理apt缓存以减少镜像大小
|
46 |
+
RUN apt-get update && apt-get install -y \
|
47 |
+
curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
|
48 |
+
ca-certificates openssl tzdata python3 python3-venv python3-pip gosu \
|
49 |
+
htop jq wget lftp cron && \
|
50 |
+
curl -fsSL https://deb.nodesource.com/setup_${NODEJS_VER}.x | bash - && \
|
51 |
+
apt-get install -y nodejs && \
|
52 |
+
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
53 |
+
dpkg-reconfigure --frontend noninteractive tzdata && \
|
54 |
+
curl https://rclone.org/install.sh | bash && \
|
55 |
+
apt-get clean && rm -rf /var/lib/apt/lists/* && \
|
56 |
+
python3 -m venv $VIRTUAL_ENV && \
|
57 |
+
$VIRTUAL_ENV/bin/pip install --upgrade pip && \
|
58 |
+
$VIRTUAL_ENV/bin/pip install -r ${PYTHON_PACKAGES} && \
|
59 |
+
npm install -g $(cat ${NODE_PACKAGES})
|
60 |
+
|
61 |
+
# 设置工作目录并复制脚本
|
62 |
+
WORKDIR ${WORKDIR}
|
63 |
+
COPY run.sh ${WORKDIR}/run.sh
|
64 |
+
COPY import-db.sh ${WORKDIR}/import-db.sh
|
65 |
+
COPY requirements.txt ${WORKDIR}/requirements.txt
|
66 |
+
COPY package.json ${WORKDIR}/package.json
|
67 |
+
COPY backup.sh ${WORKDIR}/backup.sh
|
68 |
+
|
69 |
+
RUN chmod +x ${WORKDIR}/run.sh ${WORKDIR}/import-db.sh ${WORKDIR}/backup.sh
|
70 |
+
|
71 |
+
# 更改 postgres 用户 UID 和 GID 为 1000,设置备份目录
|
72 |
+
USER root
|
73 |
+
RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
|
74 |
+
chown -R postgres:postgres /var/lib/postgresql /var/run/postgresql ${WORKDIR} && \
|
75 |
+
mkdir -p ${WORKDIR}/backups && chmod -R 775 ${WORKDIR}/backups
|
76 |
+
|
77 |
+
# 设置定期备份任务:每4小时运行一次备份任务
|
78 |
+
RUN echo "0 */1 * * * /app/backup.sh" > /etc/cron.d/backup && \
|
79 |
+
chmod 0644 /etc/cron.d/backup && crontab /etc/cron.d/backup
|
80 |
+
|
81 |
+
|
82 |
+
# 切换到 postgres 用户
|
83 |
+
USER postgres
|
84 |
+
|
85 |
+
# 分离 PostgreSQL 和 n8n 健康检查
|
86 |
+
HEALTHCHECK --interval=120s --timeout=10s --start-period=10s --retries=3 \
|
87 |
+
CMD pg_isready || exit 1
|
88 |
+
HEALTHCHECK --interval=120s --timeout=10s --start-period=10s --retries=3 \
|
89 |
+
CMD curl -f http://localhost:7860/HEALTHZ || exit 1
|
90 |
+
|
91 |
+
# 暴露 n8n 服务端口
|
92 |
+
EXPOSE 7860
|
93 |
+
|
94 |
+
# 启动容器时执行 run.sh 脚本
|
95 |
+
CMD ["./run.sh"]
|