-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from geerlingguy/docker-role-tests
Update tests using Docker for cross-platform PHP 7 testing.
- Loading branch information
Showing
7 changed files
with
112 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,52 @@ | ||
--- | ||
sudo: required | ||
language: python | ||
python: "2.7" | ||
|
||
env: | ||
- SITE=test.yml | ||
- SITE=test-global-require.yml | ||
- distribution: centos | ||
version: 7 | ||
init: /usr/lib/systemd/systemd | ||
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" | ||
- distribution: ubuntu | ||
version: 14.04 | ||
init: /sbin/init | ||
run_opts: "" | ||
|
||
services: | ||
- docker | ||
|
||
before_install: | ||
- sudo apt-get update -qq | ||
- sudo apt-get install curl | ||
# - 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' | ||
|
||
install: | ||
# Install Ansible. | ||
- pip install ansible | ||
|
||
# Add ansible.cfg to pick up roles path. | ||
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg" | ||
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}"' | ||
|
||
# Install required dependencies. | ||
- ansible-galaxy install geerlingguy.php | ||
# Install dependencies. | ||
- 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install -r /etc/ansible/roles/role_under_test/tests/requirements.yml' | ||
|
||
script: | ||
# Check the role/playbook's syntax. | ||
- "ansible-playbook -i tests/inventory tests/$SITE --syntax-check" | ||
# Ansible syntax check. | ||
- '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 with ansible-playbook. | ||
- "ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo" | ||
# Test role. | ||
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml' | ||
|
||
# Run the role/playbook again, checking to make sure it's idempotent. | ||
# 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.yml | ||
| grep -q 'changed=0.*failed=0' | ||
&& (echo 'Idempotence test: pass' && exit 0) | ||
|| (echo 'Idempotence test: fail' && exit 1) | ||
# Check if composer is installed and working. | ||
- composer | ||
# Ensure Composer is installed and working. | ||
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm composer' | ||
|
||
# Clean up | ||
- 'sudo docker stop "$(cat ${container_id})"' | ||
|
||
notifications: | ||
webhooks: https://galaxy.ansible.com/api/v1/notifications/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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 | ||
|
||
COPY initctl_faker . | ||
RUN chmod +x initctl_faker && rm -fr /sbin/initctl && ln -s /initctl_faker /sbin/initctl | ||
|
||
# Install Ansible inventory file | ||
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/sh | ||
ALIAS_CMD="$(echo ""$0"" | sed -e 's?/sbin/??')" | ||
|
||
case "$ALIAS_CMD" in | ||
start|stop|restart|reload|status) | ||
exec service $1 $ALIAS_CMD | ||
;; | ||
esac | ||
|
||
case "$1" in | ||
list ) | ||
exec service --status-all | ||
;; | ||
reload-configuration ) | ||
exec service $2 restart | ||
;; | ||
start|stop|restart|reload|status) | ||
exec service $2 $1 | ||
;; | ||
\?) | ||
exit 0 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
- src: geerlingguy.repo-remi | ||
- src: geerlingguy.php |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters