From 96bcebdb40f93254baa41ddf1cbf5672df2630dd Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Tue, 10 Feb 2026 22:57:42 +0000 Subject: [PATCH] Cache test image to speed up CI backend test step MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a 'test' stage to Dockerfile that extends runtime-base with the venv and test dependencies (pytest, fakeredis, etc.) pre-installed. Drone CI now builds and caches this image as :test, then uses it directly for running tests — eliminating apt-get and pip install on every build. --- .drone.yml | 21 +++++++++++++++++---- Dockerfile | 12 +++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index 93d7fa9..a10041a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -109,12 +109,25 @@ trigger: - push steps: + - name: Cache test image + image: plugins/docker + settings: + username: viktorbarzin + password: + from_secret: dockerhub-token + repo: viktorbarzin/realestatecrawler + dockerfile: Dockerfile + context: . + target: test + cache_from: + - viktorbarzin/realestatecrawler:test + - viktorbarzin/realestatecrawler:builder + tags: + - test + - name: Run backend tests - image: python:3.13-slim + image: viktorbarzin/realestatecrawler:test commands: - - apt-get update && apt-get install -y --no-install-recommends gcc libmariadb-dev pkg-config python3-dev build-essential libgl1 libglib2.0-0 && rm -rf /var/lib/apt/lists/* - - pip install --no-cache-dir -r requirements.txt - - pip install --no-cache-dir pytest pytest-asyncio pytest-xdist httpx aioresponses fakeredis - pytest tests/ -x -q - name: Cache builder stage diff --git a/Dockerfile b/Dockerfile index 0a7490b..44e1b6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libmariadb3 \ && rm -rf /var/lib/apt/lists/* -# Stage 3: Final image — combine venv from builder + runtime base +# Stage 3: Test image — runtime deps + venv + test dependencies +FROM runtime-base AS test + +WORKDIR /app + +COPY --from=builder /app/.venv /app/.venv +ENV PATH="/app/.venv/bin:$PATH" + +RUN pip install --no-cache-dir pytest pytest-asyncio pytest-xdist httpx aioresponses fakeredis + +# Stage 4: Final image — combine venv from builder + runtime base FROM runtime-base WORKDIR /app