Update Dockerfile and add comments in pyproject.toml

This commit is contained in:
2025-01-23 18:39:47 +01:00
parent 62b200d131
commit bf5c08346e
4 changed files with 51 additions and 49 deletions

View File

@ -1,48 +1,13 @@
FROM python:3.12-slim as base
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV POETRY_VIRTUALENVS_IN_PROJECT=1
ENV POETRY_NO_INTERACTION=1
ENV POETRY_HOME=/opt/poetry
ENV PYSETUP_PATH=/opt/pysetup
ENV VENV_PATH="/opt/pysetup/.venv"
ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100
FROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONFAULTHANDLER=1
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
ENV PYTHONPATH="${PYTHONPATH}:/discord_reminder_bot"
FROM base as python-deps
RUN apt-get update && \
apt-get install -y --no-install-recommends curl build-essential
RUN --mount=type=cache,target=/root/.cache \
curl -sSL https://install.python-poetry.org | python3 -
WORKDIR $PYSETUP_PATH
COPY pyproject.toml ./
RUN --mount=type=cache,target=/root/.cache \
poetry install --only main
FROM base as runtime
# Copy virtual env from python-deps stage
COPY --from=python-deps $PYSETUP_PATH $PYSETUP_PATH
# Create directory for the sqlite database.
RUN mkdir -p /home/botuser/data
# Copy source code
COPY discord_reminder_bot /home/botuser/discord_reminder_bot/
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN useradd -m botuser && mkdir -p /home/botuser/data
WORKDIR /home/botuser
COPY interactions /home/botuser/interactions
COPY discord_reminder_bot /home/botuser/discord_reminder_bot
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --no-install-project
VOLUME ["/home/botuser/data/"]
# Run bot.
CMD [ "python", "/home/botuser/discord_reminder_bot/main.py" ]
CMD ["uv", "run", "discord_reminder_bot/main.py"]