From ffc022ed357faafd083b65c9583f59f248c0c517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Sch=C3=B6ldstr=C3=B6m?= Date: Tue, 16 Feb 2016 11:25:40 -0500 Subject: [PATCH 1/3] Add docker based tests --- .travis.yml | 95 ++++++++++++++++++++---------- tests/Dockerfile.centos-6 | 15 +++++ tests/Dockerfile.centos-7 | 27 +++++++++ tests/Dockerfile.ubuntu-12.04 | 11 ++++ tests/Dockerfile.ubuntu-14.04 | 11 ++++ tests/test-install-from-source.yml | 12 ---- tests/test-install-package.yml | 9 --- tests/test-package.yml | 13 ++++ tests/test-source.yml | 17 ++++++ 9 files changed, 159 insertions(+), 51 deletions(-) create mode 100644 tests/Dockerfile.centos-6 create mode 100644 tests/Dockerfile.centos-7 create mode 100644 tests/Dockerfile.ubuntu-12.04 create mode 100644 tests/Dockerfile.ubuntu-14.04 delete mode 100644 tests/test-install-from-source.yml delete mode 100644 tests/test-install-package.yml create mode 100644 tests/test-package.yml create mode 100644 tests/test-source.yml diff --git a/.travis.yml b/.travis.yml index 674a29a..1fda9f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,49 +1,84 @@ --- -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.3 + - 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.4 + - distribution: ubuntu + version: 14.04 + init: /sbin/init + run_opts: "" + SITE: package + PHP_VERSION: 5.5 + - distribution: ubuntu + version: 12.04 + init: /sbin/init + run_opts: "" + SITE: package + PHP_VERSION: 5.3 + +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" + # 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' - # 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-${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/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/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..f949d2d --- /dev/null +++ b/tests/test-package.yml @@ -0,0 +1,13 @@ +--- +- hosts: all + + vars: + php_enable_webserver: false + + pre_tasks: + - name: Ensure build dependencies are installed (RedHat). + yum: name=which state=present + when: ansible_os_family == 'RedHat' + + roles: + - 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 From 1cd50cb01cf389296f6dd748c6f24f7d82199f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Sch=C3=B6ldstr=C3=B6m?= Date: Tue, 16 Feb 2016 11:58:39 -0500 Subject: [PATCH 2/3] Add missing rhel dependencies when building from source --- tasks/install-from-source.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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). From 12c6c0622ec22d0c71a2564bbdf2cfc8ef21708d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Sch=C3=B6ldstr=C3=B6m?= Date: Tue, 16 Feb 2016 16:59:49 -0500 Subject: [PATCH 3/3] Run tests for php 5.6 --- .travis.yml | 11 +++++++---- tests/requirements.yml | 2 ++ tests/test-package.yml | 7 +++++++ 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 tests/requirements.yml diff --git a/.travis.yml b/.travis.yml index 1fda9f2..e1a45b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,25 +22,25 @@ env: init: /sbin/init run_opts: "" SITE: package - PHP_VERSION: 5.3 + 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.4 + PHP_VERSION: 5.6 - distribution: ubuntu version: 14.04 init: /sbin/init run_opts: "" SITE: package - PHP_VERSION: 5.5 + PHP_VERSION: 5.6 - distribution: ubuntu version: 12.04 init: /sbin/init run_opts: "" SITE: package - PHP_VERSION: 5.3 + PHP_VERSION: 5.6 services: - docker @@ -57,6 +57,9 @@ script: # 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}"' + # Install dependencies. + - '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' 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-package.yml b/tests/test-package.yml index f949d2d..71369a6 100644 --- a/tests/test-package.yml +++ b/tests/test-package.yml @@ -3,11 +3,18 @@ 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