From b7c8fe1f0446c36c57623cfb0e62307dd4665a2f Mon Sep 17 00:00:00 2001 From: vincent Date: Sat, 10 May 2025 00:41:41 +0800 Subject: [PATCH] fix dockerfile --- .dockerignore | 5 ++++- Dockerfile | 37 ++++++++++++++++++------------------- README.md | 37 +++++++++++++++++-------------------- docker-compose.yml | 6 ++++-- supervisord.conf | 2 +- tests/test_llm_api.py | 6 +++--- 6 files changed, 47 insertions(+), 46 deletions(-) diff --git a/.dockerignore b/.dockerignore index 9635889..140fab3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,5 @@ data -tmp \ No newline at end of file +tmp +results + +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b4d6fa1..ffdf721 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM python:3.11-slim # Set platform for multi-arch builds (Docker Buildx will set this) ARG TARGETPLATFORM +ARG NODE_MAJOR=20 # Install system dependencies RUN apt-get update && apt-get install -y \ @@ -42,6 +43,7 @@ RUN apt-get update && apt-get install -y \ fonts-dejavu \ fonts-dejavu-core \ fonts-dejavu-extra \ + vim \ && rm -rf /var/lib/apt/lists/* # Install noVNC @@ -49,6 +51,17 @@ RUN git clone https://github.com/novnc/noVNC.git /opt/novnc \ && git clone https://github.com/novnc/websockify /opt/novnc/utils/websockify \ && ln -s /opt/novnc/vnc.html /opt/novnc/index.html +# Install Node.js using NodeSource PPA +RUN mkdir -p /etc/apt/keyrings \ + && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ + && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \ + && apt-get update \ + && apt-get install nodejs -y \ + && rm -rf /var/lib/apt/lists/* + +# Verify Node.js and npm installation (optional, but good for debugging) +RUN node -v && npm -v && npx -v + # Set up working directory WORKDIR /app @@ -56,8 +69,7 @@ WORKDIR /app COPY requirements.txt . # Ensure 'patchright' is in your requirements.txt or install it directly # RUN pip install --no-cache-dir -r requirements.txt patchright # If not in requirements -RUN pip install --no-cache-dir -r requirements.txt # Assuming patchright is in requirements.txt -RUN pip install --no-cache-dir patchright # Or install it explicitly +RUN pip install --no-cache-dir -r requirements.txt # Install Patchright browsers and dependencies # Patchright documentation suggests PLAYWRIGHT_BROWSERS_PATH is still relevant @@ -69,32 +81,19 @@ RUN mkdir -p $PLAYWRIGHT_BROWSERS_PATH # Install recommended: Google Chrome (instead of just Chromium for better undetectability) # The 'patchright install chrome' command might download and place it. # The '--with-deps' equivalent for patchright install is to run 'patchright install-deps chrome' after. -RUN patchright install chrome -RUN patchright install-deps chrome +RUN patchright install chrome --with-deps # Alternative: Install Chromium if Google Chrome is problematic in certain environments -RUN patchright install chromium -RUN patchright install-deps chromium +RUN patchright install chromium --with-deps # Copy the application code COPY . . -# Set environment variables (Updated Names) -ENV PYTHONUNBUFFERED=1 -ENV BROWSER_USE_LOGGING_LEVEL=info -# BROWSER_PATH will be determined by Patchright installation, supervisord will find it. -ENV ANONYMIZED_TELEMETRY=false -ENV DISPLAY=:99 -ENV RESOLUTION=1920x1080x24 -ENV VNC_PASSWORD=youvncpassword -ENV KEEP_BROWSER_OPEN=true -ENV RESOLUTION_WIDTH=1920 -ENV RESOLUTION_HEIGHT=1080 - # Set up supervisor configuration RUN mkdir -p /var/log/supervisor COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf EXPOSE 7788 6080 5901 9222 -CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] \ No newline at end of file +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] +#CMD ["/bin/bash"] \ No newline at end of file diff --git a/README.md b/README.md index faa9638..b67a2ed 100644 --- a/README.md +++ b/README.md @@ -63,11 +63,11 @@ uv pip install -r requirements.txt Install Browsers in Patchright. ```bash -patchright install +patchright install --with-deps ``` Or you can install specific browsers by running: ```bash -patchright install chromium --with-deps --no-shell +patchright install chromium --with-deps ``` #### Step 4: Configure Environment @@ -82,25 +82,24 @@ cp .env.example .env ``` 2. Open `.env` in your preferred text editor and add your API keys and other settings -#### Local Setup +#### Step 5: Enjoy the web-ui 1. **Run the WebUI:** - After completing the installation steps above, start the application: ```bash python webui.py --ip 127.0.0.1 --port 7788 ``` 2. **Access the WebUI:** Open your web browser and navigate to `http://127.0.0.1:7788`. 3. **Using Your Own Browser(Optional):** - - Set `CHROME_PATH` to the executable path of your browser and `CHROME_USER_DATA` to the user data directory of your browser. Leave `CHROME_USER_DATA` empty if you want to use local user data. + - Set `BROWSER_PATH` to the executable path of your browser and `BROWSER_USER_DATA` to the user data directory of your browser. Leave `BROWSER_USER_DATA` empty if you want to use local user data. - Windows ```env - CHROME_PATH="C:\Program Files\Google\Chrome\Application\chrome.exe" - CHROME_USER_DATA="C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data" + BROWSER_PATH="C:\Program Files\Google\Chrome\Application\chrome.exe" + BROWSER_USER_DATA="C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data" ``` > Note: Replace `YourUsername` with your actual Windows username for Windows systems. - Mac ```env - CHROME_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" - CHROME_USER_DATA="/Users/YourUsername/Library/Application Support/Google/Chrome" + BROWSER_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" + BROWSER_USER_DATA="/Users/YourUsername/Library/Application Support/Google/Chrome" ``` - Close all Chrome windows - Open the WebUI in a non-Chrome browser, such as Firefox or Edge. This is important because the persistent browser context will use the Chrome data when running the agent. @@ -113,14 +112,14 @@ cp .env.example .env - [Docker Desktop](https://www.docker.com/products/docker-desktop/) (For Windows/macOS) - [Docker Engine](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/) (For Linux) -#### Installation Steps -1. Clone the repository: +#### Step 1: Clone the Repository ```bash git clone https://github.com/browser-use/web-ui.git cd web-ui ``` -2. Create and configure environment file: +#### Step 2: Configure Environment +1. Create a copy of the example environment file: - Windows (Command Prompt): ```bash copy .env.example .env @@ -129,25 +128,23 @@ copy .env.example .env ```bash cp .env.example .env ``` -Edit `.env` with your preferred text editor and add your API keys +2. Open `.env` in your preferred text editor and add your API keys and other settings -3. Run with Docker: +#### Step 3: Docker Build and Run ```bash -# Build and start the container with default settings (browser closes after AI tasks) docker compose up --build ``` +For ARM64 systems (e.g., Apple Silicon Macs), please run follow command: ```bash -# Or run with persistent browser (browser stays open between AI tasks) -CHROME_PERSISTENT_SESSION=true docker compose up --build +TARGETPLATFORM=linux/arm64 docker compose up --build ``` -4. Access the Application: -- Web Interface: Open `http://localhost:7788` in your browser +#### Step 4: Enjoy the web-ui and vnc +- Web-UI: Open `http://localhost:7788` in your browser - VNC Viewer (for watching browser interactions): Open `http://localhost:6080/vnc.html` - Default VNC password: "youvncpassword" - Can be changed by setting `VNC_PASSWORD` in your `.env` file - ## Changelog - [x] **2025/01/26:** Thanks to @vvincent1234. Now browser-use-webui can combine with DeepSeek-r1 to engage in deep thinking! - [x] **2025/01/10:** Thanks to @casistack. Now we have Docker Setup option and also Support keep browser open between tasks.[Video tutorial demo](https://github.com/browser-use/web-ui/issues/1#issuecomment-2582511750). diff --git a/docker-compose.yml b/docker-compose.yml index 780d2a9..c16fd92 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,5 @@ services: + # debug: docker compose run --rm -it browser-use-webui bash browser-use-webui: build: context: . @@ -11,7 +12,7 @@ services: - "5901:5901" - "9222:9222" environment: - # LLM API Keys & Endpoints (Your existing list) + # LLM API Keys & Endpoints - OPENAI_ENDPOINT=${OPENAI_ENDPOINT:-https://api.openai.com/v1} - OPENAI_API_KEY=${OPENAI_API_KEY:-} - ANTHROPIC_ENDPOINT=${ANTHROPIC_ENDPOINT:-https://api.anthropic.com} @@ -42,7 +43,8 @@ services: - BROWSER_USE_LOGGING_LEVEL=${BROWSER_USE_LOGGING_LEVEL:-info} # Browser Settings - - BROWSER_USER_DATA=${BROWSER_USER_DATA:-/app/data/chrome_data} + - BROWSER_PATH=/usr/bin/google-chrome + - BROWSER_USER_DATA=/app/data/chrome_data - BROWSER_DEBUGGING_PORT=${BROWSER_DEBUGGING_PORT:-9222} - BROWSER_DEBUGGING_HOST=${BROWSER_DEBUGGING_HOST:-0.0.0.0} - KEEP_BROWSER_OPEN=${KEEP_BROWSER_OPEN:-true} diff --git a/supervisord.conf b/supervisord.conf index 2c5d8b4..5135d09 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -3,7 +3,7 @@ user=root nodaemon=true logfile=/dev/stdout logfile_maxbytes=0 -loglevel=debug +loglevel=error [program:xvfb] command=Xvfb :99 -screen 0 %(ENV_RESOLUTION)s -ac +extension GLX +render -noreset diff --git a/tests/test_llm_api.py b/tests/test_llm_api.py index e98569b..938f825 100644 --- a/tests/test_llm_api.py +++ b/tests/test_llm_api.py @@ -142,17 +142,17 @@ def test_ibm_model(): def test_qwen_model(): - config = LLMConfig(provider="alibaba", model_name="qwen3-30b-a3b") + config = LLMConfig(provider="alibaba", model_name="qwen-vl-max") test_llm(config, "How many 'r's are in the word 'strawberry'?") if __name__ == "__main__": # test_openai_model() # test_google_model() - # test_azure_openai_model() + test_azure_openai_model() # test_deepseek_model() # test_ollama_model() - test_deepseek_r1_model() + # test_deepseek_r1_model() # test_deepseek_r1_ollama_model() # test_mistral_model() # test_ibm_model()