zhenxun_bot/Dockerfile

68 lines
1.8 KiB
Docker
Raw Normal View History

FROM python:3.11-bookworm AS requirements-stage
2024-08-14 13:35:03 +08:00
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
2024-08-14 13:35:03 +08:00
WORKDIR /app/zhenxun
ENV TZ=Asia/Shanghai PYTHONUNBUFFERED=1
#COPY ./scripts/docker/start.sh /start.sh
#RUN chmod +x /start.sh
2024-08-14 13:35:03 +08:00
EXPOSE 8080
2024-09-02 23:12:27 +08:00
RUN apt update && \
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/*
2024-08-14 13:35:03 +08:00
# 复制依赖项和应用代码
COPY --from=build-stage /wheel /wheel
COPY . .
2024-08-14 13:35:03 +08:00
RUN pip install --no-cache-dir --no-index --find-links=/wheel -r /wheel/requirements.txt && rm -rf /wheel
2024-08-14 13:35:03 +08:00
RUN playwright install --with-deps chromium \
&& rm -rf /var/lib/apt/lists/* /tmp/*
2024-08-14 13:35:03 +08:00
COPY --from=metadata-stage /tmp/VERSION /app/VERSION
2024-09-02 23:12:27 +08:00
VOLUME ["/app/zhenxun/data", "/app/zhenxun/resources", "/app/zhenxun/log"]
2024-08-14 13:35:03 +08:00
CMD ["python", "bot.py"]