hijnu commited on
Commit
bb7a720
1 Parent(s): b3e4b70

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -66
Dockerfile CHANGED
@@ -2,34 +2,25 @@
2
  FROM node:20-slim AS builder
3
 
4
  # 设置构建时变量
5
- ARG REQUIREMENTS="requests yt-dlp"
6
  ARG PACKAGES="n8n"
7
  ARG WORKDIR=/app
8
- ARG RCLONE_VERSION=latest
 
9
 
10
  # 安装 Python3、venv 以及必要的系统工具
11
- RUN apt-get update && apt-get install -y --no-install-recommends \
12
- python3 \
13
- python3-venv \
14
- curl \
15
- gnupg \
16
- build-essential \
17
- unzip \
18
- && npm install -g ${PACKAGES} \
19
- && apt-get clean \
20
- && rm -rf /var/lib/apt/lists/*
21
 
22
  # 设置 Python 虚拟环境
23
  ENV VIRTUAL_ENV=/opt/venv
24
- RUN python3 -m venv $VIRTUAL_ENV \
25
- && $VIRTUAL_ENV/bin/pip install --no-cache-dir --upgrade pip \
26
- && $VIRTUAL_ENV/bin/pip install --no-cache-dir $REQUIREMENTS
27
 
28
- # 下载并安装 rclone
29
- RUN curl https://rclone.org/install.sh | bash
30
-
31
- # 主运行阶段:基于 PostgreSQL 镜像
32
- FROM postgres:15
33
 
34
  # 设置构建时变量
35
  ARG POSTGRES_USER=n8n
@@ -39,10 +30,9 @@ ARG WEBHOOK_URL=https://aigenai-db.hf.space/
39
  ARG WORKDIR=/app
40
  ARG DB_IMPORT=no
41
  ARG NODEJS_VER=20
42
- ARG PACKAGES=n8n
43
 
44
  # 设置环境变量
45
- ENV DB_IMPORT=no
46
  ENV POSTGRES_USER=${POSTGRES_USER} \
47
  POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
48
  POSTGRES_DB=${POSTGRES_DB} \
@@ -65,36 +55,22 @@ ENV POSTGRES_USER=${POSTGRES_USER} \
65
  VIRTUAL_ENV=/opt/venv \
66
  PATH="$VIRTUAL_ENV/bin:/usr/local/lib/node_modules/n8n/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
67
 
68
- # 复制构建阶段的 Node.js、n8n、Python 运行环境和 rclone
69
  COPY --from=builder /usr/local/bin/node /usr/local/bin/
70
  COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
 
71
  COPY --from=builder $VIRTUAL_ENV $VIRTUAL_ENV
72
- COPY --from=builder /usr/bin/rclone /usr/bin/rclone
73
 
74
  # 安装必要的软件包并设置时区
75
- RUN apt-get update && apt-get install -y --no-install-recommends \
76
- curl \
77
- unzip \
78
- gnupg \
79
- build-essential \
80
- sudo \
81
- vim \
82
- git \
83
- procps \
84
- lsof \
85
- net-tools \
86
- ca-certificates \
87
- openssl \
88
- tzdata \
89
- python3 \
90
- htop \
91
- jq \
92
- wget \
93
- gosu \
94
- && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
95
- && echo "Asia/Shanghai" > /etc/timezone \
96
- && apt-get clean \
97
- && rm -rf /var/lib/apt/lists/*
98
 
99
  # 设置工作目录并复制启动脚本
100
  WORKDIR ${WORKDIR}
@@ -102,28 +78,18 @@ COPY run.sh ${WORKDIR}/run.sh
102
  COPY import-db.sh /docker-entrypoint-initdb.d/
103
  RUN chmod +x ${WORKDIR}/run.sh /docker-entrypoint-initdb.d/import-db.sh
104
 
105
- # 设置 POSTGRES_USER UID 为 1000
106
- RUN usermod -u 1000 ${POSTGRES_USER} \
107
- && groupmod -g 1000 ${POSTGRES_USER} \
108
- && chown -R ${POSTGRES_USER}:${POSTGRES_USER} /var/lib/postgresql \
109
- && chown -R ${POSTGRES_USER}:${POSTGRES_USER} /var/run/postgresql \
110
- && chown -R ${POSTGRES_USER}:${POSTGRES_USER} ${WORKDIR} \
111
- && mkdir -p ${WORKDIR}/backups \
112
- && chown -R ${POSTGRES_USER}:${POSTGRES_USER} ${WORKDIR}/backups \
113
- && chmod -R 775 ${WORKDIR}/backups
114
 
115
- # 设置 POSTGRES_USER 的 shell 为 bash
116
- RUN chsh -s /bin/bash ${POSTGRES_USER}
117
-
118
- # 健康检查配置
119
  HEALTHCHECK --interval=120s --timeout=10s --start-period=10s --retries=3 \
120
  CMD curl -f http://localhost:7860/HEALTHZ || exit 1
121
 
122
- # 暴露 n8n 端口
123
- EXPOSE 7860
124
-
125
- # 切换到 POSTGRES_USER
126
- USER ${POSTGRES_USER}
127
-
128
  # 启动容器时执行 run.sh 脚本
129
  CMD ["./run.sh"]
 
2
  FROM node:20-slim AS builder
3
 
4
  # 设置构建时变量
5
+ ARG requirements="requests yt-dlp"
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
  # 设置 Python 虚拟环境
17
  ENV VIRTUAL_ENV=/opt/venv
18
+ RUN python3 -m venv $VIRTUAL_ENV && \
19
+ $VIRTUAL_ENV/bin/pip install --upgrade pip && \
20
+ $VIRTUAL_ENV/bin/pip install $requirements
21
 
22
+ # 主运行阶段:基于较小的 PostgreSQL 镜像
23
+ FROM postgres:latest
 
 
 
24
 
25
  # 设置构建时变量
26
  ARG POSTGRES_USER=n8n
 
30
  ARG WORKDIR=/app
31
  ARG DB_IMPORT=no
32
  ARG NODEJS_VER=20
33
+ ARG PACKAGES="n8n"
34
 
35
  # 设置环境变量
 
36
  ENV POSTGRES_USER=${POSTGRES_USER} \
37
  POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
38
  POSTGRES_DB=${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
+ # 复制构建阶段的 Node.js n8n
59
  COPY --from=builder /usr/local/bin/node /usr/local/bin/
60
  COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
61
+ # 复制构建阶段的 Python 运行环境
62
  COPY --from=builder $VIRTUAL_ENV $VIRTUAL_ENV
 
63
 
64
  # 安装必要的软件包并设置时区
65
+ RUN apt-get update && apt-get install -y \
66
+ curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
67
+ ca-certificates openssl tzdata python3-venv gosu \
68
+ htop jq wget && \
69
+ ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
70
+ dpkg-reconfigure --frontend noninteractive tzdata
71
+
72
+ # 安装 rclone
73
+ RUN curl https://rclone.org/install.sh | bash
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  # 设置工作目录并复制启动脚本
76
  WORKDIR ${WORKDIR}
 
78
  COPY import-db.sh /docker-entrypoint-initdb.d/
79
  RUN chmod +x ${WORKDIR}/run.sh /docker-entrypoint-initdb.d/import-db.sh
80
 
81
+ # 更改现有的 postgres 用户 UID 和 GID 为 1000
82
+ USER root
83
+ RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
84
+ chown -R postgres:postgres /var/lib/postgresql && chown -R postgres:postgres /var/run/postgresql && \
85
+ chown -R postgres:postgres $WORKDIR && mkdir -p $WORKDIR/backups && chmod -R 775 $WORKDIR/backups
86
+
87
+ # 切换到 postgres 用户
88
+ USER postgres
 
89
 
90
+ # 健康检查配置(可选)
 
 
 
91
  HEALTHCHECK --interval=120s --timeout=10s --start-period=10s --retries=3 \
92
  CMD curl -f http://localhost:7860/HEALTHZ || exit 1
93
 
 
 
 
 
 
 
94
  # 启动容器时执行 run.sh 脚本
95
  CMD ["./run.sh"]