Update Dockerfile
Browse files- Dockerfile +31 -41
Dockerfile
CHANGED
@@ -1,25 +1,23 @@
|
|
1 |
# 使用 PostgreSQL 作为基础镜像
|
2 |
-
FROM postgres:
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
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 NODE_PACKAGES="n8n"
|
15 |
ARG PYTHON_PACKAGES="requests yt-dlp"
|
16 |
|
17 |
-
#
|
18 |
-
ENV POSTGRES_USER
|
19 |
-
POSTGRES_PASSWORD
|
20 |
-
POSTGRES_DB
|
21 |
-
WEBHOOK_URL
|
22 |
-
DB_IMPORT
|
23 |
N8N_HOST=0.0.0.0 \
|
24 |
N8N_PORT=7860 \
|
25 |
N8N_PROTOCOL=https \
|
@@ -34,30 +32,25 @@ ENV POSTGRES_USER=${POSTGRES_USER} \
|
|
34 |
DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} \
|
35 |
DB_POSTGRESDB_DATABASE=${POSTGRES_DB} \
|
36 |
VIRTUAL_ENV=$WORKDIR/venv \
|
37 |
-
PATH="$WORKDIR/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
38 |
|
39 |
-
#
|
40 |
-
RUN apt-get update && apt-get install -y \
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
# 安装 Node.js
|
45 |
curl -fsSL https://deb.nodesource.com/setup_${NODEJS_VER}.x | bash - && \
|
46 |
apt-get install -y nodejs && \
|
47 |
-
# 安装全局 Node.js 包
|
48 |
npm install -g ${NODE_PACKAGES} && \
|
49 |
-
|
50 |
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
51 |
dpkg-reconfigure --frontend noninteractive tzdata && \
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
apt-get clean &&
|
56 |
-
|
57 |
-
|
58 |
-
RUN python3 -m venv $VIRTUAL_ENV && \
|
59 |
-
$VIRTUAL_ENV/bin/pip install --upgrade pip && \
|
60 |
-
$VIRTUAL_ENV/bin/pip install ${PYTHON_PACKAGES}
|
61 |
|
62 |
# 设置工作目录并复制启动脚本
|
63 |
WORKDIR ${WORKDIR}
|
@@ -65,20 +58,17 @@ COPY run.sh ${WORKDIR}/run.sh
|
|
65 |
COPY import-db.sh /docker-entrypoint-initdb.d/
|
66 |
RUN chmod +x ${WORKDIR}/run.sh /docker-entrypoint-initdb.d/import-db.sh
|
67 |
|
68 |
-
#
|
69 |
-
USER root
|
70 |
RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
|
71 |
-
chown -R postgres:postgres /var/lib/postgresql && \
|
72 |
-
|
73 |
-
chown -R postgres:postgres $WORKDIR && \
|
74 |
-
mkdir -p $WORKDIR/backups && chmod -R 775 $WORKDIR/backups
|
75 |
|
76 |
# 切换到 postgres 用户
|
77 |
USER postgres
|
78 |
|
79 |
# 健康检查配置
|
80 |
-
HEALTHCHECK --interval=
|
81 |
-
CMD curl -f http://localhost:7860/HEALTHZ || exit 1
|
82 |
|
83 |
# 启动容器时执行 run.sh 脚本
|
84 |
CMD ["./run.sh"]
|
|
|
1 |
# 使用 PostgreSQL 作为基础镜像
|
2 |
+
FROM postgres:14
|
3 |
|
4 |
+
# 元数据
|
5 |
+
LABEL maintainer="B站ai来事 <aiflow@petalmail.com>"
|
6 |
+
LABEL version="2.0"
|
7 |
+
LABEL description="Custom image with PostgreSQL, Node.js, and Python for n8n"
|
8 |
+
|
9 |
+
# 构建参数
|
|
|
10 |
ARG WORKDIR=/app
|
|
|
11 |
ARG NODEJS_VER=20
|
12 |
ARG NODE_PACKAGES="n8n"
|
13 |
ARG PYTHON_PACKAGES="requests yt-dlp"
|
14 |
|
15 |
+
# 环境变量
|
16 |
+
ENV POSTGRES_USER=n8n \
|
17 |
+
POSTGRES_PASSWORD=n8n \
|
18 |
+
POSTGRES_DB=n8n \
|
19 |
+
WEBHOOK_URL=https://aigenai-db.hf.space/ \
|
20 |
+
DB_IMPORT=no \
|
21 |
N8N_HOST=0.0.0.0 \
|
22 |
N8N_PORT=7860 \
|
23 |
N8N_PROTOCOL=https \
|
|
|
32 |
DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} \
|
33 |
DB_POSTGRESDB_DATABASE=${POSTGRES_DB} \
|
34 |
VIRTUAL_ENV=$WORKDIR/venv \
|
35 |
+
PATH="$WORKDIR/venv/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
36 |
|
37 |
+
# 安装依赖和设置环境
|
38 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
39 |
+
curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
|
40 |
+
ca-certificates openssl tzdata python3 python3-venv python3-pip gosu \
|
41 |
+
htop jq wget && \
|
|
|
42 |
curl -fsSL https://deb.nodesource.com/setup_${NODEJS_VER}.x | bash - && \
|
43 |
apt-get install -y nodejs && \
|
|
|
44 |
npm install -g ${NODE_PACKAGES} && \
|
45 |
+
curl https://rclone.org/install.sh | bash && \
|
46 |
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
47 |
dpkg-reconfigure --frontend noninteractive tzdata && \
|
48 |
+
python3 -m venv $VIRTUAL_ENV && \
|
49 |
+
$VIRTUAL_ENV/bin/pip install --no-cache-dir --upgrade pip && \
|
50 |
+
$VIRTUAL_ENV/bin/pip install --no-cache-dir ${PYTHON_PACKAGES} && \
|
51 |
+
apt-get clean && \
|
52 |
+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
|
53 |
+
npm cache clean --force
|
|
|
|
|
|
|
54 |
|
55 |
# 设置工作目录并复制启动脚本
|
56 |
WORKDIR ${WORKDIR}
|
|
|
58 |
COPY import-db.sh /docker-entrypoint-initdb.d/
|
59 |
RUN chmod +x ${WORKDIR}/run.sh /docker-entrypoint-initdb.d/import-db.sh
|
60 |
|
61 |
+
# 设置用户和权限
|
|
|
62 |
RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
|
63 |
+
chown -R postgres:postgres /var/lib/postgresql /var/run/postgresql ${WORKDIR} && \
|
64 |
+
mkdir -p ${WORKDIR}/backups && chmod -R 775 ${WORKDIR}/backups
|
|
|
|
|
65 |
|
66 |
# 切换到 postgres 用户
|
67 |
USER postgres
|
68 |
|
69 |
# 健康检查配置
|
70 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
71 |
+
CMD pg_isready && curl -f http://localhost:7860/HEALTHZ || exit 1
|
72 |
|
73 |
# 启动容器时执行 run.sh 脚本
|
74 |
CMD ["./run.sh"]
|