From 74f845b06d878b041564fffa472688829bffc18f Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Mon, 3 Nov 2025 02:41:40 +0800 Subject: [PATCH] Chore: Dockerfile (#3266) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Dockerfile python main.py 改为uv run main.py * fix(dockerfile): 减少重复安装 * fix: 修复一些细节问题 * fix(.dockerignore): 需要git文件夹以获取astrbot版本(带git commit hash后缀) * fix(.dockerignore): uv run之前会uv sync --- .dockerignore | 4 +--- Dockerfile | 19 +++++++++++-------- Dockerfile_with_node | 27 ++++++++++++++++----------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/.dockerignore b/.dockerignore index 30bd2e249..8638bf3f6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,8 @@ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 -# github acions +# github actions .github/ .*ignore -.git/ # User-specific stuff .idea/ # Byte-compiled / optimized / DLL files @@ -15,7 +14,6 @@ env/ venv*/ ENV/ .conda/ -README*.md dashboard/ data/ changelogs/ diff --git a/Dockerfile b/Dockerfile index df48b2be2..1f3fa3eb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,19 +12,22 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ bash \ ffmpeg \ + nodejs \ + curl \ + gnupg \ + git \ && apt-get clean \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -RUN apt-get update && apt-get install -y curl gnupg && \ - curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \ - apt-get install -y nodejs && \ +RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \ + apt-get install -y --no-install-recommends nodejs && \ + echo "3.11" > .python-version && \ rm -rf /var/lib/apt/lists/* -RUN python -m pip install uv -RUN uv pip install -r requirements.txt --no-cache-dir --system -RUN uv pip install socksio uv pilk --no-cache-dir --system +RUN python -m pip install --no-cache-dir uv && \ + uv pip install socksio pilk --no-cache-dir --system EXPOSE 6185 EXPOSE 6186 -CMD [ "python", "main.py" ] +CMD ["uv", "run", "main.py"] \ No newline at end of file diff --git a/Dockerfile_with_node b/Dockerfile_with_node index 3bd37468a..1f0b3a749 100644 --- a/Dockerfile_with_node +++ b/Dockerfile_with_node @@ -1,4 +1,4 @@ -FROM python:3.10-slim +FROM python:3.11-slim WORKDIR /AstrBot @@ -14,22 +14,27 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ unzip \ ca-certificates \ bash \ + git \ && apt-get clean \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -# Installation of Node.js -ENV NVM_DIR="/root/.nvm" +ENV NVM_DIR="/root/.nvm" \ + NODE_VERSION=22 RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | bash && \ . "$NVM_DIR/nvm.sh" && \ - nvm install 22 && \ - nvm use 22 -RUN /bin/bash -c ". \"$NVM_DIR/nvm.sh\" && node -v && npm -v" + nvm install $NODE_VERSION && \ + nvm use $NODE_VERSION && \ + nvm alias default $NODE_VERSION && \ + node -v && npm -v && \ + echo "3.11" > .python-version +ENV PATH="$NVM_DIR/versions/node/v$(node -v | cut -d 'v' -f 2)/bin:$PATH" -RUN python -m pip install uv -RUN uv pip install -r requirements.txt --no-cache-dir --system -RUN uv pip install socksio uv pyffmpeg --no-cache-dir --system +RUN python -m pip install --no-cache-dir uv + +# 安装项目依赖(根据指南,使用 uv sync) +RUN uv sync --no-cache EXPOSE 6185 EXPOSE 6186 -CMD ["python", "main.py"] +CMD ["uv", "run", "main.py"] \ No newline at end of file