Cache test image to speed up CI backend test step

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.
This commit is contained in:
Viktor Barzin 2026-02-10 22:57:42 +00:00
parent 909cb8e04b
commit 96bcebdb40
No known key found for this signature in database
GPG key ID: 0EB088298288D958
2 changed files with 28 additions and 5 deletions

View file

@ -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

View file

@ -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