agenticSeek icon indicating copy to clipboard operation
agenticSeek copied to clipboard

Current backend dockerization progress

Open Fosowl opened this issue 10 months ago • 25 comments

I am currently working on putting backend in docker on the docker_deployement branch but I am kind of stuck on the following issue, if anyone know or find a solution feel free to reply or send a message on discord.

The issue is that I want to run the backend in docker (currently it's the only service run on host), I am implementing required change on the docker_deployement branch, it's almost finished, except that the backend service keep exiting due to a error with selenium "unable to discover open pages".

Current fix attempted:

  • Ensured chrome and chromedriver version are matching
  • Tried using chrome-headless-shell
  • Ensured binary right are correct
  • long list of possible depencies installed with apt-install in the dockerfile
  • Tried apt install approach apt-get install -y google-chrome-stable
  • tried --headless=new instead of --headless
  • Tried different configuration and chrome options (see browser.py)

To help with solving:

See https://github.com/Fosowl/agenticSeek/issues/155 to understand some of the considerations. checkout to docker_deployement branch I am currently working on. start with./start_services.sh full yes, you need to add "full" as argument to the script You should see the error as below: Suggest a workaround

Issue log:

backend   | path: /usr/local/bin/chromedriver
backend   | Traceback (most recent call last):
backend   |   File "/app/api.py", line 109, in <module>
backend   |     interaction = initialize_system()
backend   |   File "/app/api.py", line 65, in initialize_system
backend   |     create_driver(headless=config.getboolean('BROWSER', 'headless_browser'), stealth_mode=stealth_mode, lang=languages[0]),
backend   |   File "/app/sources/browser.py", line 214, in create_driver
backend   |     return webdriver.Chrome(service=service, options=chrome_options)
backend   |   File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/chrome/webdriver.py", line 47, in __init__
backend   |     super().__init__(
backend   |   File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/chromium/webdriver.py", line 69, in __init__
backend   |     super().__init__(command_executor=executor, options=options)
backend   |   File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 257, in __init__
backend   |     self.start_session(capabilities)
backend   |   File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 356, in start_session
backend   |     response = self.execute(Command.NEW_SESSION, caps)["value"]
backend   |   File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 447, in execute
backend   |     self.error_handler.check_response(response)
backend   |   File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
backend   |     raise exception_class(message, screen, stacktrace)
backend   | selenium.common.exceptions.SessionNotCreatedException: Message: session not created
backend   | from unknown error: unable to discover open pages
backend   | Stacktrace:
backend   | #0 0x55555601f29a <unknown>
backend   | #1 0x555555a8b040 <unknown>
backend   | #2 0x555555aca618 <unknown>
backend   | #3 0x555555ac48f3 <unknown>
backend   | #4 0x555555ac0a4f <unknown>
backend   | #5 0x555555b11126 <unknown>

Fosowl avatar May 29 '25 20:05 Fosowl

just tried with

docker compose up backend

and got some error as it was not able to install the chrome

Image

=> ERROR [backend 15/15] RUN CHROME_VERSION=$(google-chrome --version | grep -oP '\d+.\d+.\d+') && wget -O chromedrive 2.1s

[backend 15/15] 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:
0.562 --2025-05-31 06:49:21-- https://chromedriver.storage.googleapis.com/LATEST_RELEASE_137/chromedriver_linux64.zip
0.593 Resolving chromedriver.storage.googleapis.com (chromedriver.storage.googleapis.com)... 142.250.77.219, 142.250.77.251, 142.250.182.187, ... 1.679 Connecting to chromedriver.storage.googleapis.com (chromedriver.storage.googleapis.com)|142.250.77.219|:443... connected. 1.802 HTTP request sent, awaiting response... 404 Not Found 2.090 2025-05-31 06:49:22 ERROR 404: Not Found. 2.090


failed to solve: process "/bin/sh -c 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" did not complete successfully: exit code: 8

mannubaveja007 avatar May 31 '25 08:05 mannubaveja007

Dockerfile.backend fixes (full working setup) #265 https://github.com/Fosowl/agenticSeek/issues/265

plitc avatar May 31 '25 13:05 plitc

Dockerfile.backend fixes (full working setup) #265 #265

command i ran

docker compose up backend 
Image

from your repo the main branch of the repo https://github.com/a2s-ai/A2S_AgenticSeek

mannubaveja007 avatar May 31 '25 14:05 mannubaveja007

Dockerfile.backend fixes (full working setup) #265 #265

command i ran

docker compose up backend 
Image from your repo the main branch of the repo https://github.com/a2s-ai/A2S_AgenticSeek

@mannubaveja007 "rosetta error" ? So I’m assuming you’re trying this on an Apple Mac with an Apple Silicon chip? The “chrome” download refers to the Linux64 package, so for ARM64 users we’d need to add a platform check and download the appropriate package.

Our setup has been tested in an Ubuntu 22 VM with Docker.

plitc avatar May 31 '25 14:05 plitc

Got it. I’ve got an Ubuntu VM as well, so I’ll test everything there.

Also, to make things smoother, we could automate the setup by detecting the OS and then handling the installation steps accordingly. That way, the process becomes a lot more convenient—no need for users to worry about OS-specific steps manually.

mannubaveja007 avatar May 31 '25 14:05 mannubaveja007

@mannubaveja007

...difficult...

On a Linux host, running uname -m inside the container returns “x86_64”, whereas on a Mac it returns “aarch64”. However, on https://googlechromelabs.github.io/chrome-for-testing/ only the X64 package is provided for Linux-there is no ARM64 build available for Linux.

plitc avatar May 31 '25 17:05 plitc

Here is one I guess correct me if am wrong

mac-arm64

link --> https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.55/mac-arm64/chrome-mac-arm64.zip

anyways you are right doing this is difficult!

mannubaveja007 avatar May 31 '25 17:05 mannubaveja007

@plitc @mannubaveja007 Thank you so much for sharing with us a working solution, help a lot! I am currently attempting to integrate the required change on the docker_deployement branch and pushed my latest attempt a few minutes ago.

However I know stumble into this issue:

backend  |   File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 447, in execute
backend  |     self.error_handler.check_response(response)
backend  |   File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
backend  |     raise exception_class(message, screen, stacktrace)
backend  | selenium.common.exceptions.SessionNotCreatedException: Message: session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir

I have tried creating a temporary profile like so:

    profile_dir = f"/tmp/chrome_profile_{uuid.uuid4().hex[:8]}"
    chrome_options.add_argument(f'--user-data-dir={profile_dir}')

Remove the add_arguement doesn't fix either. Allowing chrome to run as root doesn't fix. Neither chmod777 the /tmp folder or using a non-root user in docker.

So I wonder how come you didn't run into this issue ? I see no particular change on your fork to address it. Any ideas ?

Fosowl avatar May 31 '25 17:05 Fosowl

@mannubaveja007 This is a native package for macOS (like .dmg), not for Linux when running in Docker on a Mac…

plitc avatar May 31 '25 17:05 plitc

about what you are discussing doesn't FROM --platform=linux/amd64 python:3.11-slim allow to emulate a amd64 architecture no matter the host ? Therefore there is no need to detect the OS and adapt the downloaded chrome version. Correct me if am wrong

Fosowl avatar May 31 '25 17:05 Fosowl

Seem to work just fine on mac m1 with FROM --platform=linux/amd64 now the only issue i get is for user-data-dir (see my message above)

Fosowl avatar May 31 '25 17:05 Fosowl

Seem to work just fine on mac m1 with FROM --platform=linux/amd64 now the only issue i get is for user-data-dir (see my message above)

it was tinkering in my mind but was not clear about the properly let me try changing and then things if it works...

mannubaveja007 avatar May 31 '25 17:05 mannubaveja007

@Fosowl @mannubaveja007 Once more for clarity: if no platform is specified, Docker pulls the image matching the current host platform. So when the host uses an Apple M-series chip (aarch64), Docker will fetch the native aarch64 Linux image (giving maximum performance without emulation)-but in that case the x64 build of Google Chrome won’t run. If you explicitly set the platform to “amd64” in your Docker configuration, Docker pulls the amd64 image instead; macOS on Apple M will then emulate it, and the x64 build of Google Chrome will work.

@Fosowl I spent half the day yesterday debugging to fully understand the core issues in the Docker.Backend. I kept running into various errors and fixed them. One of the main problems was the faulty communication between the front-end container and the back-end container (API service), and between SearXNG and Redis. You really have to grasp what counts as a client request, what goes from the browser to the front-end, which requests go on to the back-end, and what needs to be resolved and reachable via DNS within the container logic. Please take a close look at all six commits, since I adjusted the fixed IP or the Docker-DNS container name in various other places there. https://github.com/Fosowl/agenticSeek/compare/main...a2s-ai:A2S_AgenticSeek:main

Here are the steps summarized again: https://github.com/a2s-ai/A2S_AgenticSeek?tab=readme-ov-file#a2s-ai-build-and-run

plitc avatar May 31 '25 18:05 plitc

@mannubaveja007 @plitc I have got it working ! Forgot to change to headless in the config

Fosowl avatar May 31 '25 20:05 Fosowl

@mannubaveja007 @plitc I have got it working ! Forgot to change to headless in the config

That's Great would love to test it and if anything will fix it !

mannubaveja007 avatar Jun 01 '25 03:06 mannubaveja007

@Fosowl What doesn’t work in Docker Compose is
- SEARXNG_SECRET_KEY=$(openssl rand -hex 32) because YAML files do not support shell or command substitution. I solved it as follows: https://github.com/a2s-ai/A2S_AgenticSeek/commit/88c54681af7779aaa4454898ff0350599d00b6d5

plitc avatar Jun 01 '25 07:06 plitc

@Fosowl What doesn’t work in Docker Compose is - SEARXNG_SECRET_KEY=$(openssl rand -hex 32) because YAML files do not support shell or command substitution. I solved it as follows: a2s-ai@88c5468

I Actually tried that to solve even solved that very easily but after that due to my machine was getting errors so could't proceed. will try with my ubuntu and arch machine

mannubaveja007 avatar Jun 01 '25 07:06 mannubaveja007

@plitc depends on the OS, it work perfectly with my setup, i have only discovered recently that some users have had issue with it

Fosowl avatar Jun 02 '25 19:06 Fosowl

@mannubaveja007 I have merged the fully dockerized version on the dev branch and updated the readme (setup a bit different), would you mind to be one of the early testers ?

Fosowl avatar Jun 03 '25 16:06 Fosowl

@mannubaveja007 I have merged the fully dockerized version on the dev branch and updated the readme (setup a bit different), would you mind to be one of the early testers ?

sure let me do it

mannubaveja007 avatar Jun 03 '25 17:06 mannubaveja007

Docker Test Summary

Issue

Backend container fails at startup.

Error:

Image

Tried with both config.ini

[MAIN]
is_local = False
provider_name = google
provider_model = gemini-2.0-flash
provider_server_address = 127.0.0.1:5000 # doesn't matter

and also

[MAIN]
is_local = True # Whenever you are running locally or with remote provider.
provider_name = ollama # or lm-studio, openai, etc..
provider_model = deepseek-r1:14b # choose a model that fit your hardware
provider_server_address = 127.0.0.1:11434
agent_name = Jarvis # name of your AI
recover_last_session = True # whenever to recover the previous session
save_session = True # whenever to remember the current session
speak = False # text to speech
listen = False # Speech to text, only for CLI, experimental
jarvis_personality = False # Whenever to use a more "Jarvis" like personality (experimental)
languages = en en # The list of languages, Text to speech will default to the first language on the list
[BROWSER]
headless_browser = True # leave unchanged unless using CLI on host.
stealth_mode = True # Use undetected selenium to reduce browser detection

getting that error

mannubaveja007 avatar Jun 03 '25 18:06 mannubaveja007

you need to remove all the comment like # use undetected ... config file do not support comment @mannubaveja007

Fosowl avatar Jun 03 '25 20:06 Fosowl

you need to remove all the comment like # use undetected ... config file do not support comment @mannubaveja007

Tried without them too

Image

I guess you were also getting that error which clearly stats our selenium or the chromedriver is being crashed in between

i guess this might be due to version mismatch of chrome driver or the chromium

Image

Reason is also clearly defined here

Image

my chrome version is this but i guess some chromium version here is 134 or maybe there is some contradiction

mannubaveja007 avatar Jun 04 '25 15:06 mannubaveja007

that's impossible we explicitly download chrome and chromedriver 34.0.6998.88. can you delete the backend container and images in docker and do a full build again from the dev branch ? then run with ./start_services full

Fosowl avatar Jun 04 '25 18:06 Fosowl

Sure got it let me delete everything and the and yes am doing from dev branch only...

mannubaveja007 avatar Jun 04 '25 18:06 mannubaveja007

Backend containerization has been merged to main in #298. tested by @antoineVIVIES and myself. readme updated.

Fosowl avatar Jun 06 '25 16:06 Fosowl