feat: replace pip with uv in Dockerfile
- Use uv 0.10.7 with pyproject.toml + uv.lock instead of pip + requirements.txt - Bind mounts for pyproject.toml/uv.lock with BuildKit cache for faster rebuilds - UV_COMPILE_BYTECODE=1 for pre-compiled .pyc, UV_LINK_MODE=copy for multi-stage - UV_PYTHON_DOWNLOADS=never to prevent uv from downloading its own Python - Replace wget healthcheck with Python stdlib (removes apt layer from runtime) - Increase start-period to 60s for migration headroom - Fix redundant chown -R on entire /app - Add .venv, tests, .mypy_cache, .ruff_cache to .dockerignore
This commit is contained in:
@@ -16,6 +16,10 @@ __pycache__/
|
|||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
.coverage
|
.coverage
|
||||||
htmlcov/
|
htmlcov/
|
||||||
|
.venv/
|
||||||
|
tests/
|
||||||
|
.mypy_cache/
|
||||||
|
.ruff_cache/
|
||||||
|
|
||||||
# Environment files
|
# Environment files
|
||||||
.env
|
.env
|
||||||
|
|||||||
+15
-16
@@ -4,13 +4,18 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
gcc \
|
gcc \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN python -m venv /opt/venv
|
COPY --from=ghcr.io/astral-sh/uv:0.10.7 /uv /uvx /bin/
|
||||||
ENV PATH="/opt/venv/bin:$PATH"
|
|
||||||
|
|
||||||
COPY requirements.txt .
|
ENV UV_COMPILE_BYTECODE=1 \
|
||||||
|
UV_LINK_MODE=copy \
|
||||||
|
UV_PYTHON_DOWNLOADS=never
|
||||||
|
|
||||||
RUN pip install --no-cache-dir --upgrade pip && \
|
WORKDIR /app
|
||||||
pip install --no-cache-dir -r requirements.txt
|
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
|
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
||||||
|
--mount=type=bind,source=uv.lock,target=uv.lock \
|
||||||
|
uv sync --locked --no-dev
|
||||||
|
|
||||||
FROM python:3.13-slim
|
FROM python:3.13-slim
|
||||||
|
|
||||||
@@ -18,13 +23,8 @@ ARG VERSION="v3.18.0" # x-release-please-version
|
|||||||
ARG BUILD_DATE
|
ARG BUILD_DATE
|
||||||
ARG VCS_REF
|
ARG VCS_REF
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
COPY --from=builder /app/.venv /app/.venv
|
||||||
wget \
|
ENV PATH="/app/.venv/bin:$PATH"
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
|
||||||
&& apt-get clean
|
|
||||||
|
|
||||||
COPY --from=builder /opt/venv /opt/venv
|
|
||||||
ENV PATH="/opt/venv/bin:$PATH"
|
|
||||||
|
|
||||||
RUN groupadd -g 1000 app && \
|
RUN groupadd -g 1000 app && \
|
||||||
useradd -u 1000 -g 1000 -m -s /bin/bash app
|
useradd -u 1000 -g 1000 -m -s /bin/bash app
|
||||||
@@ -33,8 +33,7 @@ WORKDIR /app
|
|||||||
|
|
||||||
COPY --chown=app:app . .
|
COPY --chown=app:app . .
|
||||||
|
|
||||||
RUN mkdir -p logs data && \
|
RUN mkdir -p logs data && chown app:app logs data
|
||||||
chown -R app:app /app logs data
|
|
||||||
|
|
||||||
USER app
|
USER app
|
||||||
|
|
||||||
@@ -56,7 +55,7 @@ LABEL org.opencontainers.image.title="Bedolaga RemnaWave Bot" \
|
|||||||
org.opencontainers.image.url="https://github.com/fr1ngg/remnawave-bedolaga-telegram-bot" \
|
org.opencontainers.image.url="https://github.com/fr1ngg/remnawave-bedolaga-telegram-bot" \
|
||||||
org.opencontainers.image.vendor="fr1ngg"
|
org.opencontainers.image.vendor="fr1ngg"
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||||
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8080/health')" || exit 1
|
||||||
|
|
||||||
CMD ["python", "main.py"]
|
CMD ["python", "main.py"]
|
||||||
|
|||||||
Reference in New Issue
Block a user