diff --git a/Dockerfile b/Dockerfile index a5b17e2..d8299ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,9 +29,11 @@ ARG BUILD_TIME WORKDIR /app +# Go mod files COPY go.mod go.sum ./ RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download +# Copy backend source COPY . . # Copy frontend dist @@ -61,11 +63,6 @@ RUN sed -i 's@deb.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.li && python3 -m venv /opt/venv \ && /opt/venv/bin/pip install --upgrade pip \ && /opt/venv/bin/pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \ - # 设置虚拟环境 Python 为系统默认 - && update-alternatives --install /usr/bin/python python /opt/venv/bin/python 1 \ - && update-alternatives --install /usr/bin/python3 python3 /opt/venv/bin/python 1 \ - && update-alternatives --install /usr/bin/pip pip /opt/venv/bin/pip 1 \ - && update-alternatives --install /usr/bin/pip3 pip3 /opt/venv/bin/pip 1 \ && rm -rf /var/lib/apt/lists/* WORKDIR /app @@ -83,4 +80,4 @@ RUN chmod +x docker-entrypoint.sh EXPOSE 8052 -CMD ["./docker-entrypoint.sh"] +ENTRYPOINT ["./docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2d5b2ad..e37c85f 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,22 +1,33 @@ #!/bin/sh -# 创建必要的目录 +# ============================ +# 激活 Python 虚拟环境 +# ============================ +if [ -d /opt/venv ]; then + export PATH="/opt/venv/bin:$PATH" +fi + +# ============================ +# 创建必要目录 +# ============================ mkdir -p /app/data /app/data/scripts /app/configs -# 如果数据库文件存在,设置不可变属性防止误删 +# ============================ +# 设置不可变属性 +# ============================ if [ -f /app/data/ql.db ]; then chattr +i /app/data/ql.db 2>/dev/null || true fi -# 如果 configs 目录存在,设置不可变属性 if [ -d /app/configs ]; then chattr +i /app/configs 2>/dev/null || true fi -# 如果 scripts 目录存在,设置不可变属性 if [ -d /app/data/scripts ]; then chattr +i /app/data/scripts 2>/dev/null || true fi +# ============================ # 启动应用 +# ============================ exec ./baihu