Skip to content

Commit

Permalink
Merge pull request #1 from zablose/dev
Browse files Browse the repository at this point in the history
Option to add Google Chrome to run Laravel Dusk tests.
  • Loading branch information
zablose authored Nov 18, 2020
2 parents 35b5495 + 8b9716f commit 0b487fc
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
DAMP_ADD_CHROME=false
DAMP_ADD_COMPOSER=true
DAMP_ADD_LARAVEL=false
DAMP_ADD_NODEJS=false

DAMP_DB_NAME=damp
DAMP_DB_USER=damp
DAMP_DB_PASSWORD=
DAMP_DB_PASSWORD=''

DAMP_LOG=/var/log/damp.log

Expand Down
3 changes: 3 additions & 0 deletions docker-compose-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ services:
- $HOME/.composer/cache/:/home/${DAMP_USER_NAME}/.composer/cache/
- ./:${DAMP_WEB_DIR}/
- ./post-setup.example.sh:/home/${DAMP_USER_NAME}/post-setup.sh
- /tmp/.X11-unix:/tmp/.X11-unix
environment:
- DISPLAY=$DISPLAY
logging:
driver: syslog
options:
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ services:
- $HOME/.composer/cache/:/home/${DAMP_USER_NAME}/.composer/cache/
- ./web/:${DAMP_WEB_DIR}/
- ./post-setup.example.sh:/home/${DAMP_USER_NAME}/post-setup.sh
- /tmp/.X11-unix:/tmp/.X11-unix
environment:
- DISPLAY=$DISPLAY
logging:
driver: syslog
options:
Expand Down
43 changes: 43 additions & 0 deletions docker/user/install/chrome.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -e

. /usr/local/bin/exit-if-root
. /usr/local/bin/source-env-file

if [[ "${DAMP_ADD_CHROME}" != "true" ]]
then
echo 'Skipping Chrome installation ...'
exit 0
fi

driver_file=chromedriver_linux64.zip
driver_url=https://chromedriver.storage.googleapis.com
driver_version=$(curl -s ${driver_url}/LATEST_RELEASE)
apt_source=/etc/apt/sources.list.d/google-chrome.list

echo 'Installing Chrome ...'

if [[ ! -f "${apt_source}" ]]
then
{
curl -sS https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee ${apt_source}
sudo apt-get -y update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install \
dbus-x11 \
google-chrome-stable
} | sudo tee /var/log/damp-chrome-install.log 1>/dev/null
fi

echo 'Installing Chrome Driver ...'

if [[ ! -f '/usr/local/bin/chromedriver' ]]
then
log=/var/log/damp-chrome-driver-install.log
{
sudo wget -O ${driver_file} ${driver_url}/${driver_version}/${driver_file} -o ${log}
sudo unzip ${driver_file} chromedriver -d /usr/local/bin/
rm -f ${driver_file}
} | sudo tee -a ${log} 1>/dev/null
fi
8 changes: 0 additions & 8 deletions docker/user/setup/mariadb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ GRANT ALL PRIVILEGES ON *.* TO '${DAMP_USER_NAME}'@'%' IDENTIFIED BY '${DAMP_DB_
FLUSH PRIVILEGES;
EOF

file=/home/${DAMP_USER_NAME}/db.sql.sh
if [ -e "${file}" ]; then
echo "Running custom SQL script ..."
source ${file}
else
echo "Custom SQL script '${file}' not found. Skipping ..."
fi

sudo /etc/init.d/mysql stop

while [ -e "/var/run/mysqld/mysqld.sock" ]; do
Expand Down
1 change: 1 addition & 0 deletions docker/user/setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ bash ${setup}/php.sh
install=$HOME/install
bash ${install}/composer.sh
bash ${install}/nodejs.sh
bash ${install}/chrome.sh
7 changes: 5 additions & 2 deletions post-setup.example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ CREATE TABLE IF NOT EXISTS ${DAMP_EXAMPLE_DB_TABLE}
EOF

cd ${DAMP_WEB_APP}

mysql -V
sudo mysql -e 'show databases;'

if [[ "${DAMP_ADD_CHROME}" == "true" ]]
then
google-chrome --version
fi
32 changes: 28 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
Dockerized development environment based on Debian 10.6 with Apache 2.4, MariaDB 10.3 and PHP 7.4.

With some extras:
* composer - Dependency Manager for PHP
* laravel - Laravel installer
* npm - Node Package Manager
* composer - Dependency manager for PHP.
* laravel - Laravel installer.
* npm - Node package manager.
* google-chrome - Web browser to run Laravel Dusk tests.

## Usage

Expand Down Expand Up @@ -68,12 +69,14 @@ Use [https://project.zdev:44300/](https://project.zdev:44300/) to access web fro
| Name | Example | Comment |
| --- | --- | --- |
| DAMP_ADD_CHROME | false | Adds Google Chrome with driver into container, if set to `true`, to be used by Laravel Dusk. |
| DAMP_ADD_COMPOSER | true | Adds Composer into container if set to `true`. |
| DAMP_ADD_LARAVEL | false | Adds Laravel installer if set to `true` and Composer was added. |
| DAMP_ADD_NODEJS | false | Installs Node.js with npm if set to `true`. |
| DAMP_DB_NAME | damp | Database name. |
| DAMP_DB_USER | damp | Database username. |
| DAMP_DB_PASSWORD | | For all users excluding root. Root has no password with access via socket only. |
| DAMP_DB_PASSWORD | '' | For all users excluding root. Root has no password with access via socket only. |
| | | Quotes are important. Won't work without in some cases, if complex password with special characters is in use. |
| DAMP_LOG | /var/log/damp.log | Log file name inside container. |
| DAMP_PORT_DB | 33060 | Port used to connect to the database from your host system. |
| DAMP_PORT_HTTP | 18000 | |
Expand Down Expand Up @@ -102,10 +105,25 @@ Look at [post-setup.example.sh](./post-setup.example.sh) for an example.

### Logs

> On successful container creation last message will be `Waiting for termination signal to stop container gracefully.`.
Check `./logs/` folder.

$ tail -f logs/zablose-damp.log

Or

$ tail -f logs/all.log

Other logs to look at inside the container:

| File | Comment |
| --- | --- |
| `/var/log/damp-chrome-driver-install.log` | |
| `/var/log/damp-chrome-install.log` | |
| `/var/log/damp-image-build.log` | |
| `/var/log/damp.log` | Same as 'logs/zablose-damp.log' on the host. |

### Scripts

> Get into container first.
Expand All @@ -122,6 +140,12 @@ Check `./logs/` folder.
| docker exec -it docker-damp-damp bash | Get into container, running Bash shell. |
| docker ps -a | List all containers. |

## Hints

| Command | Description |
| --- | --- |
| sudo su - | Switch to root. |

## License

This package is free software distributed under the terms of the MIT license.

0 comments on commit 0b487fc

Please sign in to comment.