File size: 2,488 Bytes
18b2392 71f6342 18b2392 71f6342 c93dbc8 71f6342 242b7bb 7f49ed9 18b2392 242b7bb 40c7d94 4dd70a2 c93dbc8 79c3846 40c7d94 c93dbc8 40c7d94 c93dbc8 79c3846 c93dbc8 79c3846 7f49ed9 79c3846 7f49ed9 997d703 7f49ed9 13cb3b2 71f6342 7f49ed9 71f6342 7f49ed9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 使用 PostgreSQL 官方镜像
FROM postgres:latest
# 设置环境变量,用于数据库配置
ENV POSTGRES_USER=myuser \
POSTGRES_PASSWORD=mypassword \
POSTGRES_DB=mydatabase \
VIRTUAL_ENV=/opt/venv \
PATH="$VIRTUAL_ENV/bin:$PATH"
ENV N8N_HOST=0.0.0.0
ENV N8N_PORT=7860
ENV N8N_PROTOCOL=https
ENV WEBHOOK_URL=https://aigenai-db.hf.space/
ENV GENERIC_TIMEZONE=Asia/Shanghai
ENV N8N_METRICS=true
ENV QUEUE_HEALTH_CHECK_ACTIVE=true
ENV N8N_PAYLOAD_SIZE_MAX=256
# 将应用程序代码和启动脚本复制到容器中
COPY run.sh /app/run.sh
# 切换到 root 用户进行安装和用户修改
USER root
# 设置脚本可执行权限
RUN chmod +x /app/run.sh
# 更新包管理器并安装必要软件包,包括 Python3、venv、curl、Node.js、n8n
RUN apt-get update && apt-get install -y curl unzip gnupg build-essential sudo vim git procps lsof net-tools ca-certificates openssl tzdata python3-venv gosu && \
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
dpkg-reconfigure --frontend noninteractive tzdata && \
# 安装 Node.js 及 n8n
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs && \
npm install -g n8n && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
# 创建虚拟环境并安装 Python 包
python3 -m venv $VIRTUAL_ENV && \
$VIRTUAL_ENV/bin/pip install --upgrade pip && \
$VIRTUAL_ENV/bin/pip install psycopg2-binary && \
# 更改现有的 postgres 用户 UID 和 GID 为 1000
usermod -u 1000 postgres && groupmod -g 1000 postgres && \
# 修正数据库目录的所有者和组,确保新 UID 和 GID 能正常访问
chown -R postgres:postgres /var/lib/postgresql && \
chown -R postgres:postgres /var/run/postgresql
# 切换到 postgres 用户,初始化数据库并创建角色
USER postgres
# 初始化 PostgreSQL 数据库,并创建指定的用户角色和数据库
RUN initdb -D /var/lib/postgresql/data && \
pg_ctl start -D /var/lib/postgresql/data && \
psql --command "CREATE ROLE $POSTGRES_USER WITH LOGIN SUPERUSER PASSWORD '$POSTGRES_PASSWORD';" && \
createdb -O $POSTGRES_USER $POSTGRES_DB && \
pg_ctl stop -D /var/lib/postgresql/data
# 设置工作目录
WORKDIR /app
# 启动容器时执行run.sh脚本
CMD ["./run.sh"]
# 设置健康检查以确保 Flask 应用正常运行
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1
|