From 881cbfb8c255a0b5753756dcd96cebb69f22a5f4 Mon Sep 17 00:00:00 2001 From: Taufek Johar Date: Thu, 28 Sep 2017 17:59:16 +0800 Subject: [PATCH] Install Dependencies to Run Dusk Tests **Why we need this change?** Currently we are unable to run Dusk (Browser) tests in workspace container. This change, is to allow us to install all dependencies needed to run Dust test which consists of 1. Linux packages such as xvfb (x-virtual frame buffer to run browser in headless container) and etc. 2. Chrome browser. 3. Chrome driver. To install the Dusk dependencies. 1. Update `WORKSPACE_INSTALL_DUSK_DEPS` to true. 2. Run `docker-compose build workspace`. I've also added couple of aliases to facilitate the preparation of test environment. 1. xvfb = `Xvfb -ac :0 -screen 0 1024x768x16 &` (run x-virtual frame buffer in the background) 2. serve = `php artisan serve --quiet &` (run laravel app in the background) Once those are installed, we will need to update the default chrome driver argument in Laravel 5.5 from `--headless` to `sandbox`. Below are the steps to run Dusk in workspace. 1. `docker-compose run workspace bash` (get into workspace). 2. `laravel new dusk-test` (generate new lavarel app for testing purpose). 3. `cd dusk-test` (change directory to newly generate app folder). 4. `composer install --dev laravel/dusk` (install dusk via composer). 5. `php artisan dusk:install` (generate dusk files). 6. `sed -i '/APP_URL/d' .env` (remove APP_URL entry in .env) 7. `echo 'APP_URL=localhost:8000' >> .env` (add new APP_URL entry in .env) 8. `sed -i--'s/headless/no-sandbox/g' tests/DuskTestCase.php` (replace the default chrome driver argument). 9. `xvfb` (alias to run Xvfb instance in the background). 10. `serve` (alias to run laravel app in the background). 11. `dusk` (alias to run Dusk test). --- docker-compose.yml | 1 + env-example | 1 + workspace/Dockerfile-56 | 29 +++++++++++++++++++++++++++++ workspace/Dockerfile-70 | 29 +++++++++++++++++++++++++++++ workspace/Dockerfile-71 | 29 +++++++++++++++++++++++++++++ workspace/aliases.sh | 4 ++++ 6 files changed, 93 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index f3f34e2..75c848f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,6 +40,7 @@ services: - INSTALL_IMAGE_OPTIMIZERS=${WORKSPACE_INSTALL_IMAGE_OPTIMIZERS} - INSTALL_IMAGEMAGICK=${WORKSPACE_INSTALL_IMAGEMAGICK} - INSTALL_TERRAFORM=${WORKSPACE_INSTALL_TERRAFORM} + - INSTALL_DUSK_DEPS=${WORKSPACE_INSTALL_DUSK_DEPS} - PUID=${WORKSPACE_PUID} - PGID=${WORKSPACE_PGID} - NODE_VERSION=${WORKSPACE_NODE_VERSION} diff --git a/env-example b/env-example index 2fd338b..33c773e 100644 --- a/env-example +++ b/env-example @@ -53,6 +53,7 @@ WORKSPACE_INSTALL_PYTHON=false WORKSPACE_INSTALL_IMAGE_OPTIMIZERS=false WORKSPACE_INSTALL_IMAGEMAGICK=false WORKSPACE_INSTALL_TERRAFORM=false +WORKSPACE_INSTALL_DUSK_DEPS=false WORKSPACE_PUID=1000 WORKSPACE_PGID=1000 WORKSPACE_NODE_VERSION=stable diff --git a/workspace/Dockerfile-56 b/workspace/Dockerfile-56 index f70fc82..9ccb62c 100644 --- a/workspace/Dockerfile-56 +++ b/workspace/Dockerfile-56 @@ -525,6 +525,35 @@ RUN if [ ${INSTALL_TERRAFORM} = true ]; then \ && rm terraform_0.10.6_linux_amd64.zip \ ;fi +##################################### +# Dusk Dependencies: +##################################### +USER root +ARG INSTALL_DUSK_DEPS=false +ENV INSTALL_DUSK_DEPS ${INSTALL_DUSK_DEPS} +RUN if [ ${INSTALL_DUSK_DEPS} = true ]; then \ + # Install required packages + add-apt-repository ppa:ondrej/php \ + && apt-get update \ + && apt-get -y install zip wget unzip xdg-utils \ + libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4 xvfb \ + gtk2-engines-pixbuf xfonts-cyrillic xfonts-100dpi xfonts-75dpi \ + xfonts-base xfonts-scalable x11-apps \ + + # Install Google Chrome + && wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ + && dpkg -i --force-depends google-chrome-stable_current_amd64.deb \ + && apt-get -y -f install \ + && dpkg -i --force-depends google-chrome-stable_current_amd64.deb \ + && rm google-chrome-stable_current_amd64.deb \ + + # Install Chrome Driver + && wget https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip \ + && unzip chromedriver_linux64.zip \ + && mv chromedriver /usr/local/bin/ \ + && rm chromedriver_linux64.zip \ +;fi + # #-------------------------------------------------------------------------- # Final Touch diff --git a/workspace/Dockerfile-70 b/workspace/Dockerfile-70 index 819d88d..0daa29f 100644 --- a/workspace/Dockerfile-70 +++ b/workspace/Dockerfile-70 @@ -618,6 +618,35 @@ RUN if [ ${INSTALL_TERRAFORM} = true ]; then \ && rm terraform_0.10.6_linux_amd64.zip \ ;fi +##################################### +# Dusk Dependencies: +##################################### +USER root +ARG INSTALL_DUSK_DEPS=false +ENV INSTALL_DUSK_DEPS ${INSTALL_DUSK_DEPS} +RUN if [ ${INSTALL_DUSK_DEPS} = true ]; then \ + # Install required packages + add-apt-repository ppa:ondrej/php \ + && apt-get update \ + && apt-get -y install zip wget unzip xdg-utils \ + libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4 xvfb \ + gtk2-engines-pixbuf xfonts-cyrillic xfonts-100dpi xfonts-75dpi \ + xfonts-base xfonts-scalable x11-apps \ + + # Install Google Chrome + && wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ + && dpkg -i --force-depends google-chrome-stable_current_amd64.deb \ + && apt-get -y -f install \ + && dpkg -i --force-depends google-chrome-stable_current_amd64.deb \ + && rm google-chrome-stable_current_amd64.deb \ + + # Install Chrome Driver + && wget https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip \ + && unzip chromedriver_linux64.zip \ + && mv chromedriver /usr/local/bin/ \ + && rm chromedriver_linux64.zip \ +;fi + # #-------------------------------------------------------------------------- # Final Touch diff --git a/workspace/Dockerfile-71 b/workspace/Dockerfile-71 index 383689d..533b72f 100644 --- a/workspace/Dockerfile-71 +++ b/workspace/Dockerfile-71 @@ -624,6 +624,35 @@ RUN if [ ${INSTALL_TERRAFORM} = true ]; then \ && rm terraform_0.10.6_linux_amd64.zip \ ;fi +##################################### +# Dusk Dependencies: +##################################### +USER root +ARG INSTALL_DUSK_DEPS=false +ENV INSTALL_DUSK_DEPS ${INSTALL_DUSK_DEPS} +RUN if [ ${INSTALL_DUSK_DEPS} = true ]; then \ + # Install required packages + add-apt-repository ppa:ondrej/php \ + && apt-get update \ + && apt-get -y install zip wget unzip xdg-utils \ + libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4 xvfb \ + gtk2-engines-pixbuf xfonts-cyrillic xfonts-100dpi xfonts-75dpi \ + xfonts-base xfonts-scalable x11-apps \ + + # Install Google Chrome + && wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ + && dpkg -i --force-depends google-chrome-stable_current_amd64.deb \ + && apt-get -y -f install \ + && dpkg -i --force-depends google-chrome-stable_current_amd64.deb \ + && rm google-chrome-stable_current_amd64.deb \ + + # Install Chrome Driver + && wget https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip \ + && unzip chromedriver_linux64.zip \ + && mv chromedriver /usr/local/bin/ \ + && rm chromedriver_linux64.zip \ +;fi + # #-------------------------------------------------------------------------- # Final Touch diff --git a/workspace/aliases.sh b/workspace/aliases.sh index 3e9bbb6..29fc22d 100644 --- a/workspace/aliases.sh +++ b/workspace/aliases.sh @@ -69,6 +69,7 @@ alias migrate="php artisan migrate" alias refresh="php artisan migrate:refresh" alias rollback="php artisan migrate:rollback" alias seed="php artisan:seed" +alias serve="php artisan serve --quiet &" alias phpunit="./vendor/bin/phpunit" alias pu="phpunit" @@ -88,6 +89,9 @@ alias reload="source ~/.aliases && echo \"$COL_GREEN ==> Aliases Reloaded... $CO alias run="npm run" alias tree="xtree" +# Xvfb +alias xvfb="Xvfb -ac :0 -screen 0 1024x768x16 &" + # requires installation of 'https://www.npmjs.com/package/npms-cli' alias npms="npms search" # requires installation of 'https://www.npmjs.com/package/package-menu-cli'