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:
parent
909cb8e04b
commit
96bcebdb40
2 changed files with 28 additions and 5 deletions
21
.drone.yml
21
.drone.yml
|
|
@ -109,12 +109,25 @@ trigger:
|
||||||
- push
|
- push
|
||||||
|
|
||||||
steps:
|
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
|
- name: Run backend tests
|
||||||
image: python:3.13-slim
|
image: viktorbarzin/realestatecrawler:test
|
||||||
commands:
|
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
|
- pytest tests/ -x -q
|
||||||
|
|
||||||
- name: Cache builder stage
|
- name: Cache builder stage
|
||||||
|
|
|
||||||
12
Dockerfile
12
Dockerfile
|
|
@ -28,7 +28,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
libmariadb3 \
|
libmariadb3 \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& 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
|
FROM runtime-base
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue