From b6964a92fac50b09b26d86afc5c92b55b8beb977 Mon Sep 17 00:00:00 2001 From: BalconyJH <73932916+BalconyJH@users.noreply.github.com> Date: Fri, 13 Dec 2024 02:07:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=98=B6=E6=AE=B5=E6=9E=84=E5=BB=BADo?= =?UTF-8?q?cker=E9=95=9C=E5=83=8F=EF=BC=8C=E7=B2=BE=E7=AE=80=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=95=9C=E5=83=8F=E4=BD=93=E7=A7=AF=20(#1752)=20(#176?= =?UTF-8?q?4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🚀 更新Dockerfile (#1752) * :see_no_evil: 忽略文件夹 * :construction_worker: 更新 Dockerfile --------- Co-authored-by: fanyinrumeng <42991257+fanyinrumeng@users.noreply.github.com> --- .dockerignore | 7 ++++- Dockerfile | 71 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/.dockerignore b/.dockerignore index 5d0f2bf2..c5602018 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,11 @@ .devcontainer/ .github/ .vscode/ -assets/ +.idea/ +.pytest_cache/ +.ruff_cache/ +.venv/ +docs_image/ k8s/ tests/ .dockerignore @@ -9,6 +13,7 @@ tests/ .gitignore .pre-commit-config.yaml .prettier* +.env.dev docker-compose.yml Dockerfile LICENSE diff --git a/Dockerfile b/Dockerfile index 343d4d96..acdbd5fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,67 @@ -FROM python:3.11-slim-bookworm +FROM python:3.11-bookworm AS requirements-stage -EXPOSE 8080 +WORKDIR /tmp + +ENV POETRY_HOME="/opt/poetry" PATH="${PATH}:/opt/poetry/bin" + +RUN curl -sSL https://install.python-poetry.org | python - -y && \ + poetry self add poetry-plugin-export + +COPY ./pyproject.toml ./poetry.lock* /tmp/ + +RUN poetry export \ + -f requirements.txt \ + --output requirements.txt \ + --without-hashes \ + --without-urls + +FROM python:3.11-bookworm AS build-stage + +WORKDIR /wheel + +COPY --from=requirements-stage /tmp/requirements.txt /wheel/requirements.txt + +# RUN python3 -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple + +RUN pip wheel --wheel-dir=/wheel --no-cache-dir --requirement /wheel/requirements.txt + +FROM python:3.11-bookworm AS metadata-stage + +WORKDIR /tmp + +RUN --mount=type=bind,source=./.git/,target=/tmp/.git/ \ + git describe --tags --exact-match > /tmp/VERSION 2>/dev/null \ + || git rev-parse --short HEAD > /tmp/VERSION \ + && echo "Building version: $(cat /tmp/VERSION)" + +FROM python:3.11-slim-bookworm WORKDIR /app/zhenxun -COPY . /app/zhenxun +ENV TZ=Asia/Shanghai PYTHONUNBUFFERED=1 +#COPY ./scripts/docker/start.sh /start.sh +#RUN chmod +x /start.sh + +EXPOSE 8080 RUN apt update && \ - apt upgrade -y && \ - apt install -y --no-install-recommends \ - gcc \ - g++ && \ - apt clean + apt install -y --no-install-recommends curl fontconfig fonts-noto-color-emoji \ + && apt clean \ + && fc-cache -fv \ + && apt-get purge -y --auto-remove curl \ + && rm -rf /var/lib/apt/lists/* -RUN pip install poetry -i https://mirrors.aliyun.com/pypi/simple/ +# 复制依赖项和应用代码 +COPY --from=build-stage /wheel /wheel +COPY . . -RUN poetry install +RUN pip install --no-cache-dir --no-index --find-links=/wheel -r /wheel/requirements.txt && rm -rf /wheel -VOLUME /app/zhenxun/data /app/zhenxun/data +RUN playwright install --with-deps chromium \ + && rm -rf /var/lib/apt/lists/* /tmp/* -VOLUME /app/zhenxun/resources /app/zhenxun/resources +COPY --from=metadata-stage /tmp/VERSION /app/VERSION -VOLUME /app/zhenxun/.env.dev /app/zhenxun/.env.dev +VOLUME ["/app/zhenxun/data", "/app/zhenxun/resources", "/app/zhenxun/log"] -RUN poetry run playwright install --with-deps chromium - -CMD ["poetry", "run", "python", "bot.py"] +CMD ["python", "bot.py"]