hivesolutions / headless

Simple headless browser API
https://headless.hive.pt
1 stars 2 forks source link

Docker build fails on arm64 due to Phantom.js lack of support #13

Closed hugo-gomes closed 8 months ago

hugo-gomes commented 8 months ago

Description

The build process fails when attempting to build the Docker images provided by the headless project on an arm64 architecture system. This issue is due to the need for arm64 support from Phantom.js, one of the back-end engines utilized by the project for rendering images and PDFs from HTML.

Expected Behavior

The Docker build process should be completed successfully on arm64 architecture, allowing the headless project to be used in such environments.

Actual Behavior

The build process fails on arm64 systems because Phantom.js does not provide binaries compatible with this architecture.

Possible Solutions

Conditional Dependency Management: Implement logic within the Dockerfile or build scripts to skip the installation of Phantom.js or use alternative methods when detecting an arm64 architecture. Documentation: Update the project's documentation to indicate the current architecture limitations and provide guidance or workarounds for arm64 system users.

joamag commented 8 months ago

@hugo-gomes posting here the current error

PhantomJS is not installed, the Phantom engine will not be available
2024-02-27 18:25:49,43 [INFO] Listening on 0.0.0.0:8080
2024-02-27 18:25:49,66 [INFO] Exiting on user's request
/app/node_modules/@puppeteer/browsers/lib/cjs/launch.js:267
                reject(new Error([
                       ^

Error: Failed to launch the browser process!
rosetta error: failed to open elf at /lib64/ld-linux-x86-64.so.2

TROUBLESHOOTING: https://pptr.dev/troubleshooting

    at Interface.onClose (/app/node_modules/@puppeteer/browsers/lib/cjs/launch.js:267:24)
    at Interface.emit (node:events:529:35)
    at Interface.close (node:internal/readline/interface:534:10)
    at Socket.onend (node:internal/readline/interface:260:10)
    at Socket.emit (node:events:529:35)
    at endReadableNT (node:internal/streams/readable:1400:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v18.19.1
hugo-gomes commented 8 months ago

@joamag Google Chrome has no arm64 version available for Linux. https://github.com/GoogleChromeLabs/chrome-for-testing?tab=readme-ov-file#json-api-endpoints

The current list of supported platforms is:
* linux64
* mac-arm64
* mac-x64
* win32
* win64

However, Chromium does have an arm64 version for Linux: https://chromium.googlesource.com/chromium/src/+/master/docs/linux/chromium_packages.md

PS: Chrome has recently launched an arm version for Windows - https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/native-chromium-builds-windows-on-arm

joamag commented 8 months ago

How can we install the arm64 Chromium to use for puppeteer?

hugo-gomes commented 8 months ago

The official puppeteer image, which includes Chrome for Testing, does not have an arm64 image available - https://github.com/puppeteer/puppeteer/pkgs/container/puppeteer/183435219?tag=22.3.0

@joamag we can add Chromium by installing it from Debian and Ubuntu official repositories for ARM architectures:

Additionally, both Dockerfiles will need to set PUPPETEER_SKIP_CHROME_DOWNLOAD and PUPPETEER_EXECUTABLE_PATH accordingly.

Replacing Chrome with Chromium is not a drop-in replacement since there are some differences:

joamag commented 8 months ago

Maybe we should create a separate Dockerfile just for other CPU archs and use the strategy you're mentioning

joamag commented 8 months ago

This is now considered solved by https://github.com/hivesolutions/headless/pull/17