This repository has been archived by the owner on Feb 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #1206: Is it possible this will work? Everything is composer ru…
…n-tests
- Loading branch information
1 parent
39d84cc
commit 1ff0768
Showing
3 changed files
with
183 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,169 @@ | ||
#!/bin/bash | ||
# | ||
# A script to run Drupal VM functional tests. | ||
|
||
# Set volume options. | ||
# Set defaults if they're not set upstream. | ||
CONFIG="${CONFIG:-tests/config.yml}" | ||
MAKEFILE="${MAKEFILE:-example.drupal.make.yml}" | ||
COMPOSERFILE="${COMPOSERFILE:-example.drupal.composer.json}" | ||
HOSTNAME="${HOSTNAME:-drupalvm.dev}" | ||
MACHINE_NAME="${MACHINE_NAME:-drupalvm}" | ||
IP="${IP:-192.168.88.88}" | ||
DRUPALVM_DIR="${DRUPALVM_DIR:-/var/www/drupalvm}" | ||
DRUSH_BIN="${DRUSH_BIN:-drush}" | ||
TEST_INSTALLED_EXTRAS="${TEST_INSTALLED_EXTRAS:-true}" | ||
CONTAINER_ID="${CONTAINER_ID:-dvm-test}" | ||
type="${type:-tests/defaults}" | ||
distro="${distro:-ubuntu1604}" | ||
|
||
## Set up vars for Docker setup. | ||
# CentOS 7 | ||
if [ $distro = 'centos7' ]; then | ||
init="/usr/lib/systemd/systemd" | ||
opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" | ||
# CentOS 6 | ||
elif [ $distro = 'centos6' ]; then | ||
init="/sbin/init" | ||
opts="--privileged" | ||
# Ubuntu 16.04 | ||
elif [ $distro = 'ubuntu1604' ]; then | ||
init="/lib/systemd/systemd" | ||
opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" | ||
# Ubuntu 14.04 | ||
elif [ $distro = 'ubuntu1404' ]; then | ||
init="/sbin/init" | ||
opts="--privileged" | ||
# Ubuntu 12.04 | ||
elif [ $distro = 'ubuntu1204' ]; then | ||
init="/sbin/init" | ||
opts="--privileged" | ||
# Debian 8 | ||
elif [ $distro = 'debian8' ]; then | ||
init="/lib/systemd/systemd" | ||
opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" | ||
# Fedora 24 | ||
elif [ $distro = 'fedora24' ]; then | ||
init="/usr/lib/systemd/systemd" | ||
opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" | ||
fi | ||
|
||
# Set OS-specific options. | ||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
volume_opts='rw,cached' | ||
xargs_command='xargs' | ||
else | ||
volume_opts='rw' | ||
xargs_command='xargs -r' | ||
fi | ||
|
||
# Exit on any individual command failure. | ||
set -e | ||
|
||
# Pretty colors. | ||
red='\033[0;31m' | ||
green='\033[0;32m' | ||
neutral='\033[0m' | ||
|
||
# Remove test container if it already exists. | ||
docker ps -aq --filter name=dvm-test | xargs docker rm -f -v | ||
printf "\n"${green}"Removing any existing test containers..."${neutral}"\n" | ||
docker ps -aq --filter name=$CONTAINER_ID | $xargs_command docker rm -f -v | ||
printf ${green}"...done!"${neutral}"\n" | ||
|
||
# Run the container. | ||
docker run --name=dvm-test -d \ | ||
printf "\n"${green}"Starting Docker container: geerlingguy/docker-$distro-ansible."${neutral}"\n" | ||
docker run --name=$CONTAINER_ID -d \ | ||
--add-host "$HOSTNAME drupalvm":127.0.0.1 \ | ||
-v $PWD:/var/www/drupalvm/:$volume_opts \ | ||
-p 8888:80 \ | ||
--privileged \ | ||
geerlingguy/docker-ubuntu1604-ansible:latest \ | ||
/lib/systemd/systemd | ||
$opts \ | ||
geerlingguy/docker-$distro-ansible:latest \ | ||
$init | ||
|
||
# Create Drupal directory. | ||
docker exec dvm-test mkdir -p /var/www/drupalvm/drupal | ||
# Set up directories. | ||
docker exec $CONTAINER_ID mkdir -p /var/www/drupalvm/drupal | ||
[[ ! -z "$config_dir" ]] && docker exec $CONTAINER_ID mkdir -p $config_dir || true | ||
|
||
# Copy configuration into place. | ||
docker exec $CONTAINER_ID cp $DRUPALVM_DIR/$CONFIG ${config_dir:-$DRUPALVM_DIR}/config.yml | ||
docker exec $CONTAINER_ID cp $DRUPALVM_DIR/$MAKEFILE ${config_dir:-$DRUPALVM_DIR}/drupal.make.yml | ||
docker exec $CONTAINER_ID cp $DRUPALVM_DIR/$COMPOSERFILE ${config_dir:-$DRUPALVM_DIR}/drupal.composer.json | ||
[[ ! -z "$DRUPALVM_ENV" ]] && docker exec $CONTAINER_ID bash -c "cp $DRUPALVM_DIR/tests/$DRUPALVM_ENV.config.yml ${config_dir:-$DRUPALVM_DIR}/$DRUPALVM_ENV.config.yml" || true | ||
|
||
# Override configuration variables with local config. | ||
[[ ! -z "$local_config" ]] && docker exec $CONTAINER_ID bash -c "cp $DRUPALVM_DIR/$local_config ${config_dir:-$DRUPALVM_DIR}/local.config.yml" || true | ||
|
||
# Check playbook syntax. | ||
docker exec --tty dvm-test env TERM=xterm ansible-playbook /var/www/drupalvm/provisioning/playbook.yml --syntax-check | ||
printf "\n"${green}"Checking playbook syntax..."${neutral}"\n" | ||
docker exec --tty $CONTAINER_ID env TERM=xterm ansible-playbook $DRUPALVM_DIR/provisioning/playbook.yml --syntax-check | ||
|
||
# Run the setup playbook. | ||
printf "\n"${green}"Running the setup playbook..."${neutral}"\n" | ||
docker exec --tty $CONTAINER_ID env TERM=xterm ansible-playbook /var/www/drupalvm/tests/test-setup.yml | ||
|
||
# Set things up and run the Ansible playbook. | ||
docker exec --tty dvm-test env TERM=xterm ansible-playbook /var/www/drupalvm/tests/test-setup.yml | ||
docker exec dvm-test env TERM=xterm ANSIBLE_FORCE_COLOR=true COMPOSER_PROCESS_TIMEOUT=1800 ansible-playbook /var/www/drupalvm/provisioning/playbook.yml | ||
# Run the Drupal VM playbook. | ||
printf "\n"${green}"Running the Drupal VM playbook..."${neutral}"\n" | ||
if [ ! -z "${config_dir}" ]; then | ||
# Run with config_dir specified. | ||
docker exec $CONTAINER_ID env TERM=xterm ANSIBLE_FORCE_COLOR=true DRUPALVM_ENV=$DRUPALVM_ENV \ | ||
ansible-playbook $DRUPALVM_DIR/provisioning/playbook.yml \ | ||
--extra-vars="config_dir=$config_dir"; | ||
else | ||
# Run without config_dir specified. | ||
docker exec $CONTAINER_ID env TERM=xterm ANSIBLE_FORCE_COLOR=true DRUPALVM_ENV=$DRUPALVM_ENV \ | ||
ansible-playbook $DRUPALVM_DIR/provisioning/playbook.yml; | ||
fi | ||
|
||
# Check if Drupal was installed successfully. | ||
docker exec dvm-test curl -s --header Host:$HOSTNAME localhost \ | ||
# Drupal. | ||
printf "\n"${green}"Running functional tests..."${neutral}"\n" | ||
docker exec $CONTAINER_ID curl -s --header Host:$HOSTNAME localhost \ | ||
| grep -q '<title>Welcome to Drupal' \ | ||
&& (echo 'Drupal install pass' && exit 0) \ | ||
|| (echo 'Drupal install fail' && exit 1) | ||
|
||
# Adminer. | ||
if [ $TEST_INSTALLED_EXTRAS = true ]; then | ||
docker exec $CONTAINER_ID curl -s --header Host:adminer.$HOSTNAME localhost \ | ||
| grep -q '<title>Login - Adminer' \ | ||
&& (echo 'Adminer install pass' && exit 0) \ | ||
|| (echo 'Adminer install fail' && exit 1) | ||
fi | ||
|
||
# Pimp My Log. | ||
if [ $TEST_INSTALLED_EXTRAS = true ]; then | ||
docker exec $CONTAINER_ID curl -s --header Host:pimpmylog.$HOSTNAME localhost \ | ||
| grep -q '<title>Pimp my Log' \ | ||
&& (echo 'Pimp my Log install pass' && exit 0) \ | ||
|| (echo 'Pimp my Log install fail' && exit 1) | ||
fi | ||
|
||
# MailHog. | ||
if [ $TEST_INSTALLED_EXTRAS = true ]; then | ||
docker exec $CONTAINER_ID curl -s localhost:8025 \ | ||
| grep -q '<title>MailHog' \ | ||
&& (echo 'MailHog install pass' && exit 0) \ | ||
|| (echo 'MailHog install fail' && exit 1) | ||
fi | ||
|
||
# Varnish. | ||
if [ $TEST_INSTALLED_EXTRAS = true ]; then | ||
docker exec $CONTAINER_ID curl -sI --header Host:$HOSTNAME localhost:81 \ | ||
| grep -q 'Via: .* varnish' \ | ||
&& (echo 'Varnish install pass' && exit 0) \ | ||
|| (echo 'Varnish install fail' && exit 1) | ||
fi | ||
|
||
# Dashboard. | ||
docker exec $CONTAINER_ID curl -s --header Host:$IP localhost | ||
| grep -q "<li>$IP $HOSTNAME</li>" | ||
&& (echo 'Dashboard install pass' && exit 0) | ||
|| (echo 'Dashboard install fail' && exit 1) | ||
|
||
# Drush. | ||
docker exec $CONTAINER_ID $DRUSH_BIN @$MACHINE_NAME.$HOSTNAME status | ||
| grep -q 'Drupal bootstrap.*Successful' | ||
&& (echo 'Drush install pass' && exit 0) | ||
|| (echo 'Drush install fail' && exit 1) | ||
|
||
# Remove test container. | ||
docker rm -f dvm-test | ||
printf "\n"${green}"Cleaning up..."${neutral}"\n" | ||
docker rm -f $CONTAINER_ID | ||
printf ${green}"...done!"${neutral}"\n\n" |