perf: optimize CI pipeline — eliminate double dependency installs, use local registry cache
- Frontend Dockerfile: split into deps/test/builder/nginx stages so npm ci runs once (cached when package-lock.json unchanged), tests run in build - Backend Dockerfile: add test stage that runs pytest inside the build, eliminating separate test image build - .drone.yml: remove separate test steps (now inside Dockerfile builds), point cache_from/cache_repo at local registry (10.0.20.10:5000) instead of Docker Hub for faster layer cache pulls
This commit is contained in:
parent
68859ae577
commit
b1be4d4170
3 changed files with 68 additions and 49 deletions
84
.drone.yml
84
.drone.yml
|
|
@ -30,17 +30,7 @@ steps:
|
||||||
exit 1
|
exit 1
|
||||||
- git checkout "$DRONE_COMMIT"
|
- git checkout "$DRONE_COMMIT"
|
||||||
|
|
||||||
- name: Run frontend tests
|
- name: Build and test frontend image
|
||||||
image: node:24-alpine
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
memory: 2048MiB
|
|
||||||
commands:
|
|
||||||
- cd frontend
|
|
||||||
- npm ci
|
|
||||||
- npx vitest run
|
|
||||||
|
|
||||||
- name: Build frontend image
|
|
||||||
image: plugins/kaniko
|
image: plugins/kaniko
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
|
|
@ -53,10 +43,30 @@ steps:
|
||||||
dockerfile: frontend/Dockerfile
|
dockerfile: frontend/Dockerfile
|
||||||
context: frontend
|
context: frontend
|
||||||
enable_cache: true
|
enable_cache: true
|
||||||
cache_repo: viktorbarzin/immoweb-cache
|
cache_repo: 10.0.20.10:5000/immoweb-cache
|
||||||
|
registry: 10.0.20.10:5000
|
||||||
|
insecure: true
|
||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
- ${DRONE_BUILD_NUMBER}
|
- "${DRONE_BUILD_NUMBER}"
|
||||||
|
|
||||||
|
- name: Push to Docker Hub
|
||||||
|
image: plugins/kaniko
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 512MiB
|
||||||
|
settings:
|
||||||
|
username: viktorbarzin
|
||||||
|
password:
|
||||||
|
from_secret: dockerhub-token
|
||||||
|
repo: viktorbarzin/immoweb
|
||||||
|
dockerfile: frontend/Dockerfile
|
||||||
|
context: frontend
|
||||||
|
enable_cache: true
|
||||||
|
cache_repo: 10.0.20.10:5000/immoweb-cache
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
- "${DRONE_BUILD_NUMBER}"
|
||||||
|
|
||||||
- name: Update deployment
|
- name: Update deployment
|
||||||
image: alpine
|
image: alpine
|
||||||
|
|
@ -131,42 +141,38 @@ steps:
|
||||||
exit 1
|
exit 1
|
||||||
- git checkout "$DRONE_COMMIT"
|
- git checkout "$DRONE_COMMIT"
|
||||||
|
|
||||||
- name: Cache test image
|
- name: Build and test API image
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
username: viktorbarzin
|
username: viktorbarzin
|
||||||
password:
|
password:
|
||||||
from_secret: dockerhub-token
|
from_secret: dockerhub-token
|
||||||
repo: viktorbarzin/realestatecrawler
|
repo: 10.0.20.10:5000/viktorbarzin/realestatecrawler
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
context: .
|
context: .
|
||||||
target: test
|
insecure: true
|
||||||
cache_from:
|
cache_from:
|
||||||
- viktorbarzin/realestatecrawler:test
|
- 10.0.20.10:5000/viktorbarzin/realestatecrawler:latest
|
||||||
- viktorbarzin/realestatecrawler:builder
|
- 10.0.20.10:5000/viktorbarzin/realestatecrawler:builder
|
||||||
tags:
|
|
||||||
- test
|
|
||||||
|
|
||||||
- name: Run backend tests
|
|
||||||
image: viktorbarzin/realestatecrawler:test
|
|
||||||
commands:
|
|
||||||
- pytest tests/ -x -q
|
|
||||||
|
|
||||||
- name: Build API image
|
|
||||||
image: plugins/docker
|
|
||||||
settings:
|
|
||||||
username: viktorbarzin
|
|
||||||
password:
|
|
||||||
from_secret: dockerhub-token
|
|
||||||
repo: viktorbarzin/realestatecrawler
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
context: .
|
|
||||||
cache_from:
|
|
||||||
- viktorbarzin/realestatecrawler:builder
|
|
||||||
- viktorbarzin/realestatecrawler:latest
|
|
||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
- ${DRONE_BUILD_NUMBER}
|
- builder
|
||||||
|
- "${DRONE_BUILD_NUMBER}"
|
||||||
|
|
||||||
|
- name: Push to Docker Hub
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
username: viktorbarzin
|
||||||
|
password:
|
||||||
|
from_secret: dockerhub-token
|
||||||
|
repo: viktorbarzin/realestatecrawler
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
context: .
|
||||||
|
cache_from:
|
||||||
|
- 10.0.20.10:5000/viktorbarzin/realestatecrawler:latest
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
- "${DRONE_BUILD_NUMBER}"
|
||||||
|
|
||||||
- name: Update deployment
|
- name: Update deployment
|
||||||
image: alpine
|
image: alpine
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ 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: Test image — runtime deps + venv + test dependencies
|
# Stage 3: Test — runtime deps + venv + test dependencies + run tests
|
||||||
FROM runtime-base AS test
|
FROM runtime-base AS test
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
@ -38,6 +38,10 @@ ENV PATH="/app/.venv/bin:$PATH"
|
||||||
|
|
||||||
RUN pip install --no-cache-dir pytest pytest-asyncio pytest-xdist httpx aioresponses fakeredis
|
RUN pip install --no-cache-dir pytest pytest-asyncio pytest-xdist httpx aioresponses fakeredis
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN pytest tests/ -x -q
|
||||||
|
|
||||||
# Stage 4: Final image — combine venv from builder + runtime base
|
# Stage 4: Final image — combine venv from builder + runtime base
|
||||||
FROM runtime-base
|
FROM runtime-base
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,32 @@
|
||||||
# Stage 1: Build the React app
|
# Stage 1: Install dependencies (cached if package-lock.json unchanged)
|
||||||
FROM node:24-alpine AS builder
|
FROM node:24-alpine AS deps
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Limit Node.js heap to avoid OOM in constrained CI environments
|
# Limit Node.js heap to avoid OOM in constrained CI environments
|
||||||
ENV NODE_OPTIONS="--max-old-space-size=1024"
|
ENV NODE_OPTIONS="--max-old-space-size=1024"
|
||||||
|
|
||||||
# Copy package files first for better caching
|
# Copy package files first for better layer caching
|
||||||
COPY package.json package-lock.json* ./
|
COPY package.json package-lock.json* ./
|
||||||
|
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
# Copy all files and build
|
# Stage 2: Run tests (fails the build if tests fail)
|
||||||
|
FROM deps AS test
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Skip tsc type-checking (already done in test step); Vite transpiles via SWC
|
RUN npx vitest run
|
||||||
RUN npx vite build
|
|
||||||
|
|
||||||
|
# Stage 3: Build production bundle
|
||||||
|
FROM deps AS builder
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Skip tsc type-checking (vitest already validated); Vite transpiles via SWC
|
||||||
|
RUN npx vite build
|
||||||
|
|
||||||
|
# Stage 4: Serve with nginx
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
# Remove default nginx static files
|
# Remove default nginx static files
|
||||||
|
|
@ -24,9 +34,8 @@ RUN rm -rf /usr/share/nginx/html/*
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy only necessary files from the builder stage
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
COPY --from=builder /app/nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
COPY --from=builder /app/nginx.conf /etc/nginx/conf.d/default.conf
|
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue