Parallelize frontend tests in Drone pipeline with 4 shards

Split the monolithic "build and test" kaniko step into a DAG:
tests run in 4 parallel shards (vitest --shard) alongside the
Docker image build, gated by a shared npm ci step. The kaniko
build now targets the named 'production' stage to skip the
in-Dockerfile test stage.
This commit is contained in:
Viktor Barzin 2026-02-21 21:02:22 +00:00
parent a36c0dfdf7
commit 15dbcfa332
No known key found for this signature in database
GPG key ID: 0EB088298288D958
2 changed files with 58 additions and 2 deletions

View file

@ -30,8 +30,55 @@ steps:
exit 1 exit 1
- git checkout "$DRONE_COMMIT" - git checkout "$DRONE_COMMIT"
- name: Build and test frontend image - name: install-frontend-deps
image: node:24-alpine
depends_on:
- clone
environment:
NODE_OPTIONS: "--max-old-space-size=1024"
commands:
- cd frontend && npm ci
- name: test-shard-1
image: node:24-alpine
depends_on:
- install-frontend-deps
environment:
NODE_OPTIONS: "--max-old-space-size=1024"
commands:
- cd frontend && npx vitest run --reporter=verbose --shard=1/4
- name: test-shard-2
image: node:24-alpine
depends_on:
- install-frontend-deps
environment:
NODE_OPTIONS: "--max-old-space-size=1024"
commands:
- cd frontend && npx vitest run --reporter=verbose --shard=2/4
- name: test-shard-3
image: node:24-alpine
depends_on:
- install-frontend-deps
environment:
NODE_OPTIONS: "--max-old-space-size=1024"
commands:
- cd frontend && npx vitest run --reporter=verbose --shard=3/4
- name: test-shard-4
image: node:24-alpine
depends_on:
- install-frontend-deps
environment:
NODE_OPTIONS: "--max-old-space-size=1024"
commands:
- cd frontend && npx vitest run --reporter=verbose --shard=4/4
- name: build-frontend-image
image: plugins/kaniko image: plugins/kaniko
depends_on:
- clone
resources: resources:
limits: limits:
memory: 2048MiB memory: 2048MiB
@ -42,6 +89,7 @@ steps:
repo: viktorbarzin/immoweb repo: viktorbarzin/immoweb
dockerfile: frontend/Dockerfile dockerfile: frontend/Dockerfile
context: frontend context: frontend
target: production
enable_cache: true enable_cache: true
cache_repo: viktorbarzin/immoweb-cache cache_repo: viktorbarzin/immoweb-cache
tags: tags:
@ -50,12 +98,20 @@ steps:
- name: Update deployment - name: Update deployment
image: alpine image: alpine
depends_on:
- test-shard-1
- test-shard-2
- test-shard-3
- test-shard-4
- build-frontend-image
commands: commands:
- apk add curl - apk add curl
- 'curl -s -X PATCH "https://kubernetes:6443/apis/apps/v1/namespaces/realestate-crawler/deployments/realestate-crawler-ui" -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -H "Content-Type: application/json-patch+json" -k -d ''[{"op":"replace","path":"/spec/template/spec/containers/0/image","value":"viktorbarzin/immoweb:''"$DRONE_BUILD_NUMBER"''"}]'' | head' - 'curl -s -X PATCH "https://kubernetes:6443/apis/apps/v1/namespaces/realestate-crawler/deployments/realestate-crawler-ui" -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -H "Content-Type: application/json-patch+json" -k -d ''[{"op":"replace","path":"/spec/template/spec/containers/0/image","value":"viktorbarzin/immoweb:''"$DRONE_BUILD_NUMBER"''"}]'' | head'
- name: verify-deploy - name: verify-deploy
image: alpine image: alpine
depends_on:
- Update deployment
commands: commands:
- apk add --no-cache curl jq - apk add --no-cache curl jq
- | - |

View file

@ -30,7 +30,7 @@ COPY . .
RUN npx vite build RUN npx vite build
# Stage 4: Serve with nginx # Stage 4: Serve with nginx
FROM nginx:alpine FROM nginx:alpine AS production
# Remove default nginx static files # Remove default nginx static files
RUN rm -rf /usr/share/nginx/html/* RUN rm -rf /usr/share/nginx/html/*