diff --git a/.travis.yml b/.travis.yml index 674a29a..e1a45b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,49 +1,87 @@ --- -language: python -python: "2.7" +sudo: required env: - - SITE=test-install-package.yml - - SITE=test-install-from-source.yml + # Only test source install on latest supported OSes. + - distribution: centos + version: 7 + init: /usr/lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + SITE: source + PHP_VERSION: 7.0.3 + - distribution: ubuntu + version: 14.04 + init: /sbin/init + run_opts: "" + SITE: source + PHP_VERSION: 7.0.3 + + # Test package install on all supported OSes. + - distribution: centos + version: 6 + init: /sbin/init + run_opts: "" + SITE: package + PHP_VERSION: 5.6 + - distribution: centos + version: 7 + init: /usr/lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + SITE: package + PHP_VERSION: 5.6 + - distribution: ubuntu + version: 14.04 + init: /sbin/init + run_opts: "" + SITE: package + PHP_VERSION: 5.6 + - distribution: ubuntu + version: 12.04 + init: /sbin/init + run_opts: "" + SITE: package + PHP_VERSION: 5.6 + +services: + - docker before_install: - - sudo apt-get update -qq - -install: - # Install Ansible. - # TODO - remove specific version number after the following issue is fixed: - # https://github.com/ansible/ansible-modules-core/issues/2473 - - pip install ansible==1.9.4 - - # Add ansible.cfg to pick up roles path. - - "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg" + # - sudo apt-get update + # Pull container + - 'sudo docker pull ${distribution}:${version}' + # Customize container + - 'sudo docker build --rm=true --file=tests/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests' script: - # Check the role/playbook's syntax. - - "ansible-playbook -i tests/inventory tests/$SITE --syntax-check" + - 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 the role/playbook with ansible-playbook. - - "ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo" + # Install dependencies. + - 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install -r /etc/ansible/roles/role_under_test/tests/requirements.yml' - # Run the role/playbook again, checking to make sure it's idempotent. + # 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' + + # Test role. + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test-${SITE}.yml' + + # Test role idempotence. - > - ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo + sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test-${SITE}.yml | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) - # Run the role/playbook in --check mode. - - "ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo --check" + # Ensure PHP is installed and at the right version. + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm which php' + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm test -x /usr/bin/php' - # Make sure PHP is available. - - > - php -v - | grep -q 'The PHP Group' - && (echo 'PHP is installed' && exit 0) - || (echo 'PHP is not installed' && exit 1) + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm php --version' + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm /usr/bin/php --version | grep -qF "PHP $PHP_VERSION"' - # And for posterity... - - php -v + # Clean up + - 'sudo docker stop "$(cat ${container_id})"' notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/tasks/install-from-source.yml b/tasks/install-from-source.yml index 19915b5..4fbf42e 100644 --- a/tasks/install-from-source.yml +++ b/tasks/install-from-source.yml @@ -2,16 +2,27 @@ - name: Ensure dependencies for building from source are installed (RedHat). yum: "pkg={{ item }} state=installed" with_items: + - autoconf + - automake + - libtool + - bison + - make + - curl-devel - recode-devel - aspell-devel + - libxml2-devel + - pkgconfig - libmcrypt-devel - t1lib-devel - libXpm-devel - libpng-devel - libjpeg-turbo-devel - bzip2-devel - - openssl-libs + - openssl-devel + - freetype-devel - libicu-devel + - mariadb-devel + - gmp-devel when: ansible_os_family == 'RedHat' - name: Update apt cache (Debian). diff --git a/tests/Dockerfile.centos-6 b/tests/Dockerfile.centos-6 new file mode 100644 index 0000000..4a4e7b8 --- /dev/null +++ b/tests/Dockerfile.centos-6 @@ -0,0 +1,15 @@ +FROM centos:6 + +# Install Ansible +RUN yum -y update; yum clean all; +RUN yum -y install epel-release +RUN yum -y install git ansible sudo +RUN yum clean all + +# Disable requiretty +RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers + +# Install Ansible inventory file +RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts + +CMD ["/usr/sbin/init"] diff --git a/tests/Dockerfile.centos-7 b/tests/Dockerfile.centos-7 new file mode 100644 index 0000000..8aa0654 --- /dev/null +++ b/tests/Dockerfile.centos-7 @@ -0,0 +1,27 @@ +FROM centos:7 + +# Install systemd -- See https://hub.docker.com/_/centos/ +RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs +RUN yum -y update; yum clean all; \ +(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ +rm -f /lib/systemd/system/multi-user.target.wants/*; \ +rm -f /etc/systemd/system/*.wants/*; \ +rm -f /lib/systemd/system/local-fs.target.wants/*; \ +rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ +rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ +rm -f /lib/systemd/system/basic.target.wants/*; \ +rm -f /lib/systemd/system/anaconda.target.wants/*; + +# Install Ansible +RUN yum -y install epel-release +RUN yum -y install git ansible sudo +RUN yum clean all + +# Disable requiretty +RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers + +# Install Ansible inventory file +RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts + +VOLUME ["/sys/fs/cgroup"] +CMD ["/usr/sbin/init"] diff --git a/tests/Dockerfile.ubuntu-12.04 b/tests/Dockerfile.ubuntu-12.04 new file mode 100644 index 0000000..d0c130c --- /dev/null +++ b/tests/Dockerfile.ubuntu-12.04 @@ -0,0 +1,11 @@ +FROM ubuntu:12.04 +RUN apt-get update + +# Install Ansible +RUN apt-get install -y software-properties-common python-software-properties git +RUN apt-add-repository -y ppa:ansible/ansible +RUN apt-get update +RUN apt-get install -y ansible + +# Install Ansible inventory file +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts diff --git a/tests/Dockerfile.ubuntu-14.04 b/tests/Dockerfile.ubuntu-14.04 new file mode 100644 index 0000000..ca33287 --- /dev/null +++ b/tests/Dockerfile.ubuntu-14.04 @@ -0,0 +1,11 @@ +FROM ubuntu:14.04 +RUN apt-get update + +# Install Ansible +RUN apt-get install -y software-properties-common git +RUN apt-add-repository -y ppa:ansible/ansible +RUN apt-get update +RUN apt-get install -y ansible + +# Install Ansible inventory file +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts diff --git a/tests/requirements.yml b/tests/requirements.yml new file mode 100644 index 0000000..711227a --- /dev/null +++ b/tests/requirements.yml @@ -0,0 +1,2 @@ +--- +- src: geerlingguy.repo-remi diff --git a/tests/test-install-from-source.yml b/tests/test-install-from-source.yml deleted file mode 100644 index b99a085..0000000 --- a/tests/test-install-from-source.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- hosts: localhost - remote_user: root - - vars: - php_enable_webserver: false - php_install_from_source: true - php_source_clone_dir: /home/travis/php-src - php_source_make_command: "make --jobs=2" - - roles: - - ansible-role-php diff --git a/tests/test-install-package.yml b/tests/test-install-package.yml deleted file mode 100644 index ea845ac..0000000 --- a/tests/test-install-package.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -- hosts: localhost - remote_user: root - - vars: - php_enable_webserver: false - - roles: - - ansible-role-php diff --git a/tests/test-package.yml b/tests/test-package.yml new file mode 100644 index 0000000..71369a6 --- /dev/null +++ b/tests/test-package.yml @@ -0,0 +1,20 @@ +--- +- hosts: all + + vars: + php_enable_webserver: false + php_version: 5.6 + php_enablerepo: "remi,remi-php56" + + 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_under_test diff --git a/tests/test-source.yml b/tests/test-source.yml new file mode 100644 index 0000000..725e190 --- /dev/null +++ b/tests/test-source.yml @@ -0,0 +1,17 @@ +--- +- hosts: all + + vars: + php_enable_webserver: false + php_install_from_source: true + php_source_clone_dir: /root/php-src + php_source_make_command: "make --jobs=2" + php_source_version: "php-7.0.3" + + pre_tasks: + - name: Ensure build dependencies are installed (RedHat). + yum: name=which state=present + when: ansible_os_family == 'RedHat' + + roles: + - role_under_test