Tests im Dockerfile statt über setup-python
actions/setup-python@v5 lädt seine Runtime von GitHub-Releases und scheitert auf dem Gitea-Runner - der Lauf brach vor dem Deploy ab. Die Tests laufen jetzt in einer eigenen Dockerfile-Stufe, die der Workflow mit --target test aufruft. Damit gilt für sie dieselbe Python-Version und derselbe Paketstand wie für die Produktion, und der Schritt braucht nichts außer dem Docker-Daemon, den der Runner ohnehin nutzt. Ein Bind-Mount des Workspace wäre keine Option gewesen: der liegt im Job-Container, der Pfad zeigt auf dem Host ins Leere. Die Teststufe hängt nicht am finalen Image und wird beim Deploy-Build übersprungen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
15
Dockerfile
15
Dockerfile
@@ -1,11 +1,26 @@
|
||||
# Abhaengigkeiten in ein venv bauen, damit der Compiler-Ballast nicht ins
|
||||
# fertige Image wandert.
|
||||
FROM python:3.12-slim AS build
|
||||
WORKDIR /app
|
||||
RUN python -m venv /opt/venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Testlauf gegen dieselbe Python-Version und dieselben Pakete wie die
|
||||
# Produktion. Die Stufe haengt nicht am finalen Image und wird bei einem
|
||||
# normalen Build uebersprungen; der Workflow ruft sie mit --target test auf.
|
||||
FROM build AS test
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends libglib2.0-0 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
COPY requirements-dev.txt .
|
||||
RUN pip install --no-cache-dir -r requirements-dev.txt
|
||||
COPY app ./app
|
||||
COPY static ./static
|
||||
COPY tests ./tests
|
||||
RUN pytest -q
|
||||
|
||||
FROM python:3.12-slim
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
|
||||
Reference in New Issue
Block a user