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
|
|
@ -1,22 +1,32 @@
|
|||
# Stage 1: Build the React app
|
||||
FROM node:24-alpine AS builder
|
||||
# Stage 1: Install dependencies (cached if package-lock.json unchanged)
|
||||
FROM node:24-alpine AS deps
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Limit Node.js heap to avoid OOM in constrained CI environments
|
||||
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* ./
|
||||
|
||||
RUN npm ci
|
||||
|
||||
# Copy all files and build
|
||||
# Stage 2: Run tests (fails the build if tests fail)
|
||||
FROM deps AS test
|
||||
|
||||
COPY . .
|
||||
|
||||
# Skip tsc type-checking (already done in test step); Vite transpiles via SWC
|
||||
RUN npx vite build
|
||||
RUN npx vitest run
|
||||
|
||||
# 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
|
||||
|
||||
# Remove default nginx static files
|
||||
|
|
@ -24,9 +34,8 @@ RUN rm -rf /usr/share/nginx/html/*
|
|||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy only necessary files from the builder stage
|
||||
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/dist /usr/share/nginx/html
|
||||
COPY --from=builder /app/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue