daisy / ace

Ace by DAISY, an Accessibility Checker for EPUB
MIT License
74 stars 22 forks source link

Ace HTTP CLI Dockerfile and .dockerignore #373

Open josteinaj opened 2 years ago

josteinaj commented 2 years ago

Added Dockerfile. Fixes #372.

➜  ace git:(dockerfile) docker build .  
(…)
Successfully built 69fe3399436f
➜  ace git:(dockerfile) docker run --network host --rm -it --env ACE_PORT=80 69fe3399436f
yarn run v1.22.19
$ /usr/src/ace/node_modules/.bin/ace-http -v
1.2.7-alpha.3
Done in 0.37s.
yarn run v1.22.19
$ /usr/src/ace/node_modules/.bin/ace-http -H localhost -p 80 -l en
info:    [ace-http] server listening on http://localhost:80
➜  ~ curl http://localhost/jobs   
[]%
➜  ~ curl --form "epub=@/tmp/X60352A.epub" http://localhost/jobs/

{"job":"http://localhost:80/jobs/500dffb1-79bb-4c49-a504-b3bd9a6eaa04","status":1,"report":{}}%                                                                 
➜  ~ curl http://localhost:80/jobs/500dffb1-79bb-4c49-a504-b3bd9a6eaa04
{"job":"http://localhost:80/jobs/500dffb1-79bb-4c49-a504-b3bd9a6eaa04","status":1,"report":{}}%                                                                 
➜  ~ curl http://localhost:80/jobs/500dffb1-79bb-4c49-a504-b3bd9a6eaa04
{"job":"http://localhost:80/jobs/500dffb1-79bb-4c49-a504-b3bd9a6eaa04","status":0,"report":{"zip":"http://localhost:80/jobs/500dffb1-79bb-4c49-a504-b3bd9a6eaa04/report/?type=zip","json":"http://localhost:80/jobs/500dffb1-79bb-4c49-a504-b3bd9a6eaa04/report/?type=json"}}%
danielweck commented 1 year ago

Hello, is apt-get install -y chromium really necessary, given that yarn install ensures Puppeteer is available to Ace's NodeJS scripts?

josteinaj commented 1 year ago

Hi!

Without apt-get install -y chromium, I get this when submitting a job to the API:

~/ace dockerfile !1 ❯ docker run --network host --rm -it --env ACE_PORT=80 dd4e0ac5be41
yarn run v1.22.19
$ /usr/src/ace/node_modules/.bin/ace-http -v
1.2.7-alpha.3
Done in 0.41s.
yarn run v1.22.19
$ /usr/src/ace/node_modules/.bin/ace-http -H localhost -p 80 -l en
info:    [ace-http] server listening on http://localhost:80
info:    [ace-http] Job started
info:    Processing /tmp/tmp-59-CW3qH3ly22aH/f8ad363d67976a50d301a7374410f050
info:    Parsing EPUB
info:    Analyzing accessibility metadata
info:    Checking package...
info:    - EPUB/package.opf: No issues found
error:   Ace processing error: Failed to launch the browser process!
/usr/src/ace/node_modules/puppeteer/.local-chromium/linux-991974/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

TypeError: Cannot read properties of undefined (reading 'internal')
    at /usr/src/ace/packages/ace-http/lib/index.js:195:57
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

With chromium installed using apt-get, it works:

~/ace dockerfile ❯ docker run --network host --rm -it --env ACE_PORT=80 a6c87e548719
yarn run v1.22.19
$ /usr/src/ace/node_modules/.bin/ace-http -v
1.2.7-alpha.3
Done in 0.42s.
yarn run v1.22.19
$ /usr/src/ace/node_modules/.bin/ace-http -H localhost -p 80 -l en
info:    [ace-http] server listening on http://localhost:80
info:    [ace-http] Job started
info:    Processing /tmp/tmp-59-e0vipyz29w3u/0d65d56cc5f1ba2d97eb93c95d45b9c1
info:    Parsing EPUB
info:    Analyzing accessibility metadata
info:    Checking package...
info:    - EPUB/package.opf: No issues found
info:    Checking documents...
info:    - X60352A-02-titlepage.xhtml: No issues found
info:    - X60352A-03-colophon.xhtml: No issues found
info:    - X60352A-01-cover.xhtml: No issues found
info:    - X60352A-04-foreword.xhtml: No issues found
info:    - X60352A-06-chapter.xhtml: No issues found
info:    - X60352A-07-chapter.xhtml: No issues found
info:    - X60352A-08-chapter.xhtml: No issues found
info:    - X60352A-05-chapter.xhtml: No issues found
info:    - X60352A-09-chapter.xhtml: No issues found
info:    - X60352A-10-chapter.xhtml: No issues found
info:    - X60352A-11-chapter.xhtml: No issues found
info:    - X60352A-12-chapter.xhtml: No issues found
info:    - X60352A-14-backmatter.xhtml: No issues found
info:    - nav.xhtml: No issues found
info:    - X60352A-13-chapter.xhtml: 8 issues found
info:    Consolidating results...
info:    Copying data
info:    Saving JSON report
info:    Saving HTML report
info:    Done.
info:    [ace-http] Job finished 9a2a513b-16b9-46c6-9b23-f30148c66866
danielweck commented 1 year ago

Thank you for the explanation. I am familiar with globally or locally installing Chromium, Firefox etc. "drivers" in some cases with unit tests frameworks, but I incorrectly assumed that Puppeteer pulled-in the correct build of Chromium by default as its peer dependency. I wonder if the xvfb APT package (and its xvfb-run executable) would trigger an environment / platform detection in Puppeteer, causing it to choose the appropriate Chromium build in its postinstall step?

josteinaj commented 1 year ago

I tried installing xvfb and running all the yarn-commands through xvfb-run now, but I get the same error.

josteinaj commented 1 year ago

In the Dockerfile in this PR, the ace source code is added before installing chromium. That way, when the ace code changes, the latest version of chromium will be installed through apt-get.

josteinaj commented 1 year ago

I rabased onto master now. Same behavior.

danielweck commented 1 year ago

Note that Puppeteer v20 switched to Chrome instead of Chromium, but Ace remains on an older version due to other breaking changes that make it impossible to upgrade at this moment in time: https://github.com/puppeteer/puppeteer/releases/tag/puppeteer-v20.0.0

danielweck commented 1 month ago

Let's keep this ace-http Docker PR open for now, but see https://github.com/daisy/ace/issues/392#issuecomment-2078316146 for further information about headless Puppeteer vs. Electron