From 01f23b885de5cd5e074fe1537693d56622d3f1ad Mon Sep 17 00:00:00 2001 From: Arne Neumann Date: Thu, 22 Feb 2018 10:24:24 +0100 Subject: [PATCH] replace phantomjs with Firefox/geckodriver - phantomjs is deprecated and didn't work correctly when used inside a Docker container (RST tree would have no EDU texts when converted to .png images) --- Dockerfile | 12 ++++++++++-- src/rstviewer/main.py | 8 +++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6ba56ac..2e2d3fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,19 @@ FROM nlpbox/nlpbox-base:16.04 RUN apt-get update -y && apt-get upgrade -y && \ - apt-get install -y python-pip phantomjs && \ + apt-get install -y python-pip phantomjs firefox && \ pip2 install selenium pudb +# settings for interactive debugging ADD pudb.cfg /root/ +# install geckodriver for headless browsing with selenium +WORKDIR /usr/local/bin +RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz && \ + tar -xvzf geckodriver-v0.19.1-linux64.tar.gz && \ + rm geckodriver-v0.19.1-linux64.tar.gz + + WORKDIR /opt RUN git clone https://github.com/arne-cl/rstviewer.git @@ -13,6 +21,6 @@ WORKDIR /opt/rstviewer RUN python2 setup.py install # workaround for PhantomJS error "QXcbConnection: Could not connect to display " -ENV QT_QPA_PLATFORM offscreen +# ENV QT_QPA_PLATFORM offscreen ENTRYPOINT ["rstviewer"] diff --git a/src/rstviewer/main.py b/src/rstviewer/main.py index 017da25..192d004 100755 --- a/src/rstviewer/main.py +++ b/src/rstviewer/main.py @@ -305,12 +305,14 @@ def rs3topng(rs3_filepath, png_filepath=None): temp.close() try: - driver = webdriver.PhantomJS() + opts = webdriver.firefox.options.Options() + opts.add_argument('--headless') + driver = webdriver.Firefox(options=opts) except WebDriverException as err: raise WebDriverException( - 'Please install phantomjs: http://phantomjs.org/\n' + err.msg) + 'Please install Firefox and geckodriver: https://github.com/mozilla/geckodriver/releases\n' + err.msg) - driver.get(temp.name) + driver.get("file://{}".format(temp.name)) os.unlink(temp.name) png_str = driver.get_screenshot_as_png()