@@ -7,38 +7,85 @@ ENV PYTHONUNBUFFERED=1 \
77 PIP_NO_CACHE_DIR=1 \
88 DEBIAN_FRONTEND=noninteractive
99
10- # Install system dependencies
10+ # Install system dependencies for Playwright
1111RUN apt-get update && apt-get install -y \
1212 wget \
1313 gnupg \
1414 curl \
1515 unzip \
16+ # Playwright system dependencies
17+ libnss3 \
18+ libnspr4 \
19+ libatk-bridge2.0-0 \
20+ libdrm2 \
21+ libxkbcommon0 \
22+ libxcomposite1 \
23+ libxdamage1 \
24+ libxrandr2 \
25+ libgbm1 \
26+ libxss1 \
27+ libasound2 \
28+ libatspi2.0-0 \
29+ libgtk-3-0 \
30+ # Additional dependencies for headless operation
31+ xvfb \
1632 && apt-get clean \
1733 && rm -rf /var/lib/apt/lists/*
1834
19- # Install Google Chrome
20- RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/googlechrome-linux-keyring.gpg \
21- && echo "deb [arch=amd64 signed-by=/usr/share/keyrings/googlechrome-linux-keyring.gpg] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list \
22- && apt-get update \
23- && apt-get install -y google-chrome-stable \
24- && apt-get clean \
25- && rm -rf /var/lib/apt/lists/*
26-
27- # Install uv
35+ # Install uv for fast package management
2836RUN pip install uv
2937
3038# Set working directory
3139WORKDIR /app
3240
33- # Copy pyproject.toml and install dependencies
34- COPY pyproject.toml ./
41+ # Copy essential files for package installation
42+ COPY pyproject.toml README.md ./
43+
44+ # Install Python dependencies
3545RUN uv pip install --system -e .
3646
37- # Copy source code
47+ # Install Playwright system dependencies
48+ RUN python -m playwright install-deps chromium
49+
50+ # Create non-root user for security
51+ RUN groupadd -r playwright && useradd -r -g playwright -G audio,video playwright \
52+ && mkdir -p /home/playwright/Downloads \
53+ && chown -R playwright:playwright /home/playwright \
54+ && chown -R playwright:playwright /app
55+
56+ # Copy entrypoint script first (as root)
57+ COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
58+ RUN chmod +x /usr/local/bin/docker-entrypoint.sh
59+
60+ # Copy source code (before switching user)
3861COPY . .
3962
63+ # Set ownership of the app directory (as root)
64+ RUN chown -R playwright:playwright /app
65+
66+ # Switch to non-root user
67+ USER playwright
68+
69+ # Set Playwright environment variables
70+ ENV PLAYWRIGHT_BROWSERS_PATH=/home/playwright/.cache/ms-playwright
71+
72+ # Install browsers as playwright user
73+ RUN python -m playwright install chromium
74+
75+ # Create cache directories
76+ RUN mkdir -p /home/playwright/.cache/ms-playwright \
77+ && mkdir -p /app/cache/html \
78+ && mkdir -p /app/cache/images
79+
4080# Expose port (if running web service)
4181EXPOSE 8000
4282
43- # Default command
44- CMD ["python" , "-c" , "from piedomains.api import DomainClassifier; print('piedomains v0.4.0 ready!')" ]
83+ # Set entrypoint
84+ ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh" ]
85+
86+ # Health check to verify installation
87+ HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
88+ CMD python -c "import piedomains; print('✓ piedomains ready')" || exit 1
89+
90+ # Default command - interactive shell
91+ CMD []
0 commit comments