Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorin committed May 8, 2017
0 parents commit 580f49e
Show file tree
Hide file tree
Showing 11 changed files with 968 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
composer.lock
31 changes: 31 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "dmore/chrome-headless-mink-driver",
"description": "Mink driver for controlling headless chrome without selenium",
"type": "library",
"license": "BSD",
"authors": [
{
"name": "Dorian More",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"DMore\\ChromeDriver\\": "src/"
}
},

"autoload-dev": {
"psr-4": {
"DMore\\ChromeDriverTests\\": "tests/"
}
},
"minimum-stability": "stable",
"require-dev": {
"phpunit/phpunit": "^5.0.0"
},
"require": {
"textalk/websocket": "^1.2.0",
"behat/mink": "1.*"
}
}
48 changes: 48 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM php:7.0-fpm

RUN sed -i -e "s/;daemonize\s*=\s*yes/daemonize = no/g" /usr/local/etc/php-fpm.conf \
&& sed -i -e "s/;catch_workers_output\s*=\s*yes/catch_workers_output = yes/g" /usr/local/etc/php-fpm.d/www.conf \
&& sed -i -e "s/pm.max_children = 5/pm.max_children = 9/g" /usr/local/etc/php-fpm.d/www.conf \
&& sed -i -e "s/pm.start_servers = 2/pm.start_servers = 3/g" /usr/local/etc/php-fpm.d/www.conf \
&& sed -i -e "s/pm.min_spare_servers = 1/pm.min_spare_servers = 2/g" /usr/local/etc/php-fpm.d/www.conf \
&& sed -i -e "s/pm.max_spare_servers = 3/pm.max_spare_servers = 4/g" /usr/local/etc/php-fpm.d/www.conf \
&& sed -i -e "s/pm.max_requests = 500/pm.max_requests = 200/g" /usr/local/etc/php-fpm.d/www.conf

RUN apt-get update -qqy \
&& apt-get -qqy install wget ca-certificates apt-transport-https nginx supervisor ttf-wqy-zenhei ttf-unfonts-core \
unzip git \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*


RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update -qqy \
&& apt-get -qqy install google-chrome-unstable \
&& rm /etc/apt/sources.list.d/google-chrome.list \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*

RUN useradd headless --shell /bin/bash --create-home \
&& usermod -a -G sudo headless \
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \
&& echo 'headless:nopassword' | chpasswd

RUN mkdir /data

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& rm -rf /etc/nginx/sites-enabled/default \
&& mkdir -p /root/.ssh \
&& echo "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config

VOLUME /code

WORKDIR /code

COPY files/supervisord.conf /etc/supervisord.conf

COPY files/entrypoint.sh /entrypoint.sh

COPY files/mink_vhost.conf /etc/nginx/sites-enabled/mink

ENTRYPOINT ["/entrypoint.sh"]

CMD ["bash"]
11 changes: 11 additions & 0 deletions docker/files/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

umask 000

/usr/bin/supervisord -n -c /etc/supervisord.conf > /dev/null 2>&1 &

if [[ $# -eq 1 && $1 == "bash" ]]; then
$@
else
exec "$@"
fi
31 changes: 31 additions & 0 deletions docker/files/mink_vhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
server {
listen 80 default_server;
listen [::]:80 default_server;

root /code/vendor/behat/mink/driver-testsuite/web-fixtures;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}


location ~ \.php$ {
index index.html index.htm index.php;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_pass localhost:9000;
fastcgi_read_timeout 3600s;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
}
}
56 changes: 56 additions & 0 deletions docker/files/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)

[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=warn ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
user=root ;

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket

[program:php-fpm]
command=/usr/local/sbin/php-fpm -R
autostart=true
autorestart=true
priority=5
stdout_logfile=NONE
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:nginx]
command=/usr/sbin/nginx
autostart=true
autorestart=true
priority=10
stdout_logfile=NONE
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stdout_events_enabled=false
stderr_events_enabled=true

[program:chrome]
command=/usr/bin/google-chrome-unstable --disable-gpu --headless --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 --no-sandbox
autostart=true
autorestart=true
priority=10
stdout_logfile=NONE
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stdout_events_enabled=false
stderr_events_enabled=true
20 changes: 20 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true" bootstrap="vendor/behat/mink/driver-testsuite/bootstrap.php">
<testsuites>
<testsuite name="Driver test suite">
<directory>tests</directory>
<directory>vendor/behat/mink/driver-testsuite/tests</directory>
</testsuite>
</testsuites>

<php>
<var name="driver_config_factory" value="DMore\ChromeDriverTests\ChromeDriverConfig::getInstance" />
</php>

<filter>
<whitelist>
<directory>./src/Behat/Mink/Driver</directory>
</whitelist>
</filter>
</phpunit>
11 changes: 11 additions & 0 deletions socket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
require('vendor/autoload.php');

use WebSocket\Client;

$client = new Client("ws://localhost:9222/devtools/page/8317cd68-f29f-44f0-a1bd-ea0fd5b825aa");

while ($line = fgets(STDIN)) {
$client->send($line);
var_dump($client->receive());
}
Loading

0 comments on commit 580f49e

Please sign in to comment.