Created
May 20, 2017 14:57
-
-
Save rajivr/48bbee7225d131be30cbdb531a81e3cc to your computer and use it in GitHub Desktop.
Example of using Xvfb, Selenium, Firefox ESR on `baseimage-amzn`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of using Xvfb, Selenium, Firefox ESR on `baseimage-amzn` | |
# | |
# Build and run Docker container | |
# | |
# ``` | |
# $ docker build -t xvfb-firefox-esr-selenium-webdriver . | |
# $ docker run --rm \ | |
# -v /tmp:/tmp -v /dev/shm:/dev/shm \ | |
# --privileged -ti xvfb-firefox-esr-selenium-webdriver /sbin/my_init -- /bin/bash -l | |
# ``` | |
# | |
# Once inside the Docker container, create `/root/google.rb` using `vi` | |
# | |
# ``` | |
# [root@e609592f773e] / # cd /root | |
# [root@e609592f773e] /root # vi google.rb | |
# ``` | |
# | |
# Following is the contents of `/root/google.rb` | |
# | |
# ``` | |
# require 'headless' | |
# require 'selenium-webdriver' | |
# | |
# Selenium::WebDriver::Firefox::Binary.path='/usr/local/firefox/firefox' | |
# | |
# headless = Headless.new | |
# headless.start | |
# | |
# browser = Selenium::WebDriver.for :firefox | |
# browser.navigate.to "https://google.com" | |
# browser.save_screenshot("/tmp/google.png") | |
# | |
# browser.quit | |
# headless.destroy | |
# ``` | |
# | |
# After creating `/root/google.rb` you can run Selenium and Firefox using Xvfb | |
# | |
# ``` | |
# [root@e609592f773e] /root # ruby2.3 google.rb | |
# [root@e609592f773e] /root # ls /tmp/ | |
# google.png | |
# ``` | |
# | |
# That's it! | |
# | |
# You can learn more about Selenium Ruby Bindings at, | |
# | |
# http://redgreenrepeat.com/2016/07/29/selenium-ruby/ | |
# https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings | |
# | |
FROM lambdalinux/baseimage-amzn:2017.03-001 | |
CMD ["/sbin/my_init"] | |
RUN \ | |
mkdir /tmp/docker-build && \ | |
# yum | |
yum update && \ | |
\ | |
yum install alsa-lib && \ | |
yum install bzip2 && \ | |
yum install gcc48 && \ | |
yum install liberation-mono-fonts && \ | |
yum install liberation-sans-fonts && \ | |
yum install liberation-serif-fonts && \ | |
yum install ruby23 && \ | |
yum install ruby23-devel && \ | |
yum install vim-minimal && \ | |
# setup epll repository | |
curl -X GET -o /tmp/docker-build/RPM-GPG-KEY-lambda-epll https://lambda-linux.io/RPM-GPG-KEY-lambda-epll && \ | |
rpm --import /tmp/docker-build/RPM-GPG-KEY-lambda-epll && \ | |
curl -X GET -o /tmp/docker-build/epll-release-2017.03-1.2.ll1.noarch.rpm https://lambda-linux.io/epll-release-2017.03-1.2.ll1.noarch.rpm && \ | |
yum install /tmp/docker-build/epll-release-2017.03-1.2.ll1.noarch.rpm && \ | |
yum --enablerepo=epll install firefox-compat && \ | |
\ | |
# install firefox esr | |
pushd /tmp/docker-build && \ | |
curl -L "https://download.mozilla.org/?product=firefox-45.9.0esr-SSL&os=linux64&lang=en-US" > firefox-esr.tar.bz2 && \ | |
tar jxvf firefox-esr.tar.bz2 && \ | |
mv firefox /usr/local && \ | |
popd && \ | |
\ | |
gem2.3 install headless -v 2.2.3 && \ | |
gem2.3 install selenium-webdriver -v 2.53.4 && \ | |
# cleanup | |
rm -rf /tmp/docker-build && \ | |
yum clean all && \ | |
rm -rf /var/cache/yum/* && \ | |
rm -rf /tmp/* && \ | |
rm -rf /var/tmp/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment