piqnt / svgexport

SVG to PNG/JPEG command-line tool and Node.js module
927 stars 85 forks source link

Running in docker broken #76

Open henryiii opened 4 years ago

henryiii commented 4 years ago

This currently fails to work in docker with:

npx svgexport  /tmp/tmp-2951T7QQRqKpEt1U/d58cc138.svg x.png
(node:3110) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
[0324/153017.535388:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

If the line in render.js var browser = await puppeteer.launch(); is replaced with var browser = await puppeteer.launch({args: ['--no-sandbox']});, then it works. Could this either detect it is running as root (such as in a docker image) or a way to pass args (via environment variables) be added? This is breaking a gitbook GitLab CI using the node:10 image.

henryiii commented 4 years ago

The current GitLab CI job and workaround here:

https://gitlab.com/CLIUtils/modern-cmake/-/blob/10e21db1782c0f23c65490f6534ca63b003ce82a/.gitlab-ci.yml#L15-32

MichaelRoosz commented 4 years ago

Because of security reasons it is not recommend to run docker or svgexport /pupeteer as root. If you switch to a different user for docker it will work.

henryiii commented 4 years ago

Can you do that in CI? You don't have control over how it sets up the docker run, AFAIK.