Skip to content
This repository has been archived by the owner on Aug 9, 2019. It is now read-only.

Commit

Permalink
replace phantomjs with Firefox/geckodriver
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
Arne Neumann committed Feb 22, 2018
1 parent cce6cde commit 01f23b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
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

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"]
8 changes: 5 additions & 3 deletions src/rstviewer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 01f23b8

Please # to comment.