Update Dockerfile
Browse files- Dockerfile +28 -34
Dockerfile
CHANGED
@@ -5,17 +5,12 @@ FROM node:20-slim AS builder
|
|
5 |
ARG requirements=requests
|
6 |
ARG PACKAGES=n8n
|
7 |
ARG WORKDIR=/app
|
8 |
-
ARG DUMP_URL
|
9 |
-
ARG DUMP_PASSWORD
|
10 |
|
11 |
# 安装 Python3、venv 以及必要的系统工具
|
12 |
RUN apt-get update && apt-get install -y python3 python3-venv curl gnupg build-essential && \
|
13 |
npm install -g ${PACKAGES} && \
|
14 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
15 |
|
16 |
-
# 验证 Node.js 和 npm 安装的 node_modules 路径是否存在
|
17 |
-
RUN ls -al /usr/local/lib/node_modules || echo "node_modules not found!"
|
18 |
-
|
19 |
# 设置 Python 虚拟环境
|
20 |
ENV VIRTUAL_ENV=/opt/venv
|
21 |
RUN python3 -m venv $VIRTUAL_ENV && \
|
@@ -25,42 +20,46 @@ RUN python3 -m venv $VIRTUAL_ENV && \
|
|
25 |
# 主运行阶段:基于较小的 PostgreSQL 镜像
|
26 |
FROM postgres:latest
|
27 |
|
28 |
-
#
|
29 |
ARG POSTGRES_USER=n8n
|
30 |
ARG POSTGRES_PASSWORD=n8n
|
31 |
ARG POSTGRES_DB=n8n
|
32 |
ARG WEBHOOK_URL=https://aigenai-db.hf.space/
|
33 |
ARG WORKDIR=/app
|
34 |
ARG DB_IMPORT=no
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
#
|
37 |
-
ENV
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
N8N_PORT=7860 \
|
39 |
N8N_PROTOCOL=https \
|
40 |
-
WEBHOOK_URL=${WEBHOOK_URL} \
|
41 |
GENERIC_TIMEZONE=Asia/Shanghai \
|
42 |
N8N_METRICS=true \
|
43 |
QUEUE_HEALTH_CHECK_ACTIVE=true \
|
44 |
-
N8N_PAYLOAD_SIZE_MAX=256
|
45 |
-
|
46 |
-
# 设置数据库连接相关的环境变量
|
47 |
-
ENV DB_TYPE=postgresdb \
|
48 |
DB_POSTGRESDB_HOST=localhost \
|
49 |
DB_POSTGRESDB_PORT=5432 \
|
50 |
DB_POSTGRESDB_USER=${POSTGRES_USER} \
|
51 |
DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} \
|
52 |
-
DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
|
53 |
-
|
54 |
-
|
55 |
-
ENV VIRTUAL_ENV=/opt/venv \
|
56 |
-
PATH="$VIRTUAL_ENV/bin:/usr/local/bin:/usr/local/lib/node_modules/n8n/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
|
57 |
|
58 |
# 复制构建阶段的 n8n 和 Python 运行环境
|
59 |
-
COPY --from=builder /usr/local/bin/node /usr/local/bin/node
|
60 |
COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
|
61 |
COPY --from=builder $VIRTUAL_ENV $VIRTUAL_ENV
|
62 |
|
63 |
-
#
|
64 |
RUN apt-get update && apt-get install -y \
|
65 |
curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
|
66 |
ca-certificates openssl tzdata python3-venv gosu \
|
@@ -71,7 +70,12 @@ RUN apt-get update && apt-get install -y \
|
|
71 |
# 设置工作目录并复制启动脚本
|
72 |
WORKDIR ${WORKDIR}
|
73 |
COPY run.sh ${WORKDIR}/run.sh
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
# 更改现有的 postgres 用户 UID 和 GID 为 1000
|
77 |
USER root
|
@@ -79,22 +83,12 @@ RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
|
|
79 |
chown -R postgres:postgres /var/lib/postgresql && \
|
80 |
chown -R postgres:postgres /var/run/postgresql
|
81 |
|
82 |
-
# 切换到 postgres
|
83 |
USER postgres
|
84 |
-
RUN initdb -D /var/lib/postgresql/data && \
|
85 |
-
pg_ctl start -D /var/lib/postgresql/data && \
|
86 |
-
psql --command "CREATE ROLE $POSTGRES_USER WITH LOGIN SUPERUSER PASSWORD '$POSTGRES_PASSWORD';" && \
|
87 |
-
createdb -O $POSTGRES_USER $POSTGRES_DB && \
|
88 |
-
pg_ctl stop -D /var/lib/postgresql/data
|
89 |
-
|
90 |
-
USER root
|
91 |
-
# 添加条件导入的 shell 脚本
|
92 |
-
COPY import-db.sh /docker-entrypoint-initdb.d/
|
93 |
-
RUN chmod +x /docker-entrypoint-initdb.d/import-db.sh
|
94 |
|
95 |
# 健康检查配置(可选)
|
96 |
HEALTHCHECK --interval=120s --timeout=10s --start-period=10s --retries=3 \
|
97 |
CMD curl -f http://localhost:7860/HEALTHZ || exit 1
|
98 |
|
99 |
-
# 启动容器时执行run.sh脚本
|
100 |
-
CMD ["./run.sh"]
|
|
|
5 |
ARG requirements=requests
|
6 |
ARG PACKAGES=n8n
|
7 |
ARG WORKDIR=/app
|
|
|
|
|
8 |
|
9 |
# 安装 Python3、venv 以及必要的系统工具
|
10 |
RUN apt-get update && apt-get install -y python3 python3-venv curl gnupg build-essential && \
|
11 |
npm install -g ${PACKAGES} && \
|
12 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
13 |
|
|
|
|
|
|
|
14 |
# 设置 Python 虚拟环境
|
15 |
ENV VIRTUAL_ENV=/opt/venv
|
16 |
RUN python3 -m venv $VIRTUAL_ENV && \
|
|
|
20 |
# 主运行阶段:基于较小的 PostgreSQL 镜像
|
21 |
FROM postgres:latest
|
22 |
|
23 |
+
# 设置构建时变量
|
24 |
ARG POSTGRES_USER=n8n
|
25 |
ARG POSTGRES_PASSWORD=n8n
|
26 |
ARG POSTGRES_DB=n8n
|
27 |
ARG WEBHOOK_URL=https://aigenai-db.hf.space/
|
28 |
ARG WORKDIR=/app
|
29 |
ARG DB_IMPORT=no
|
30 |
+
ARG NODEJS_VER=20
|
31 |
+
ARG PACKAGES=n8n
|
32 |
+
ARG DUMP_URL
|
33 |
+
ARG DUMP_PASSWORD
|
34 |
|
35 |
+
# 设置环境变量
|
36 |
+
ENV POSTGRES_USER=${POSTGRES_USER} \
|
37 |
+
POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
|
38 |
+
POSTGRES_DB=${POSTGRES_DB} \
|
39 |
+
WEBHOOK_URL=${WEBHOOK_URL} \
|
40 |
+
WORKDIR=${WORKDIR} \
|
41 |
+
DB_IMPORT=${DB_IMPORT} \
|
42 |
+
N8N_HOST=0.0.0.0 \
|
43 |
N8N_PORT=7860 \
|
44 |
N8N_PROTOCOL=https \
|
|
|
45 |
GENERIC_TIMEZONE=Asia/Shanghai \
|
46 |
N8N_METRICS=true \
|
47 |
QUEUE_HEALTH_CHECK_ACTIVE=true \
|
48 |
+
N8N_PAYLOAD_SIZE_MAX=256 \
|
49 |
+
DB_TYPE=postgresdb \
|
|
|
|
|
50 |
DB_POSTGRESDB_HOST=localhost \
|
51 |
DB_POSTGRESDB_PORT=5432 \
|
52 |
DB_POSTGRESDB_USER=${POSTGRES_USER} \
|
53 |
DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} \
|
54 |
+
DB_POSTGRESDB_DATABASE=${POSTGRES_DB} \
|
55 |
+
VIRTUAL_ENV=/opt/venv \
|
56 |
+
PATH="$VIRTUAL_ENV/bin:/usr/local/lib/node_modules/n8n/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
|
|
|
|
|
57 |
|
58 |
# 复制构建阶段的 n8n 和 Python 运行环境
|
|
|
59 |
COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
|
60 |
COPY --from=builder $VIRTUAL_ENV $VIRTUAL_ENV
|
61 |
|
62 |
+
# 安装必要的软件包并设置时区
|
63 |
RUN apt-get update && apt-get install -y \
|
64 |
curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
|
65 |
ca-certificates openssl tzdata python3-venv gosu \
|
|
|
70 |
# 设置工作目录并复制启动脚本
|
71 |
WORKDIR ${WORKDIR}
|
72 |
COPY run.sh ${WORKDIR}/run.sh
|
73 |
+
COPY import-db.sh /docker-entrypoint-initdb.d/
|
74 |
+
RUN chmod +x ${WORKDIR}/run.sh /docker-entrypoint-initdb.d/import-db.sh
|
75 |
+
|
76 |
+
# 保留构建时变量
|
77 |
+
ARG DUMP_URL
|
78 |
+
ARG DUMP_PASSWORD
|
79 |
|
80 |
# 更改现有的 postgres 用户 UID 和 GID 为 1000
|
81 |
USER root
|
|
|
83 |
chown -R postgres:postgres /var/lib/postgresql && \
|
84 |
chown -R postgres:postgres /var/run/postgresql
|
85 |
|
86 |
+
# 切换到 postgres 用户
|
87 |
USER postgres
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
# 健康检查配置(可选)
|
90 |
HEALTHCHECK --interval=120s --timeout=10s --start-period=10s --retries=3 \
|
91 |
CMD curl -f http://localhost:7860/HEALTHZ || exit 1
|
92 |
|
93 |
+
# 启动容器时执行 run.sh 脚本
|
94 |
+
CMD ["./run.sh"]
|