seleniumhq-community / docker-seleniarm

Multi-Arch (arm64/armhf/amd64) Docker images for the Selenium Grid Server
https://hub.docker.com/u/seleniarm
Other
248 stars 24 forks source link

[🚀 Feature]: multi arch build or merge in SeleniumHQ/docker-selenium #2

Closed viktorianer closed 2 years ago

viktorianer commented 2 years ago

Feature and motivation

As I mentioned in the #1, I would like to use this image not only on arm64 platform, but also on amd64 based arch, in order to make it useful in docker-compose.yml file/projects.

In general, I would love to have this changes at SeleniumHQ#1076. But, I do not know how to help here.

I can see the images from https://github.com/sj26/docker-selenium, they are build for arm and amd. https://hub.docker.com/layers/seleniarm/node-chromium/4.0.0-beta-1-20210215/images/sha256-148f4749119f950d33229f0ec37eb772a55de97491b462830bffc46981d39869?context=explore

And these images we can use in our docker-compose.yml, without any hack. But they are not up-to-date. So, that why I am saying it would be better if these changes from here, would be included in https://github.com/SeleniumHQ/docker-selenium.

And thanks for this great work and effort! 👍🏼

Expected behaviour, when I use this image in docker-compose.yml:

version: '3.9'
services:
...
  selenium_hub:
    image: seleniarm/hub:4.0.0-beta-1-20210215
    ports:
      - 4442:4442
      - 4443:4443
      - 4444:4444

  chrome:
    image: seleniarm/node-chromium:4.0.0-beta-1-20210215
    shm_size: 2gb
    ports:
      - 5555:5555
    depends_on:
      - selenium_hub

It should build the services on arm and amd arch based host platform.

Note: the node-chromium:4.0.0-beta-1-20210215 image was build for multi arch.

Possible solutions:

Usage example with images from selenium

version: '3.9'
services:
...
  selenium_hub:
    image: selenium/hub:4
    ports:
      - 4442:4442
      - 4443:4443
      - 4444:4444

  chrome:
    image: docker pull selenium/node-chromium:4
    shm_size: 2gb
    ports:
      - 5555:5555
    depends_on:
      - selenium_hub
jamesmortensen commented 2 years ago

I agree this is possible. It's been done before in previous tags, and I've done this with a WebKit Browser container image. I should be able to dig into this over the weekend.

Updating this issue with relevant documentation:

There are a couple places I can think of that have a dependency on architecture, and these would need to be addressed, possibly by using uname -m to derive the architecture type at build time.

Dependencies on ARCH for doing a find/replace in a Java conf file in Base Docker container:

https://github.com/seleniarm/docker-selenium/blob/dab951c64b97c6c023826f0f2596da4b8ff09eaf/Base/Dockerfile#L16 https://github.com/seleniarm/docker-selenium/blob/dab951c64b97c6c023826f0f2596da4b8ff09eaf/Base/Dockerfile#L36

Dependencies on ARCH for building geckodriver from source in NodeFirefox:

https://github.com/seleniarm/docker-selenium/blob/dab951c64b97c6c023826f0f2596da4b8ff09eaf/NodeFirefox/build-step-1.sh#L8 https://github.com/seleniarm/docker-selenium/blob/dab951c64b97c6c023826f0f2596da4b8ff09eaf/NodeFirefox/build-step-2.sh#L32 https://github.com/seleniarm/docker-selenium/blob/dab951c64b97c6c023826f0f2596da4b8ff09eaf/NodeFirefox/build-step-2.sh#L40

Chromium may be easier than Firefox

Firefox has more dependencies on ARCH. If you wanted to get started sooner with Selenium/Standalone-Chromium, it has less dependencies on ARCH, so as long as the Java 11 dependency can be made multi-arch, you should be able to build a multi-arch Chromium image:

docker buildx build --platform linux/amd64,linux/arm64 -t local-seleniarm/standalone-chromium:latest .

I'll be able to look at this more over the weekend. In the meantime, hope this is helpful!

jamesmortensen commented 2 years ago

@viktorianer I made changes to the Dockerfiles and pushed multi-arch builds for base, node-base, hub, node-chromium, and standalone-chromium. Please try them out and let me know how it goes. They're currently tagged as 4.1.0-alpha-20211218 because I haven't had a chance to fully test them:

docker pull seleniarm/standalone-chromium:4.1.0-alpha-20211218
viktorianer commented 2 years ago

Hey @jamesmortensen , thank you! I asked our engineers with Linux/Windows to check it. I will come back later to this issue.

tan-linx commented 2 years ago

Hi @jamesmortensen! @viktorianer and I tested the node-chromium and hub images on our Linux and M1 systems. We still get the following errors

Selenium::WebDriver::Error::WebDriverError: You are trying to work with something that isn't a file.    
test/integration/candidate_flows_test.rb:18:in `block in <class:CandidateFlowsTest>'

with these lines of code

visit("/#!/candidates/new")
fill_in("candidate_first_name", with: "Test")

We are using the frameworks rails and angular.

Our systems are Darwin mbp-work.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000 arm64 and Linux ThinkPad-T560 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux (amd64).

viktorianer commented 2 years ago

@jamesmortensen is it possible for you to add a major version tag too, e.g. 4, when you upload the new images? Thanks a lot!

jamesmortensen commented 2 years ago

@tan-linx do these involve any kind of file uploading?

visit("/#!/candidates/new")
fill_in("candidate_first_name", with: "Test")

https://github.com/SeleniumHQ/selenium/blob/trunk/rb/lib/selenium/webdriver/remote/bridge.rb#L417

Does this happen on the standard x86 images as well, when using the ThinkPad?

jamesmortensen commented 2 years ago

The reason I ask is because I know that, when uploading files to a browser in a docker container, the file must be made available on the container filesystem. This is usually done by mounting a volume between the host and container so the container can access the files to be uploaded. Could that be the issue you're facing?

viktorianer commented 2 years ago

No, there is no file upload at all. And with old images it works, so it is not Docker (but we use Docker, yes).

Basically, you can reduce the full test to this 2 lines and it will fall.

We do not have 32 bit system to test. But I will ask other if they have possibility to test this setup too.

jamesmortensen commented 2 years ago

Does the latest tag have the same problem? The latest tag is only for arm64 but it has a stable selenium server, 4.0.0 version.

If you can isolate what might be causing the issue that would be helpful.

Also, is it just the hub images or with standalone-chromium as well? I haven't had amazing experiences with the grid on Arm64. There are crashes that occur.

viktorianer commented 2 years ago

Hey @jamesmortensen, I checked today again on my M1 MBP. On a small, private project with the latest Rails 6 setup and on our big, work project with different Rails 6 setup.

First, I checked your last image:

small project: no problems

big work project: In this project, we use Rails with Angular. Therefore, we need a proxy server, and we pass the settings to the Chrome like:

CHROME_OPTIONS = %W[... proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port} ...].freeze
Capybara.register_driver :selenium_chrome_headless do |app|
  Capybara::Selenium::Driver.new(
    app,
    ...
    capabilities: Selenium::WebDriver::Chrome::Options.new(args: CHROME_OPTIONS),
   ...
  )
end

I get a typical error on hub: [1642847813.972][SEVERE]: bind() failed: Cannot assign requested address (99) And the message, which we have described above: Selenium::WebDriver::Error::WebDriverError: You are trying to work with something that isn't a file.

Then, I tried with your latest tag:

small project: no problems

big work project: Now, I get error on chrome and no error on hub: [1642848350.618][SEVERE]: bind() failed: Cannot assign requested address (99) And the message, which we have described above: Selenium::WebDriver::Error::WebDriverError: You are trying to work with something that isn't a file. But, it alternates with the following error:Capybara::ElementNotFound: Unable to find field "person_first_name" that is not disabled`.

Last, I tried seleniarm/standalone-chromium:4.1.1-alpha-20220119: the same results The same result on an older image 4.0.0-beta-1-20210215, which we use on master.

jamesmortensen commented 2 years ago

@viktorianer Does it happen with the stock x86_64 Chrome images from upstream, or just the seleniarm ones? Are you able to replicate the issue in the small project by adding the proxy? Could the proxy be interrupting the communication flow? Could you also check the version of Capybara and confirm it's up to date/compatible with Selenium 4?

How long do tests run before the error manifests itself? Are you able to run tests without the proxy server if the app is deployed to a public test server?

jamesmortensen commented 2 years ago

Does this also happen with the Firefox image?

viktorianer commented 2 years ago

Hey @jamesmortensen, I did not have time at all for this issue at this time, so sorry to not coming back to you earlier. I would not have time to dig deeper in our "big project", because I am working on other things now.

The point is, your images working great on new project. And why not use them?

So, if it is possible for you, it would be great to have regular updated images like you did it here:

@viktorianer I made changes to the Dockerfiles and pushed multi-arch builds for base, node-base, hub, node-chromium, and standalone-chromium.

Thank you for great job and a lot of work.

If possible, it would help to include/have a major tag for each of those docker images, e.g.: 4 and 4.x.

jamesmortensen commented 2 years ago

Thanks for following back up, @viktorianer Tagging is something I'll be working on eventually.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.