├── travis.json ├── Dockerfile ├── start.sh ├── LICENSE └── README.md /travis.json: -------------------------------------------------------------------------------- 1 | {"travis_build_environment":{"user":"travis","group":"travis","home":"\/home\/travis\/","update_hosts":false}} -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:12.04 2 | RUN apt-get update && apt-get install -y cron && apt-get install -y curl sudo git rsync build-essential wget ruby1.9.1 rubygems1.9.1 python-software-properties && curl -L https://www.opscode.com/chef/install.sh | bash && wget -O - https://github.com/travis-ci/travis-cookbooks/archive/master.tar.gz | tar -xz && mkdir -p /var/chef/cookbooks && cp -a travis-cookbooks-master/ci_environment/* /var/chef/cookbooks 3 | RUN apt-get -y install socat 4 | RUN adduser travis --disabled-password --gecos "" 5 | RUN mkdir /home/travis/builds 6 | ADD travis.json travis.json 7 | RUN locale-gen en_US.UTF-8 8 | ENV LANG en_US.UTF-8 9 | ENV LANGUAGE en_US:en 10 | ENV LC_ALL en_US.UTF-8 11 | RUN chmod 777 /tmp 12 | RUN echo 'travis ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers 13 | RUN chef-solo -o phantomjs -j travis.json 14 | ADD start.sh start.sh 15 | CMD sh start.sh 16 | EXPOSE 4444 17 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # get host ip 4 | export HOST_IP=$(/sbin/ip route|awk '/default/ { print $3 }') 5 | 6 | echo "Running PhantomJS in GhostDriver mode" 7 | echo "Host IP: $HOST_IP" 8 | 9 | # adding IP of a host to /etc/hosts 10 | echo "$HOST_IP dockerhost" >> /etc/hosts 11 | 12 | # adding APP_HOST to list of known hosts 13 | if [ $APP_HOST ]; 14 | then 15 | echo "Registering host $APP_HOST" 16 | echo "$HOST_IP $APP_HOST" >> /etc/hosts 17 | fi; 18 | 19 | # allow for running in test environment 20 | if [ $APP_ANY_PROTOCOL ]; 21 | then 22 | UNTRUSTED_COMMAND="--ignore-ssl-errors=true --ssl-protocol=any" 23 | else 24 | UNTRUSTED_COMMAND="" 25 | fi; 26 | 27 | # if only port provided - redirect to host+port 28 | if [ $APP_PORT ]; 29 | then 30 | echo "Registering port $APP_PORT" 31 | socat TCP4-LISTEN:$APP_PORT,fork,reuseaddr TCP4:dockerhost:$APP_PORT & 32 | fi; 33 | 34 | # starting selenium 35 | phantomjs --webdriver=4444 $UNTRUSTED_COMMAND 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Codeception PHP Testing Framework 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PhantomJsEnv 2 | =========== 3 | 4 | This is a Docker Image with PhantomJS headless browser installed. PhantomJsEnv was created to run Selenium tests on PhantomJs wihtout installing NodeJS and PhantomJS. PhantomJs is executed inside a container in ghostrdirver mode and connected from a host machine. 5 | 6 | ## Installation 7 | 8 | Grab prepacked [image from a Docker Hub](https://registry.hub.docker.com/u/davert/phantomjs-env/) 9 | 10 | ``` 11 | docker pull davert/phantomjs-env 12 | ``` 13 | 14 | 15 | Or build image by yourself. Just clone this repo and run 16 | 17 | ``` 18 | docker build -t phantomjs-env . 19 | ``` 20 | 21 | ## Usage 22 | 23 | PhantomJsEnv is able to connect to local or remote web sites. 24 | 25 | ### Accessing Remote Website 26 | 27 | Run the container and bind it to default Webdriver port `4444` 28 | 29 | ``` 30 | docker run -i -t -p 4444:4444 davert/phantomjs-env 31 | ``` 32 | 33 | ### Accessing Local Website by Port 34 | 35 | In case you want to access local website from container you can do the following: 36 | if application is run on localhost (`0.0.0.0`) on a specific port, you can pass `APP_PORT` environment variable into it: 37 | 38 | ``` 39 | php -S 0.0.0.0:8000 & 40 | docker run -i -t -p 4444:4444 -e APP_PORT=8000 davert/phantomjs-env 41 | ``` 42 | 43 | ### Accessing Local Website by Host 44 | 45 | In case local web site is served by nginx or Apache, and is configured for a specific host, you can pass host name as environment variable: 46 | 47 | ``` 48 | docker run -i -t -p 4444:4444 -e APP_HOST=myapp davert/phantomjs-env 49 | ``` 50 | 51 | ### Accessing Site with self-signed certificate 52 | 53 | If you want to test site in local environment without proper SSL certificate, you can pass APP_ANY_PROTOCOL setting as environment variable: 54 | 55 | ``` 56 | docker run -i -t -p 4444:4444 -e APP_ANY_PROTOCOL=true davert/phantomjs-env 57 | ``` 58 | --------------------------------------------------------------------------------