1
0
forked from icd/rentgen
rentgen/Dockerfile
Jacek Wielemborek b1154c4d62 test: add Selenium WebDriver integration tests
- Add Selenium WebDriver for browser extension testing
- Simplify test content script (only essential DOM attributes)
- Rename test-content-script.js → inner-test-content-script.js for clarity
- Add DEBUG_ prefix to test event name (DEBUG_rentgen_test_request)
- Auto-restore manifest.json after tests (git checkout)
- Include tests in run-checks.sh script
- Update Dockerfile to use Selenium instead of Marionette
- Ignore tests directory in web-ext lint

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-28 11:04:16 +00:00

107 lines
2.9 KiB
Docker

# Rentgen Browser Extension - Docker Build
# See README.md for detailed usage instructions
# Build stage
FROM node:lts AS builder
WORKDIR /app
# Copy package files for dependency installation (better layer caching)
COPY package.json package-lock.json ./
# Install dependencies
RUN npm install
# FIXME: COPY . . invalidates cache, so we need to optionally install Firefox
# and jump back to the correct stage. It might be too complex though, so we
# either need to use build args (if cache properly) or heavily document the
# stage transitions, maybe even with a graph.
# Copy source code (respecting .dockerignore)
COPY . .
# Build the extension for Firefox (default) - without tests
RUN npm run build
# Create the package
RUN npm run create-package
# Test builder stage - builds with ENABLE_TESTS=true
FROM node:lts AS test_builder
WORKDIR /app
# Copy package files for dependency installation
COPY package.json package-lock.json ./
# Install dependencies
RUN npm install
# Copy source code
COPY . .
# Build with tests enabled
RUN ENABLE_TESTS=true npm run build
# Create the package
RUN npm run create-package
# Code quality stage - for running quality checks
FROM builder AS code_quality
COPY tests/run-checks.sh /app/tests/run-checks.sh
RUN chmod +x /app/tests/run-checks.sh && /app/tests/run-checks.sh
# Artifacts stage - only contains the built artifacts (for --output)
FROM scratch AS artifacts
# Copy only the built extension zip file to root
COPY --from=builder /app/web-ext-artifacts/*.zip /
# Default stage - full development environment
FROM builder
# Default command shows the built artifact
CMD ["ls", "-lh", "/app/web-ext-artifacts/"]
# Runtime stage - for running extension with Selenium WebDriver
FROM node:lts AS runtime
WORKDIR /app
# Copy built extension from test_builder (includes test code)
COPY --from=test_builder /app /app
# Install Firefox and Xvfb for headless execution
RUN apt-get update && apt-get install -y \
firefox-esr \
xvfb \
wget \
&& rm -rf /var/lib/apt/lists/*
# Install geckodriver for WebDriver protocol
RUN wget -q https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz \
&& tar -xzf geckodriver-v0.34.0-linux64.tar.gz \
&& mv geckodriver /usr/local/bin/ \
&& rm geckodriver-v0.34.0-linux64.tar.gz \
&& chmod +x /usr/local/bin/geckodriver
# Install Node.js test dependencies
RUN npm install
# Set display for Xvfb
ENV DISPLAY=:99
# Start script (not used in verify stage)
CMD ["echo", "Use verify stage for testing"]
# Integration test stage - automated testing with exit code
FROM runtime AS integration_test
# Copy verification scripts
COPY tests/test_verify.mjs /app/tests/test_verify.mjs
COPY tests/test-lib.js /app/tests/test-lib.js
RUN chmod +x /app/tests/test_verify.mjs
# Run verification and exit with proper exit code
CMD ["node", "/app/tests/test_verify.mjs"]