Travis CI with vagrant + docker

freebsd
Emilien Mantel 2017-06-06 16:27:11 +02:00
parent 7f7087cdb2
commit 1bce22acbd
14 changed files with 103 additions and 89 deletions

View File

@ -1,17 +1,49 @@
env:
- PLATFORM=debian-jessie-php-5.6
- PLATFORM=debian-jessie-php-7.0
- PLATFORM=debian-jessie-php-7.1
- PLATFORM='docker-debian-jessie-php56' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-jessie-php70' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-jessie-php71' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-jessie-php56' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-jessie-php70' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-jessie-php71' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-jessie-php56' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-jessie-php70' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-jessie-php71' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-jessie-php56' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-debian-jessie-php70' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-debian-jessie-php71' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.3,<2.4'
sudo: required
dist: trusty
language: python
services:
- docker
before_install:
- wget https://releases.hashicorp.com/vagrant/1.9.5/vagrant_1.9.5_x86_64.deb
- sudo dpkg -i vagrant_1.9.5_x86_64.deb
install:
- pip install "$ANSIBLE_VERSION"
script:
- docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run --name $PLATFORM test-$PLATFORM
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM
- >
VAGRANT_DEFAULT_PROVIDER=docker vagrant provision $PLATFORM
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
- VAGRANT_DEFAULT_PROVIDER=docker vagrant status
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@ -3,9 +3,15 @@ Ansible PHP (+FPM) role for Debian
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.php-blue.svg)](https://galaxy.ansible.com/HanXHX/php) [![Build Status](https://travis-ci.org/HanXHX/ansible-php.svg?branch=master)](https://travis-ci.org/HanXHX/ansible-php)
Install PHP (php-fpm optional) on Debian Jessie/Stretch. Manage APCu, Opcache, Xdebug.
Install PHP (php-fpm optional) on Debian. Manage APCu, Opcache, Xdebug.
Managed versions: 5.6, 7.0, 7.1
Managed OS / Versions
---------------------
| OS | PHP 5.6 | PHP 7.0 | PHP 7.1 |
|:-------------: |:-----------------: |:-------------------------: |:-------------------------: |
| Debian Jessie | Yes (from Debian) | Yes (from Dotdeb or Sury) | Yes (from Dotdeb or Sury) |
| Debian Strech | No | Yes (from Debian) | Yes (from Sury) |
Requirements
------------

55
Vagrantfile vendored
View File

@ -5,32 +5,53 @@
Vagrant.configure("2") do |config|
vms = [
[ "jessie-php-5.6", "debian/contrib-jessie64", "192.168.33.88", "5.6" ],
[ "jessie-php-7.0", "debian/contrib-jessie64", "192.168.33.89", "7.0" ],
[ "jessie-php-7.1", "debian/contrib-jessie64", "192.168.33.89", "7.1" ],
[ "stretch-php-5.6", "sharlak/debian_stretch_64", "192.168.33.90", "5.6" ],
[ "stretch-php-7.0", "sharlak/debian_stretch_64", "192.168.33.91", "7.0" ]
vms_debian = [
{ :name => "debian-jessie-php56", :box => "debian/jessie64", :vars => { "php_version": '5.6' }},
{ :name => "debian-jessie-php70", :box => "debian/jessie64", :vars => { "php_version": '7.0' }},
{ :name => "debian-jessie-php71", :box => "debian/jessie64", :vars => { "php_version": '7.1' }},
{ :name => "debian-stretch-php70", :box => "debian/stretch64", :vars => { "php_version": '7.0' }},
{ :name => "debian-stretch-php71", :box => "debian/stretch64", :vars => { "php_version": '7.1' }}
]
config.vm.provider "virtualbox" do |v|
v.cpus = 1
v.memory = 256
end
conts = [
{ :name => "docker-debian-jessie-php56", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "php_version": '5.6' }},
{ :name => "docker-debian-jessie-php70", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "php_version": '7.0' }},
{ :name => "docker-debian-jessie-php71", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "php_version": '7.1' }},
{ :name => "docker-debian-stretch-php70", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.0' }},
{ :name => "docker-debian-stretch-php71", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.1' }}
]
vms.each do |vm|
config.vm.define vm[0] do |m|
m.vm.box = vm[1]
m.vm.network "private_network", ip: vm[2]
config.vm.network "private_network", type: "dhcp"
conts.each do |opts|
config.vm.define opts[:name] do |m|
m.vm.provider "docker" do |d|
d.image = opts[:docker]
d.remains_running = true
d.has_ssh = true
end
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv'
ansible.sudo = true
ansible.extra_vars = {
php_version: vm[3]
}
ansible.extra_vars = opts[:vars]
end
end
end
vms_debian.each do |opts|
config.vm.define opts[:name] do |m|
m.vm.box = opts[:box]
m.vm.provider "virtualbox" do |v|
v.cpus = 1
v.memory = 256
end
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv'
ansible.sudo = true
ansible.extra_vars = opts[:vars]
end
end
end
end

View File

@ -3,7 +3,7 @@
- name: APT | Install php-xdebug
apt: >
pkg="{{ php_apt_prefix }}xdebug"
state=latest
state=present
update_cache=yes
cache_valid_time=3600

View File

@ -1,5 +0,0 @@
FROM williamyeh/ansible:debian8-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh", "5.6"]

View File

@ -1,5 +0,0 @@
FROM williamyeh/ansible:debian8-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh", "7.0"]

View File

@ -1,5 +0,0 @@
FROM williamyeh/ansible:debian8-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh", "7.1"]

View File

@ -1 +0,0 @@
php_version: '5.6'

View File

@ -1 +0,0 @@
php_version: '7.0'

View File

@ -0,0 +1,7 @@
---
- name: APT | Install DotDeb key
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present
- name: APT | Add Dotdeb repository
apt_repository: repo='deb http://packages.dotdeb.org {{ ansible_distribution_release }} all' state=present

View File

@ -0,0 +1,7 @@
---
- name: APT | Install Sury key
apt_key: url='https://packages.sury.org/php/apt.gpg' state=present
- name: APT | Add Sury repository
apt_repository: repo='deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main' state=present

View File

@ -1,7 +0,0 @@
localhost
[php-5.6]
localhost
[php-7.0]
localhost

View File

@ -1,23 +0,0 @@
#!/bin/sh
# Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github
DIR=$( dirname $0 )
PLAYBOOK="$DIR/test.yml"
ANSIBLE_ARG="localhost"
set -ev
ansible --version
# Check syntax
ansible-playbook -i localhost, -c local --syntax-check -vv $PLAYBOOK
# Check role
ansible-playbook -i localhost, -c local -e "php_version=$1" --become -vv $PLAYBOOK
# Check indempotence
ansible-playbook -i localhost, -c local -e "php_version=$1" --become -vv $PLAYBOOK \
| grep -q 'changed=0.*failed=0' \
&& (echo 'Idempotence test: pass' && exit 0) \
|| (echo 'Idempotence test: fail' && exit 1)

View File

@ -13,28 +13,16 @@
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
with_items: ['apt-transport-https', 'curl', 'lsb-release', 'ca-certificates']
- block:
- name: APT | Install DotDeb key
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present
- name: APT | Add Dotdeb repository for Jessie + PHP7
apt_repository: repo='deb http://packages.dotdeb.org jessie all' state=present
- name: INCLUDE | Dotdeb
include: includes/dotdeb.yml
when: >
ansible_distribution_major_version | version_compare(8, 'eq') and
php_version | version_compare('7.0', 'eq')
- block:
- name: APT | Install Sury key
apt_key: url='https://packages.sury.org/php/apt.gpg' state=present
- name: APT | Add Dotdeb repository for Jessie + PHP7
apt_repository: repo='deb https://packages.sury.org/php/ jessie main' state=present
- name: INCLUDE | Sury
include: includes/sury.yml
when: >
ansible_distribution_major_version | version_compare(8, 'eq') and
ansible_distribution_major_version | version_compare(9, 'le') and
php_version | version_compare('7.1', 'eq')
- name: APT | Install nginx
@ -82,7 +70,7 @@
copy: dest=/var/www/phpinfo.php content='<?php phpinfo();'
- name: SHELL | Check vhost
shell: "curl -v -H 'Host: {{ vhost }}' http://127.0.0.1/phpinfo.php 2> /dev/null | grep h1 | grep -o 'PHP Version [57].*<' | sed -r 's/<//g'"
shell: "curl -v -H 'Host: {{ vhost }}' http://127.0.0.1/phpinfo.php 2> /dev/null | grep h1 | grep -o 'PHP Version {{ php_version }}' | sed -r 's/<//g'"
args:
warn: false
changed_when: false