-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.test
More file actions
60 lines (47 loc) · 2.05 KB
/
Dockerfile.test
File metadata and controls
60 lines (47 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Test Dockerfile for Villa Monorepo
# Optimized for running unit, integration, and E2E tests in CI/CD
# Note: Enable BuildKit (DOCKER_BUILDKIT=1) for better caching
# Stage 1: Dependencies with pnpm
FROM node:20-alpine AS deps
RUN apk add --no-cache libc6-compat python3 make g++
RUN corepack enable && corepack prepare pnpm@9.0.0 --activate
WORKDIR /app
# Copy package files for all workspaces
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY apps/hub/package.json ./apps/hub/
COPY packages/sdk/package.json ./packages/sdk/
COPY packages/ui/package.json ./packages/ui/
COPY packages/config/package.json ./packages/config/
# Install dependencies (including devDependencies for tests)
RUN pnpm install --frozen-lockfile
# Stage 2: Playwright browsers (heavy, cache separately)
FROM mcr.microsoft.com/playwright:v1.57.0-jammy AS playwright-base
# Update corepack to fix signature verification, fallback to non-strict mode
ENV COREPACK_ENABLE_STRICT=0
RUN npm install -g corepack@latest && corepack enable && corepack prepare pnpm@9.0.0 --activate
WORKDIR /app
# Copy deps from previous stage
COPY --from=deps /app/node_modules ./node_modules/
COPY --from=deps /app/apps ./apps/
COPY --from=deps /app/packages ./packages/
# Stage 3: Test runner
FROM playwright-base AS test-runner
# Security: non-root user with proper home directory for corepack cache
RUN groupadd --system --gid 1001 testuser && \
useradd --system --uid 1001 --gid testuser --create-home testuser && \
mkdir -p /home/testuser/.cache/node/corepack && \
chown -R testuser:testuser /app /home/testuser
# Copy all source code
COPY --chown=testuser:testuser . .
# Environment variables for CI mode
ENV CI=true
ENV NODE_ENV=test
ENV NEXT_TELEMETRY_DISABLED=1
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
# Build Next.js for E2E tests (needed for test server)
RUN pnpm --filter @villa/hub build
# Fix permissions for .next directory after build (built as root, needed by testuser)
RUN chown -R testuser:testuser /app/apps/hub/.next
USER testuser
# Default command runs all tests
CMD ["pnpm", "test"]