mirror of
https://github.com/geerlingguy/ansible-role-php.git
synced 2024-11-05 09:17:39 +01:00
Merge pull request #80 from oxyc/docker
Issue #64: Add docker based tests
This commit is contained in:
commit
61fbeef983
98
.travis.yml
98
.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/
|
||||
|
@ -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).
|
||||
|
15
tests/Dockerfile.centos-6
Normal file
15
tests/Dockerfile.centos-6
Normal file
@ -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"]
|
27
tests/Dockerfile.centos-7
Normal file
27
tests/Dockerfile.centos-7
Normal file
@ -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"]
|
11
tests/Dockerfile.ubuntu-12.04
Normal file
11
tests/Dockerfile.ubuntu-12.04
Normal file
@ -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
|
11
tests/Dockerfile.ubuntu-14.04
Normal file
11
tests/Dockerfile.ubuntu-14.04
Normal file
@ -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
|
2
tests/requirements.yml
Normal file
2
tests/requirements.yml
Normal file
@ -0,0 +1,2 @@
|
||||
---
|
||||
- src: geerlingguy.repo-remi
|
@ -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
|
@ -1,9 +0,0 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
|
||||
vars:
|
||||
php_enable_webserver: false
|
||||
|
||||
roles:
|
||||
- ansible-role-php
|
20
tests/test-package.yml
Normal file
20
tests/test-package.yml
Normal file
@ -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
|
17
tests/test-source.yml
Normal file
17
tests/test-source.yml
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user