latest attempt of dockerization
This commit is contained in:
+2
-3
@@ -3,10 +3,9 @@ __pycache__/
|
|||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|
||||||
# Virtual environments
|
# Virtual environments
|
||||||
venv/
|
agentic_seek_env/
|
||||||
.venv/
|
.agentic_seek_env/
|
||||||
|
|
||||||
# Environment variables (secrets)
|
|
||||||
.env
|
.env
|
||||||
|
|
||||||
# Git metadata
|
# Git metadata
|
||||||
|
|||||||
+9
-27
@@ -2,7 +2,8 @@
|
|||||||
FROM --platform=linux/amd64 python:3.11-slim
|
FROM --platform=linux/amd64 python:3.11-slim
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
WORKDIR /app
|
RUN groupadd -r chrome && useradd -r -g chrome -G audio,video chrome
|
||||||
|
|
||||||
|
|
||||||
# Install essential packages and Chrome dependencies
|
# Install essential packages and Chrome dependencies
|
||||||
RUN apt-get update -y && apt-get install -y \
|
RUN apt-get update -y && apt-get install -y \
|
||||||
@@ -59,6 +60,8 @@ apt-get install -y \
|
|||||||
ENV CHROME_TESTING_VERSION=134.0.6998.88
|
ENV CHROME_TESTING_VERSION=134.0.6998.88
|
||||||
ENV DISPLAY=:99
|
ENV DISPLAY=:99
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
wget -qO /tmp/chrome.zip \
|
wget -qO /tmp/chrome.zip \
|
||||||
"https://storage.googleapis.com/chrome-for-testing-public/${CHROME_TESTING_VERSION}/linux64/chrome-linux64.zip"; \
|
"https://storage.googleapis.com/chrome-for-testing-public/${CHROME_TESTING_VERSION}/linux64/chrome-linux64.zip"; \
|
||||||
@@ -87,6 +90,7 @@ COPY requirements.txt .
|
|||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
RUN mkdir -p /opt/workspace
|
RUN mkdir -p /opt/workspace
|
||||||
|
RUN mkdir -p /tmp && chmod 1777 /tmp
|
||||||
|
|
||||||
# Copy application code
|
# Copy application code
|
||||||
COPY api.py .
|
COPY api.py .
|
||||||
@@ -96,32 +100,10 @@ COPY crx/ crx/
|
|||||||
COPY llm_router/ llm_router/
|
COPY llm_router/ llm_router/
|
||||||
COPY config.ini .
|
COPY config.ini .
|
||||||
|
|
||||||
# Install Chrome and ChromeDriver from chrome-for-testing
|
|
||||||
#RUN wget -O chrome-headless-shell-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.55/linux64/chrome-headless-shell-linux64.zip && \
|
|
||||||
# wget -O chromedriver-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.55/linux64/chromedriver-linux64.zip && \
|
|
||||||
# unzip chrome-headless-shell-linux64.zip && \
|
|
||||||
# unzip chromedriver-linux64.zip && \
|
|
||||||
# mkdir -p /opt/google && \
|
|
||||||
# ls -la && \
|
|
||||||
# mv chrome-headless-shell-linux64 /opt/google/chrome && \
|
|
||||||
# mv chromedriver-linux64/chromedriver /usr/local/bin/chromedriver && \
|
|
||||||
# chmod +x /opt/google/chrome/chrome-headless-shell && \
|
|
||||||
# chmod +x /usr/local/bin/chromedriver
|
|
||||||
|
|
||||||
#RUN wget -q -O - https://dl.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/*
|
|
||||||
#
|
|
||||||
## Install matching ChromeDriver
|
|
||||||
#RUN CHROME_VERSION=$(google-chrome --version | grep -oP '\d+\.\d+\.\d+') && \
|
|
||||||
# wget -O chromedriver.zip "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION%%.*}/chromedriver_linux64.zip" && \
|
|
||||||
# unzip chromedriver.zip && \
|
|
||||||
# mv chromedriver /usr/local/bin/ && \
|
|
||||||
# chmod +x /usr/local/bin/chromedriver && \
|
|
||||||
# rm chromedriver.zip
|
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
# Switch to non-root user
|
||||||
|
USER chrome
|
||||||
|
RUN chown -R chrome:chrome /app
|
||||||
|
RUN chown -R chrome:chrome /tmp
|
||||||
# Run the application
|
# Run the application
|
||||||
CMD ["python3", "api.py"]
|
CMD ["python3", "api.py"]
|
||||||
+9
-13
@@ -19,6 +19,7 @@ import time
|
|||||||
import random
|
import random
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import uuid
|
||||||
import tempfile
|
import tempfile
|
||||||
import markdownify
|
import markdownify
|
||||||
import sys
|
import sys
|
||||||
@@ -43,12 +44,11 @@ def get_chrome_path() -> str:
|
|||||||
"/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta"]
|
"/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta"]
|
||||||
else: # Linux
|
else: # Linux
|
||||||
paths = ["/usr/bin/google-chrome",
|
paths = ["/usr/bin/google-chrome",
|
||||||
|
"/opt/chrome/chrome",
|
||||||
"/usr/bin/chromium-browser",
|
"/usr/bin/chromium-browser",
|
||||||
"/usr/bin/chromium",
|
"/usr/bin/chromium",
|
||||||
"/opt/chrome/chrome",
|
|
||||||
"/usr/local/bin/chrome",
|
"/usr/local/bin/chrome",
|
||||||
"/opt/google/chrome/chrome-headless-shell",
|
"/opt/google/chrome/chrome-headless-shell",
|
||||||
"/opt/google/chrome/chrome",
|
|
||||||
#"/app/chrome_bundle/chrome136/chrome-linux64"
|
#"/app/chrome_bundle/chrome136/chrome-linux64"
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -81,11 +81,6 @@ def install_chromedriver() -> str:
|
|||||||
Install the ChromeDriver if not already installed. Return the path.
|
Install the ChromeDriver if not already installed. Return the path.
|
||||||
"""
|
"""
|
||||||
chromedriver_path = shutil.which("chromedriver")
|
chromedriver_path = shutil.which("chromedriver")
|
||||||
#if not chromedriver_path:
|
|
||||||
# if os.path.exists("/app/chrome_bundle/chrome136/chromedriver"):
|
|
||||||
# print("Using bundled ChromeDriver from /app/chrome_bundle/chrome136/chromedriver")
|
|
||||||
# chromedriver_path = "/app/chrome_bundle/chrome136/chromedriver"
|
|
||||||
print("path:", chromedriver_path)
|
|
||||||
if not chromedriver_path:
|
if not chromedriver_path:
|
||||||
try:
|
try:
|
||||||
print("ChromeDriver not found, attempting to install automatically...")
|
print("ChromeDriver not found, attempting to install automatically...")
|
||||||
@@ -136,27 +131,28 @@ def create_driver(headless=False, stealth_mode=True, crx_path="./crx/nopecha.crx
|
|||||||
if headless:
|
if headless:
|
||||||
#chrome_options.add_argument("--headless")
|
#chrome_options.add_argument("--headless")
|
||||||
chrome_options.add_argument("--headless=new")
|
chrome_options.add_argument("--headless=new")
|
||||||
chrome_options.add_argument("--disable-dev-shm-usage")
|
|
||||||
chrome_options.add_argument("--disable-gpu")
|
chrome_options.add_argument("--disable-gpu")
|
||||||
chrome_options.add_argument("--disable-webgl")
|
chrome_options.add_argument("--disable-webgl")
|
||||||
chrome_options.add_argument("--remote-debugging-port=9222")
|
|
||||||
user_data_dir = tempfile.mkdtemp()
|
user_data_dir = tempfile.mkdtemp()
|
||||||
user_agent = get_random_user_agent()
|
user_agent = get_random_user_agent()
|
||||||
width, height = (1920, 1080)
|
width, height = (1920, 1080)
|
||||||
#chrome_options.add_argument(f"--user-data-dir={user_data_dir}")
|
user_data_dir = tempfile.mkdtemp(prefix="chrome_profile_")
|
||||||
|
import os
|
||||||
|
print(f"Running as UID: {os.getuid()}") # Will show 0 if root
|
||||||
|
chrome_options.add_argument("--no-sandbox")
|
||||||
|
chrome_options.add_argument('--disable-dev-shm-usage')
|
||||||
|
profile_dir = f"/tmp/chrome_profile_{uuid.uuid4().hex[:8]}"
|
||||||
|
chrome_options.add_argument(f'--user-data-dir={profile_dir}')
|
||||||
chrome_options.add_argument(f"--accept-lang={lang}-{lang.upper()},{lang};q=0.9")
|
chrome_options.add_argument(f"--accept-lang={lang}-{lang.upper()},{lang};q=0.9")
|
||||||
chrome_options.add_argument("--disable-extensions")
|
chrome_options.add_argument("--disable-extensions")
|
||||||
chrome_options.add_argument("--disable-background-timer-throttling")
|
chrome_options.add_argument("--disable-background-timer-throttling")
|
||||||
chrome_options.add_argument("--timezone=Europe/Paris")
|
chrome_options.add_argument("--timezone=Europe/Paris")
|
||||||
chrome_options.add_argument("--no-sandbox")
|
|
||||||
chrome_options.add_argument('--disable-dev-shm-usage')
|
|
||||||
chrome_options.add_argument('--remote-debugging-port=9222')
|
chrome_options.add_argument('--remote-debugging-port=9222')
|
||||||
chrome_options.add_argument('--disable-background-timer-throttling')
|
chrome_options.add_argument('--disable-background-timer-throttling')
|
||||||
chrome_options.add_argument('--disable-backgrounding-occluded-windows')
|
chrome_options.add_argument('--disable-backgrounding-occluded-windows')
|
||||||
chrome_options.add_argument('--disable-renderer-backgrounding')
|
chrome_options.add_argument('--disable-renderer-backgrounding')
|
||||||
chrome_options.add_argument('--disable-features=TranslateUI')
|
chrome_options.add_argument('--disable-features=TranslateUI')
|
||||||
chrome_options.add_argument('--disable-ipc-flooding-protection')
|
chrome_options.add_argument('--disable-ipc-flooding-protection')
|
||||||
chrome_options.add_argument("--disable-dev-shm-usage")
|
|
||||||
chrome_options.add_argument("--mute-audio")
|
chrome_options.add_argument("--mute-audio")
|
||||||
chrome_options.add_argument("--disable-notifications")
|
chrome_options.add_argument("--disable-notifications")
|
||||||
chrome_options.add_argument("--autoplay-policy=user-gesture-required")
|
chrome_options.add_argument("--autoplay-policy=user-gesture-required")
|
||||||
|
|||||||
Reference in New Issue
Block a user