diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..042920b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,51 @@ +--- +sudo: required + +env: +- distribution: centos + version: 7 + init: /usr/lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + playbook: test.yml + +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' + +script: +- container_id=$(mktemp) + +# Run container in detached state +- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/ansible-role-nextcloud:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"' + +# Ansible syntax check. +- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/ansible-role-nextcloud/tests/${playbook} --syntax-check' + +# Ansible role check. +- 'sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/ansible-role-nextcloud/tests/${playbook}' + +# Test role idempotence. +- > + sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/ansible-role-nextcloud/tests/${playbook} + | grep -q 'changed=0.*failed=0' + && (echo 'Idempotence test: pass' && exit 0) + || (echo 'Idempotence test: fail' && exit 1) + + +# Verify that we can see the web frontend +- > + sudo docker exec "$(cat ${container_id})" curl -s http://127.0.0.1/index.php 2>/dev/null + | grep -q 'a safe home for all your data' + && (echo 'Nextcloud test: pass' && exit 0) + || (echo 'Nextcloud test: fail' && exit 1) + +# Clean up +- sudo docker stop "$(cat ${container_id})" + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/tests/Dockerfile.centos-7 b/tests/Dockerfile.centos-7 new file mode 100644 index 0000000..88b20a0 --- /dev/null +++ b/tests/Dockerfile.centos-7 @@ -0,0 +1,28 @@ + +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/test.yml b/tests/test.yml index 2680d4e..1c8dba2 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -2,4 +2,4 @@ - hosts: localhost remote_user: root roles: - - nextcloud \ No newline at end of file + - ansible-role-nextcloud