Files
rss_warhammer-community/Dockerfile
T

82 lines
1.8 KiB
Docker
Raw Normal View History

2024-10-08 13:55:13 -06:00
# Use the official Python 3.12.7 Slim image as the base
FROM python:3.12.7-slim-bullseye
# Set the working directory
WORKDIR /app
2025-06-05 18:31:42 -06:00
# Install system dependencies needed for Playwright and gosu
2024-10-08 13:55:13 -06:00
RUN apt-get update && apt-get install -y \
bash \
build-essential \
libffi-dev \
git \
curl \
ca-certificates \
wget \
gnupg \
2025-06-05 18:31:42 -06:00
gosu \
2024-10-08 13:55:13 -06:00
libnss3 \
libatk-bridge2.0-0 \
libx11-xcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxi6 \
libxtst6 \
libappindicator3-1 \
libxrandr2 \
xdg-utils \
libgbm1 \
libpango-1.0-0 \
libasound2 \
libpangocairo-1.0-0 \
libxshmfence1 \
libx11-6 \
libatk1.0-0 \
libgtk-3-0 \
libdrm2 \
&& rm -rf /var/lib/apt/lists/*
2025-06-05 18:31:42 -06:00
# Copy requirements and install Python dependencies
COPY requirements.txt .
2024-10-08 13:55:13 -06:00
RUN pip install --upgrade pip && \
2025-06-05 18:31:42 -06:00
pip install -r requirements.txt
2024-10-08 13:55:13 -06:00
2025-06-05 18:19:23 -06:00
# Create an entrypoint script to handle permissions (as root)
RUN echo '#!/bin/bash\n\
# Fix permissions for mounted volumes\n\
if [ -d "/app/output" ]; then\n\
chmod 777 /app/output 2>/dev/null || true\n\
fi\n\
# Run as scraper user\n\
exec gosu scraper "$@"' > /entrypoint.sh && chmod +x /entrypoint.sh
# Create non-root user for security
RUN useradd -m -u 1001 scraper && \
mkdir -p /app/output && \
chown -R scraper:scraper /app && \
chmod 755 /app/output
2024-10-08 13:55:13 -06:00
# Copy the application code to the container
2024-10-08 13:55:13 -06:00
COPY main.py .
COPY src/ src/
RUN chown -R scraper:scraper main.py src/
2024-10-08 13:55:13 -06:00
2025-06-05 18:31:42 -06:00
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PLAYWRIGHT_BROWSERS_PATH=/home/scraper/.cache/ms-playwright
2024-10-08 13:55:13 -06:00
2025-06-05 18:19:23 -06:00
# Don't switch user here - entrypoint will handle it
# USER scraper
2025-06-05 18:31:42 -06:00
# Install Chromium for the scraper user
2025-06-05 18:19:23 -06:00
USER scraper
RUN playwright install chromium
USER root
ENTRYPOINT ["/entrypoint.sh"]
2024-10-08 13:55:13 -06:00
CMD ["python", "main.py"]