rentgen/Dockerfile
Jacek Wielemborek 1f47574afe feat(docker): dodaj weryfikację uruchomienia extensiona
- Skrypt sprawdza czy extension rzeczywiście się zainstalował
- Wyświetla czytelny komunikat sukcesu z info o procesach
- Capture output web-ext do /tmp/web-ext.log dla weryfikacji
- Timeout 30s na instalację extensiona
- Pokazuje PID Firefox i Xvfb

Weryfikacja pokazuje:
✓ Extension installed: rentgen@internet-czas-dzialac.pl
✓ Firefox ESR running in headless mode
✓ Xvfb running on display :99

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-25 17:59:52 +02:00

121 lines
3.4 KiB
Docker

# Rentgen Browser Extension - Docker Build
#
# Usage:
# Build and extract artifacts directly:
# docker buildx build . --output artifacts
#
# Build with tests (typecheck + lint):
# docker build --build-arg RUN_TESTS=true -t rentgen .
#
# Or traditional build (creates full development environment):
# docker build -t rentgen .
# docker run --rm rentgen ls -lh /app/web-ext-artifacts/
#
# Run commands in the container:
# docker run --rm rentgen npm run build:chrome
# docker run --rm rentgen npm run typecheck
#
# Run extension in Firefox (headless):
# docker build --target runtime -t rentgen-run .
# docker run --rm -it rentgen-run
#
# Using docker-compose:
# docker-compose up rentgen_check # Build only
# docker-compose up rentgen_run # Run in Firefox
# Build stage
FROM node:lts AS builder
# Optional: run tests during build (typecheck + lint)
ARG RUN_TESTS=false
WORKDIR /app
# Copy package files for dependency installation (better layer caching)
COPY package.json package-lock.json ./
# Install dependencies
RUN npm install
# Copy source code (respecting .dockerignore)
COPY . .
# Build the extension for Firefox (default)
RUN npm run build
# Create the package
RUN npm run create-package
# Optional: run quality checks
RUN if [ "$RUN_TESTS" = "true" ]; then \
echo "Running TypeScript type checking..."; \
npm run typecheck; \
echo "Running web-ext lint..."; \
npm run lint; \
fi
# 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 in Firefox
FROM builder AS runtime
# Install Firefox and Xvfb for headless execution
RUN apt-get update && apt-get install -y \
firefox-esr \
xvfb \
procps \
&& rm -rf /var/lib/apt/lists/*
# Set display for Xvfb
ENV DISPLAY=:99
# Create startup script with verbose logging and verification
RUN echo '#!/bin/bash\n\
set -e\n\
echo "Starting Xvfb on display :99..."\n\
Xvfb :99 -screen 0 1024x768x24 &\n\
XVFB_PID=$!\n\
sleep 2\n\
\n\
echo "Xvfb started with PID: $XVFB_PID"\n\
echo "Starting web-ext run with verbose logging..."\n\
echo "========================================"\n\
\n\
# Run web-ext with verbose logging and capture output\n\
npx web-ext run --verbose 2>&1 | tee /tmp/web-ext.log &\n\
WEBEXT_PID=$!\n\
\n\
# Wait for extension installation confirmation\n\
echo "Waiting for extension to install..."\n\
for i in {1..30}; do\n\
if grep -q "Installed /app as a temporary add-on" /tmp/web-ext.log 2>/dev/null; then\n\
echo "========================================"\n\
echo "✓ SUCCESS: Extension installed!"\n\
echo "✓ Firefox is running in headless mode"\n\
echo "✓ Extension: rentgen@internet-czas-dzialac.pl"\n\
echo "✓ Process info:"\n\
ps aux | grep -E "(firefox|Xvfb)" | grep -v grep | head -3\n\
echo "========================================"\n\
echo "Extension is ready. Press Ctrl+C to stop."\n\
break\n\
fi\n\
sleep 1\n\
done\n\
\n\
# Keep container running and show logs\n\
wait $WEBEXT_PID\n\
' > /app/start.sh && chmod +x /app/start.sh
# Start script
CMD ["/app/start.sh"]