gptimage / Dockerfile
ByFlown's picture
Update Dockerfile
e8d72fc verified
# Fresh build 2025-04-23 v13 to force rebuild
FROM ubuntu:20.04
# Set working directory
WORKDIR /app
# Set environment variables to avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH=/usr/local/bin:/usr/bin:/bin:/usr/lib/chromium-browser:$PATH
ENV BUILD_ID=2025-04-23-v13
# Create non-root user (matching Hugging Face's UID 1000)
RUN useradd -m -u 1000 -s /bin/bash user \
&& chown -R user:user /app
# Install system dependencies for Chrome and ChromeDriver
RUN apt-get update && apt-get install -y \
wget \
unzip \
curl \
python3 \
python3-pip \
libglib2.0-0 \
libnss3 \
libgconf-2-4 \
libfontconfig1 \
libxrender1 \
libxtst6 \
libxi6 \
libgbm-dev \
libasound2 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libpango-1.0-0 \
libcairo2 \
libgtk-3-0 \
libcups2 \
libxss1 \
libappindicator3-1 \
libindicator3-7 \
libstdc++6 \
zlib1g \
libncurses5 \
libx11-6 \
libxext6 \
libxcomposite1 \
libxrandr2 \
libgcc1 \
libxkbcommon0 \
libxdamage1 \
libxfixes3 \
libxcursor1 \
libxinerama1 \
libxxf86vm1 \
libatk-adaptor \
libgdk-pixbuf2.0-0 \
xvfb \
libdbus-1-3 \
libdbus-glib-1-2 \
&& rm -rf /var/lib/apt/lists/*
# Install Google Chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update \
&& apt-get install -y google-chrome-stable \
&& rm -rf /var/lib/apt/lists/* \
|| (echo "Chrome installation failed" && exit 1)
# Verify Chrome installation and binary location
RUN which google-chrome || (echo "google-chrome binary not found" && exit 1)
RUN google-chrome --version || (echo "Cannot run google-chrome" && exit 1)
RUN ls -l /usr/bin/google-chrome || echo "google-chrome not in /usr/bin"
# Install ChromeDriver with debugging and fallback for Chrome 135
RUN echo "Fetching Chrome version..." \
&& CHROME_VERSION=$(google-chrome --version | grep -oP '\d+\.\d+\.\d+' || echo "Failed to get Chrome version") \
&& echo "Chrome version: $CHROME_VERSION" \
&& if [ -z "$CHROME_VERSION" ]; then \
echo "Using fallback ChromeDriver version 135.0.7049.114" \
&& CHROMEDRIVER_VERSION="135.0.7049.114"; \
else \
echo "Fetching ChromeDriver version for Chrome $CHROME_VERSION..." \
&& CHROMEDRIVER_VERSION=$(curl -sS https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json | grep -oP '"version":"${CHROME_VERSION}\.[0-9]+"' | grep -oP '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n 1 || echo "Failed to fetch ChromeDriver version") \
&& echo "ChromeDriver version: $CHROMEDRIVER_VERSION" \
&& if [ -z "$CHROMEDRIVER_VERSION" ]; then \
echo "Using fallback ChromeDriver version 135.0.7049.114" \
&& CHROMEDRIVER_VERSION="135.0.7049.114"; \
fi; \
fi \
&& echo "Downloading ChromeDriver $CHROMEDRIVER_VERSION..." \
&& wget -q https://storage.googleapis.com/chrome-for-testing-public/${CHROMEDRIVER_VERSION}/linux64/chromedriver-linux64.zip \
&& echo "Unzipping ChromeDriver..." \
&& unzip chromedriver-linux64.zip \
&& echo "Moving ChromeDriver to /usr/local/bin..." \
&& mv chromedriver-linux64/chromedriver /usr/local/bin/ \
&& chmod +x /usr/local/bin/chromedriver \
&& rm chromedriver-linux64.zip \
|| (echo "ChromeDriver installation failed" && exit 1)
# Verify ChromeDriver installation
RUN which chromedriver || (echo "chromedriver binary not found" && exit 1)
RUN chromedriver --version || (echo "Cannot run chromedriver" && exit 1)
RUN ls -l /usr/local/bin/chromedriver || echo "chromedriver not in /usr/local/bin"
# Test ChromeDriver with Chrome
RUN echo "Testing ChromeDriver..." \
&& chromedriver --version \
&& google-chrome --version \
&& (xvfb-run -a google-chrome --headless=new --no-sandbox --disable-dev-shm-usage --disable-gpu --version || echo "Headless Chrome test failed")
# Clear Selenium cache to avoid outdated ChromeDriver
RUN rm -rf /home/user/.cache/selenium
# Copy requirements and install Python dependencies
COPY app/requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
# Copy the app code
COPY app/app.py .
# Switch to non-root user
USER user
# Expose the port Gradio will run on
EXPOSE 7860
# Health check to verify Gradio is running
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1
# Run the Gradio app
CMD ["python3", "app.py"]