Skip to content

Commit 1d9a82b

Browse files
committed
Initial commit
0 parents  commit 1d9a82b

File tree

10 files changed

+453
-0
lines changed

10 files changed

+453
-0
lines changed

Dockerfile

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
FROM ubuntu:xenial
3+
MAINTAINER Chilio
4+
5+
ENV DEBIAN_FRONTEND noninteractive
6+
ENV DEBCONF_NONINTERACTIVE_SEEN true
7+
ENV LC_ALL=en_US.UTF-8
8+
ENV DISPLAY :99
9+
ENV SCREEN_RESOLUTION 1920x720x24
10+
ENV CHROMEDRIVER_PORT 9515
11+
12+
ENV TMPDIR=/tmp
13+
14+
RUN apt-get update -y
15+
RUN apt-get install -yq apt-utils zip unzip
16+
RUN apt-get install -yq openssl language-pack-en-base
17+
RUN apt-get install -yq software-properties-common curl
18+
RUN add-apt-repository ppa:ondrej/php
19+
RUN sed -i'' 's/archive\.ubuntu\.com/us\.archive\.ubuntu\.com/' /etc/apt/sources.list
20+
RUN apt-get update
21+
RUN apt-get upgrade -yq
22+
RUN apt-get install -yq libgd-tools
23+
RUN apt-get install -yq --fix-missing php7.1-fpm php7.1-cli php7.1-xml php7.1-zip php7.1-curl php7.1-bcmath php7.1-json \
24+
php7.1-mbstring php7.1-pgsql php7.1-mysql php7.1-mcrypt php7.1-gd php-xdebug php-imagick imagemagick nginx
25+
26+
RUN apt-get install -yq mc lynx mysql-client bzip2 make g++
27+
28+
ENV COMPOSER_HOME /usr/local/share/composer
29+
ENV COMPOSER_ALLOW_SUPERUSER 1
30+
ENV PATH "$COMPOSER_HOME:$COMPOSER_HOME/vendor/bin:$PATH"
31+
RUN \
32+
mkdir -pv $COMPOSER_HOME && chmod -R g+w $COMPOSER_HOME \
33+
&& curl -o /tmp/composer-setup.php https://getcomposer.org/installer \
34+
&& curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig \
35+
&& php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) \
36+
!== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); \
37+
echo 'Invalid installer' . PHP_EOL; exit(1); }" \
38+
&& php /tmp/composer-setup.php --filename=composer --install-dir=$COMPOSER_HOME
39+
40+
ADD commands/xvfb.init.sh /etc/init.d/xvfb
41+
42+
ADD commands/start-nginx-ci-project.sh /usr/bin/start-nginx-ci-project
43+
44+
ADD configs/.bowerrc /root/.bowerrc
45+
46+
RUN chmod +x /usr/bin/start-nginx-ci-project
47+
ADD commands/configure-laravel.sh /usr/bin/configure-laravel
48+
49+
RUN chmod +x /usr/bin/configure-laravel
50+
51+
RUN \
52+
apt-get install -yq xvfb gconf2 fonts-ipafont-gothic xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base \
53+
xfonts-scalable \
54+
&& chmod +x /etc/init.d/xvfb \
55+
&& CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` \
56+
&& mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION \
57+
&& curl -sS -o /tmp/chromedriver_linux64.zip \
58+
http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip \
59+
&& unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION \
60+
&& rm /tmp/chromedriver_linux64.zip \
61+
&& chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver \
62+
&& ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver \
63+
&& curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
64+
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
65+
&& apt-get -yqq update && apt-get -yqq install google-chrome-stable x11vnc
66+
67+
RUN apt-get install -yq apt-transport-https
68+
RUN apt-get install -yq python-software-properties
69+
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
70+
RUN apt-get update
71+
RUN apt-get install -yq nodejs
72+
RUN apt-get install -yq git
73+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
74+
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
75+
76+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
77+
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
78+
RUN apt-get update && apt-get install -yq yarn
79+
RUN yarn global add bower --network-concurrency 1
80+
RUN wget https://phar.phpunit.de/phpunit.phar
81+
RUN chmod +x phpunit.phar
82+
RUN mv phpunit.phar /usr/local/bin/phpunit
83+
84+
RUN npm install -g node-gyp
85+
RUN npm install -g node-sass
86+
RUN npm install -g gulp
87+
88+
RUN apt-get install -y supervisor
89+
90+
ADD configs/supervisord.conf /etc/supervisor/supervisord.conf
91+
92+
ADD configs/nginx-default-site /etc/nginx/sites-available/default
93+
94+
VOLUME [ "/var/log/supervisor" ]
95+
96+
RUN apt-get -yq clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
97+
RUN apt-get upgrade
98+
RUN apt-get autoremove
99+
100+
RUN php --version
101+
RUN yarn --version
102+
RUN nginx -v
103+
RUN nodejs --version
104+
RUN npm --version
105+
RUN bower --version
106+
RUN phpunit --version
107+
RUN node-sass --version
108+
RUN gulp --version
109+
110+
EXPOSE 80 9515
111+
112+
CMD ["php7.1-fpm", "-g", "daemon off;"]
113+
CMD ["nginx", "-g", "daemon off;"]

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2017 chilio
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# This is docker image for running Laravel 5.5 Dusk tests
2+
3+
[![Docker automated](https://img.shields.io/docker/automated/chilio/laravel-dusk-ci.svg)](https://hub.docker.com/r/chilio/laravel-dusk-ci) [![Docker build](https://img.shields.io/docker/build/chilio/laravel-dusk-ci.svg)](https://hub.docker.com/r/chilio/laravel-dusk-ci) [![Docker pulls](https://img.shields.io/docker/pulls/chilio/laravel-dusk-ci.svg)](https://hub.docker.com/r/chilio/laravel-dusk-ci) [![GitHub tag](https://img.shields.io/github/tag/chilio/laravel-dusk-ci.svg)](https://github.com/chilio/laravel-dusk-ci/tags) [![GitHub issues](https://img.shields.io/github/issues/chilio/laravel-dusk-ci.svg)](https://github.com/chilio/laravel-dusk-ci/issues) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/chilio/test-dusk/master/LICENSE)
4+
5+
This is **complete** test suite for **Laravel 5.5** with **Dusk browser tests** enabled running on docker.
6+
7+
You can safely use this for testing purposes in **gitlab environments**, especially gitlab ci runners.
8+
9+
##### **What's included?**
10+
11+
| FRAMEWORK | VERSION |
12+
| --------- | ------- |
13+
| PHP | 7.1.9.1 |
14+
| NGINX | 1.10.3 |
15+
| NODEJS | 6.11.3 |
16+
| NPM | 3.10.10 |
17+
| YARN | 1.0.2 |
18+
| BOWER | 1.8.0 |
19+
| PHPUNIT | 6.3.0 |
20+
| NODE-SASS | 4.3.0 |
21+
| GULP | 3.9.1 |
22+
23+
##### **Available additional commands:**
24+
25+
`start-nginx-ci-project` - configures and starts nginx php-fpm
26+
27+
`configure-laravel` - runs laravel build routines (change path permissions, execute artisan commands)
28+
29+
##### **Note:**
30+
31+
This build is tested with **mysql**, but probably works with other docker db engines
32+
33+
To successfully run mysql add to your test routine:
34+
35+
services:
36+
37+
- mysql:5.7
38+
39+
And in your .env mark mysql as the right resource
40+
41+
##### **Usage:**
42+
43+
In your .gitlab-ci.yml use this image like:
44+
45+
`image: chilio/laravel-dusk-ci:stable`
46+
47+
add script line:
48+
49+
`- start-nginx-ci-project` ***<-- THIS IS THE IMPORTANT POINT BEFORE RUNNING DUSK***
50+
51+
Finally you can run all your tests served by nginx | php-fpm.
52+
53+
------
54+
55+
Further examples (use it if needed):
56+
57+
`- yarn --network-concurrency 1` # when you have problems with slow connection
58+
59+
`- composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts`
60+
61+
`- cp .env.example .env` ***<-- APP_URL=http://localhost AND DB_HOST=mysql***
62+
63+
64+
`- bower install --allow-root --quiet`
65+
66+
`- npm run dev ` or if you are on yarn registry `- yarn run dev `
67+
68+
`- configure-laravel`
69+
70+
`./vendor/phpunit/phpunit/phpunit -v --coverage-text --colors --stderr`
71+
72+
`- php artisan dusk`
73+
74+
##### **Examples:**
75+
76+
[**gitlab-ci.yml with stages and cache** (assuming you are on gitlab-multi-runner v9.5 and using scripts like "dev" in package.json):](examples/.gitlab-ci.yml)
77+
78+
##### **Caveats:**
79+
80+
- In your dusk tests use ->waitFor() to make sure page is rendered properly
81+
- Remember to set up .env variables properly -> especially DB_HOST=mysql , APP_URL=http://localhost
82+
- **gitlab-multi-runner is evolving** (especially changes in cache functionality), in case of problems make sure you are using 9.5.0 version, which worked at this moment
83+
84+
##### **Updates**:
85+
86+
- bower does not need **--allow-root** anymore, in case you want to use it in this docker container
87+
- yarn does not need **--network-concurrency 1** anymore - you can always try if you experience problems
88+
- always better use `yarn run dev` instead of `npm run dev` if you have this script configured in package.json
89+

commands/configure-laravel.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
cd ${CI_PROJECT_DIR}
3+
chmod -R 775 storage
4+
chmod 775 bootstrap/cache
5+
chown -R www-data ./
6+
php artisan key:generate
7+
php artisan migrate:refresh --seed

commands/start-nginx-ci-project.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
sed -i "s|root /var/www/html/public;|root ${CI_PROJECT_DIR}/public;|" /etc/nginx/sites-available/default
3+
service php7.1-fpm start
4+
service nginx start

commands/xvfb.init.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
### BEGIN INIT INFO
4+
# Provides: Xvfb
5+
# Required-Start:
6+
# Required-Stop:
7+
# Default-Start:
8+
# Default-Stop:
9+
# Short-Description: Stop/start Xvfb
10+
### END INIT INFO
11+
12+
XVFB=/usr/bin/Xvfb
13+
XVFBARGS="$DISPLAY -screen 0 $SCREEN_RESOLUTION -ac +extension GLX +render -noreset";
14+
PIDFILE='/var/run/xvfb.pid';
15+
16+
case "$1" in
17+
start)
18+
echo -n "Starting virtual X frame buffer: Xvfb"
19+
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
20+
echo "."
21+
;;
22+
stop)
23+
echo -n "Stopping virtual X frame buffer: Xvfb"
24+
start-stop-daemon --stop --quiet --pidfile $PIDFILE
25+
echo "."
26+
;;
27+
restart)
28+
$0 stop
29+
$0 start
30+
;;
31+
*)
32+
echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
33+
exit 1
34+
esac
35+
36+
exit 0

configs/.bowerrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "allow_root": true }

configs/nginx-default-site

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
##
2+
# You should look at the following URL's in order to grasp a solid understanding
3+
# of Nginx configuration files in order to fully unleash the power of Nginx.
4+
# http://wiki.nginx.org/Pitfalls
5+
# http://wiki.nginx.org/QuickStart
6+
# http://wiki.nginx.org/Configuration
7+
#
8+
# Generally, you will want to move this file somewhere, and start with a clean
9+
# file but keep this around for reference. Or just disable in sites-enabled.
10+
#
11+
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
12+
##
13+
14+
# Default server configuration
15+
#
16+
server {
17+
listen 80 default_server;
18+
listen [::]:80 default_server;
19+
20+
# SSL configuration
21+
#
22+
# listen 443 ssl default_server;
23+
# listen [::]:443 ssl default_server;
24+
#
25+
# Note: You should disable gzip for SSL traffic.
26+
# See: https://bugs.debian.org/773332
27+
#
28+
# Read up on ssl_ciphers to ensure a secure configuration.
29+
# See: https://bugs.debian.org/765782
30+
#
31+
# Self signed certs generated by the ssl-cert package
32+
# Don't use them in a production server!
33+
#
34+
# include snippets/snakeoil.conf;
35+
36+
root /var/www/html/public;
37+
38+
# Add index.php to the list if you are using PHP
39+
index index.html index.htm index.nginx-debian.html index.php;
40+
41+
server_name _;
42+
43+
location / {
44+
# First attempt to serve request as file, then
45+
# as directory, then fall back to displaying a 404.
46+
try_files $uri $uri/ /index.php?$query_string;
47+
}
48+
49+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
50+
#
51+
location ~ \.php$ {
52+
include snippets/fastcgi-php.conf;
53+
#
54+
## With php7.0-cgi alone:
55+
#fastcgi_pass 127.0.0.1:9000;
56+
## With php7.0-fpm:
57+
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
58+
}
59+
60+
61+
# deny access to .htaccess files, if Apache's document root
62+
# concurs with nginx's one
63+
#
64+
#location ~ /\.ht {
65+
#deny all;
66+
#}
67+
}
68+
69+
70+
# Virtual Host configuration for example.com
71+
#
72+
# You can move that to a different file under sites-available/ and symlink that
73+
# to sites-enabled/ to enable it.
74+
#
75+
#server {
76+
#listen 80;
77+
#listen [::]:80;
78+
#
79+
#server_name example.com;
80+
#
81+
#root /var/www/example.com;
82+
#index index.html;
83+
#
84+
#location / {
85+
#try_files $uri $uri/ =404;
86+
#}
87+
#}
88+
89+

0 commit comments

Comments
 (0)