Modern Docker multi-OS test layout.

pull/69/head
Jeff Geerling 8 years ago
parent a767f2741c
commit 5fc63d4a6f
  1. 56
      .travis.yml
  2. 1
      tests/inventory
  3. 10
      tests/test.yml

@ -1,39 +1,53 @@
--- ---
sudo: required sudo: required
language: python
python: "2.7"
env: env:
- SITE=test.yml - distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1404
init: /sbin/init
run_opts: ""
- distro: ubuntu1204
init: /sbin/init
run_opts: ""
services:
- docker
before_install: before_install:
- sudo apt-get update -qq # Pull container
- sudo apt-get install -y curl - 'sudo docker pull geerlingguy/docker-${distro}-ansible:latest'
install:
# Install Ansible.
- pip install ansible
# Add ansible.cfg to pick up roles path.
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"
script: script:
# Check the role/playbook's syntax. - container_id=$(mktemp)
- "ansible-playbook -i tests/inventory tests/$SITE --syntax-check" # 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}"'
# Run the role/playbook with ansible-playbook. # Ansible syntax check.
- "ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo" - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
# Run the role/playbook again, checking to make sure it's idempotent. # Test role.
- '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}
- > - >
ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo tail ${idempotence}
| grep -q 'changed=0.*failed=0' | grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0) && (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1) || (echo 'Idempotence test: fail' && exit 1)
# TODO - get the test working. Probably need to add a virtual host. # Check if nginx is running.
# Request a page via Nginx, to make sure Nginx is running and responds. # TODO
# - "curl http://localhost/"
after_success:
# Clean up.
- 'sudo docker stop "$(cat ${container_id})"'
notifications: notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/ webhooks: https://galaxy.ansible.com/api/v1/notifications/

@ -1 +0,0 @@
localhost

@ -1,6 +1,8 @@
--- ---
- hosts: localhost - hosts: all
remote_user: root
vars:
nginx_use_ppa: true
roles: roles:
- role: ansible-role-nginx - role_under_test
nginx_use_ppa: true