hijnu commited on
Commit
1e427ce
·
verified ·
1 Parent(s): 7ba33e3

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +31 -41
Dockerfile CHANGED
@@ -1,25 +1,23 @@
1
  # 使用 PostgreSQL 作为基础镜像
2
- FROM postgres:latest
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 NODE_PACKAGES="n8n"
15
  ARG PYTHON_PACKAGES="requests yt-dlp"
16
 
17
- # 设置环境变量
18
- ENV POSTGRES_USER=${POSTGRES_USER} \
19
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
20
- POSTGRES_DB=${POSTGRES_DB} \
21
- WEBHOOK_URL=${WEBHOOK_URL} \
22
- DB_IMPORT=${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:$PATH"
38
 
39
- # 安装必要的软件包、Node.js,Python,并设置时区
40
- RUN apt-get update && apt-get install -y \
41
- curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
42
- ca-certificates openssl tzdata python3 python3-venv python3-pip gosu \
43
- htop jq wget && \
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
- # 安装 rclone
53
- curl https://rclone.org/install.sh | bash && \
54
- # 清理 apt 缓存
55
- apt-get clean && rm -rf /var/lib/apt/lists/*
56
-
57
- # 设置 Python 虚拟环境
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
- # 更改现有的 postgres 用户 UID 和 GID 为 1000
69
- USER root
70
  RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
71
- chown -R postgres:postgres /var/lib/postgresql && \
72
- chown -R postgres:postgres /var/run/postgresql && \
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=120s --timeout=10s --start-period=10s --retries=3 \
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"]