Skip to content

Commit

Permalink
More efficient Docker test layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Sep 16, 2016
1 parent d8e7723 commit 82dd6dc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 66 deletions.
27 changes: 13 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@
sudo: required

env:
- distribution: centos
version: 6
init: /sbin/init
run_opts: ""
- distribution: centos
version: 7
- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: centos6
init: /sbin/init
run_opts: ""

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 -r /etc/ansible/roles/role_under_test/tests/requirements.yml'
Expand All @@ -35,13 +31,16 @@ script:
- '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.yml
tail ${idempotence}
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# 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 @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-repo-epel.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-repo-epel)

Installs the EPEL repository (Extra Packages for Enterprise Linux) for RHEL/CentOS.
Installs the [EPEL repository](https://fedoraproject.org/wiki/EPEL) (Extra Packages for Enterprise Linux) for RHEL/CentOS.

## Requirements

Expand Down Expand Up @@ -33,4 +33,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/).
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.

2 changes: 0 additions & 2 deletions tests/requirements.yml

This file was deleted.

0 comments on commit 82dd6dc

Please sign in to comment.