mirror of
https://github.com/geerlingguy/ansible-role-php.git
synced 2024-11-28 12:45:16 +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
|
sudo: required
|
||||||
python: "2.7"
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- SITE=test-install-package.yml
|
# Only test source install on latest supported OSes.
|
||||||
- SITE=test-install-from-source.yml
|
- 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:
|
before_install:
|
||||||
- sudo apt-get update -qq
|
# - sudo apt-get update
|
||||||
|
# Pull container
|
||||||
install:
|
- 'sudo docker pull ${distribution}:${version}'
|
||||||
# Install Ansible.
|
# Customize container
|
||||||
# TODO - remove specific version number after the following issue is fixed:
|
- 'sudo docker build --rm=true --file=tests/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'
|
||||||
# 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"
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
# Check the role/playbook's syntax.
|
- container_id=$(mktemp)
|
||||||
- "ansible-playbook -i tests/inventory tests/$SITE --syntax-check"
|
# 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.
|
# Install dependencies.
|
||||||
- "ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo"
|
- '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'
|
| grep -q 'changed=0.*failed=0'
|
||||||
&& (echo 'Idempotence test: pass' && exit 0)
|
&& (echo 'Idempotence test: pass' && exit 0)
|
||||||
|| (echo 'Idempotence test: fail' && exit 1)
|
|| (echo 'Idempotence test: fail' && exit 1)
|
||||||
|
|
||||||
# Run the role/playbook in --check mode.
|
# Ensure PHP is installed and at the right version.
|
||||||
- "ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo --check"
|
- '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.
|
- '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"'
|
||||||
php -v
|
|
||||||
| grep -q 'The PHP Group'
|
|
||||||
&& (echo 'PHP is installed' && exit 0)
|
|
||||||
|| (echo 'PHP is not installed' && exit 1)
|
|
||||||
|
|
||||||
# And for posterity...
|
# Clean up
|
||||||
- php -v
|
- 'sudo docker stop "$(cat ${container_id})"'
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||||
|
@ -2,16 +2,27 @@
|
|||||||
- name: Ensure dependencies for building from source are installed (RedHat).
|
- name: Ensure dependencies for building from source are installed (RedHat).
|
||||||
yum: "pkg={{ item }} state=installed"
|
yum: "pkg={{ item }} state=installed"
|
||||||
with_items:
|
with_items:
|
||||||
|
- autoconf
|
||||||
|
- automake
|
||||||
|
- libtool
|
||||||
|
- bison
|
||||||
|
- make
|
||||||
|
- curl-devel
|
||||||
- recode-devel
|
- recode-devel
|
||||||
- aspell-devel
|
- aspell-devel
|
||||||
|
- libxml2-devel
|
||||||
|
- pkgconfig
|
||||||
- libmcrypt-devel
|
- libmcrypt-devel
|
||||||
- t1lib-devel
|
- t1lib-devel
|
||||||
- libXpm-devel
|
- libXpm-devel
|
||||||
- libpng-devel
|
- libpng-devel
|
||||||
- libjpeg-turbo-devel
|
- libjpeg-turbo-devel
|
||||||
- bzip2-devel
|
- bzip2-devel
|
||||||
- openssl-libs
|
- openssl-devel
|
||||||
|
- freetype-devel
|
||||||
- libicu-devel
|
- libicu-devel
|
||||||
|
- mariadb-devel
|
||||||
|
- gmp-devel
|
||||||
when: ansible_os_family == 'RedHat'
|
when: ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
- name: Update apt cache (Debian).
|
- 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