Skip to content

Commit

Permalink
More efficient Docker-based test layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Sep 15, 2016
1 parent ed05600 commit d960652
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 110 deletions.
46 changes: 17 additions & 29 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,48 @@
sudo: required

env:
- distribution: centos
version: 6
init: /sbin/init
run_opts: ""
SITE: source
- distribution: centos
version: 7
- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
SITE: source
- distribution: ubuntu
version: 14.04
init: /sbin/init
run_opts: ""
SITE: source
- distribution: ubuntu
version: 12.04
init: /sbin/init
run_opts: ""
SITE: source
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"

services:
- docker

before_install:
# Pull container
- 'sudo docker pull ${distribution}:${version}'
# Customize container
- 'sudo docker build --rm=true --file=tests/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'
# Pull container.
- 'sudo docker pull geerlingguy/docker-${distro}-ansible:latest'

script:
- container_id=$(mktemp)
# Run container in detached state
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"'
# Run container in detached state.
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'

# Install dependencies.
- 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install geerlingguy.php geerlingguy.repo-remi'
- 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install -r /etc/ansible/roles/role_under_test/tests/requirements.yml'

# Ansible syntax check.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test-${SITE}.yml --syntax-check'
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'

# Test role.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test-${SITE}.yml'
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'

# Test role idempotence.
- idempotence=$(mktemp)
- sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | tee -a ${idempotence}
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test-${SITE}.yml
tail ${idempotence}
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Run script to test if Xdebug is available and working.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm php /etc/ansible/roles/role_under_test/tests/xdebug-test.php'

# Clean up
after_success:
# Clean up.
- 'sudo docker stop "$(cat ${container_id})"'

notifications:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Available variables are listed below, along with default values (see `defaults/m

Where Xdebug setup files will be downloaded and built.

php_xdebug_version: 2.4.0
php_xdebug_version: 2.4.1

The version of Xdebug to be installed (see [Updates](https://xdebug.org/updates.php) for a current listing).

Expand Down Expand Up @@ -74,4 +74,4 @@ MIT / BSD

## Author Information

This role was created in 2014 by [Jeff Geerling](http://jeffgeerling.com/), author of [Ansible for DevOps](http://ansiblefordevops.com/).
This role was created in 2014 by [Jeff Geerling](http://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
workspace: /root

php_xdebug_version: 2.4.0
php_xdebug_version: 2.4.1

php_xdebug_coverage_enable: 1
php_xdebug_default_enable: 1
Expand Down
19 changes: 0 additions & 19 deletions tests/Dockerfile.centos-6

This file was deleted.

29 changes: 0 additions & 29 deletions tests/Dockerfile.centos-7

This file was deleted.

11 changes: 0 additions & 11 deletions tests/Dockerfile.ubuntu-12.04

This file was deleted.

11 changes: 0 additions & 11 deletions tests/Dockerfile.ubuntu-14.04

This file was deleted.

1 change: 0 additions & 1 deletion tests/inventory

This file was deleted.

3 changes: 3 additions & 0 deletions tests/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- src: geerlingguy.repo-remi
- src: geerlingguy.php
10 changes: 3 additions & 7 deletions tests/test-source.yml → tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@

vars:
php_enable_webserver: false
php_version: 5.6
php_enablerepo: "remi,remi-php56"
php_enablerepo: "remi,remi-php70"

pre_tasks:
- name: Ensure build dependencies are installed (RedHat).
yum: name=which state=present
when: ansible_os_family == 'RedHat'

- name: Add repository for PHP 5.6.
apt_repository: repo='ppa:ondrej/php5-5.6'
when: ansible_os_family == 'Debian'

roles:
- { role: geerlingguy.repo-remi, when: ansible_os_family == 'RedHat' }
- role: geerlingguy.repo-remi
when: ansible_os_family == 'RedHat'
- geerlingguy.php
- role_under_test

0 comments on commit d960652

Please sign in to comment.