From 991a10f5cdb9d9616f0426fc90e9132852afbc54 Mon Sep 17 00:00:00 2001 From: Eddie Abou-Jaoude Date: Sat, 15 Aug 2015 12:14:17 +0100 Subject: [PATCH 1/9] Update ignore to ignore vagrant files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 57f6f89..4a69314 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ /vendor/ _build/ *.mo +.vagrant/ +phpunit.xml From 5df676e75c042e389d2ed16a0cc20eefb4b1d42d Mon Sep 17 00:00:00 2001 From: Eddie Abou-Jaoude Date: Sat, 15 Aug 2015 12:20:19 +0100 Subject: [PATCH 2/9] composer phar added to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4a69314..c6fa3e1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ _build/ *.mo .vagrant/ phpunit.xml +composer.phar From 8f70b116522c7d2a637f21e1dd6e9e16857687c5 Mon Sep 17 00:00:00 2001 From: Eddie Abou-Jaoude Date: Sat, 15 Aug 2015 12:21:01 +0100 Subject: [PATCH 3/9] vagrant & ansible scripts added inc docs in README --- README.md | 32 +++++++++++ Vagrantfile | 59 +++++++++++++++++++++ ansible/inventories/dev | 2 + ansible/playbook.yml | 11 ++++ ansible/roles/app/tasks/main.yml | 5 ++ ansible/roles/php/handlers/main.yml | 3 ++ ansible/roles/php/tasks/configure.yml | 9 ++++ ansible/roles/php/tasks/main.yml | 25 +++++++++ ansible/roles/php/tasks/pecl.yml | 26 +++++++++ ansible/roles/php/tasks/php-cli.yml | 10 ++++ ansible/roles/php/templates/extension.tpl | 2 + ansible/roles/server/tasks/main.yml | 31 +++++++++++ ansible/roles/server/templates/timezone.tpl | 1 + ansible/roles/vagrant_local/tasks/main.yml | 11 ++++ ansible/roles/xdebug/defaults/main.yml | 7 +++ ansible/roles/xdebug/tasks/main.yml | 4 ++ ansible/vars/all.yml | 15 ++++++ ansible/windows.sh | 31 +++++++++++ 18 files changed, 284 insertions(+) create mode 100755 Vagrantfile create mode 100755 ansible/inventories/dev create mode 100755 ansible/playbook.yml create mode 100755 ansible/roles/app/tasks/main.yml create mode 100755 ansible/roles/php/handlers/main.yml create mode 100755 ansible/roles/php/tasks/configure.yml create mode 100755 ansible/roles/php/tasks/main.yml create mode 100755 ansible/roles/php/tasks/pecl.yml create mode 100755 ansible/roles/php/tasks/php-cli.yml create mode 100755 ansible/roles/php/templates/extension.tpl create mode 100755 ansible/roles/server/tasks/main.yml create mode 100755 ansible/roles/server/templates/timezone.tpl create mode 100755 ansible/roles/vagrant_local/tasks/main.yml create mode 100755 ansible/roles/xdebug/defaults/main.yml create mode 100755 ansible/roles/xdebug/tasks/main.yml create mode 100755 ansible/vars/all.yml create mode 100755 ansible/windows.sh diff --git a/README.md b/README.md index 0d9e054..f941f1b 100755 --- a/README.md +++ b/README.md @@ -13,12 +13,44 @@ I think the problem with patterns is that often people do know them but don't kn You should look at and run the tests to see what happens in the example. To do this, you should install dependencies with `Composer` first: +### [optional] Using a Virtual Machine (VM) + +If you wish to use a ready made VM environment, you can easily create one with Vagrant and Ansible. + +```bash +$ vagrant up +``` + +### Install dependencies + ```bash $ composer install ``` Read more about how to install and use `Composer` on your local machine [here](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx). +### Running test suite + +```bash +$ ./vendor/bin/phpunit +``` + +Output example + +```bash +vagrant@design-patterns:/vagrant$ ./vendor/bin/phpunit +PHPUnit 4.6.10 by Sebastian Bergmann and contributors. + +Configuration read from /vagrant/phpunit.xml + +................................................................. 65 / 71 ( 91%) +...... + +Time: 554 ms, Memory: 5.75Mb + +OK (71 tests, 128 assertions) +``` + ## Patterns The patterns can be structured in roughly three different categories. Please click on the [:notebook:](http://en.wikipedia.org/wiki/Software_design_pattern) for a full explanation of the pattern on Wikipedia. diff --git a/Vagrantfile b/Vagrantfile new file mode 100755 index 0000000..30f924c --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,59 @@ +################################################## +# Generated by phansible.com +################################################## + +#If your Vagrant version is lower than 1.5, you can still use this provisioning +#by commenting or removing the line below and providing the config.vm.box_url parameter, +#if it's not already defined in this Vagrantfile. Keep in mind that you won't be able +#to use the Vagrant Cloud and other newer Vagrant features. +Vagrant.require_version ">= 1.5" + +# Check to determine whether we're on a windows or linux/os-x host, +# later on we use this to launch ansible in the supported way +# source: https://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby +def which(cmd) + exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] + ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| + exts.each { |ext| + exe = File.join(path, "#{cmd}#{ext}") + return exe if File.executable? exe + } + end + return nil +end +Vagrant.configure("2") do |config| + + config.vm.provider :virtualbox do |v| + v.name = "design-patterns" + v.customize [ + "modifyvm", :id, + "--name", "design-patterns", + "--memory", 512, + "--natdnshostresolver1", "on", + "--cpus", 1, + ] + end + + config.vm.box = "ubuntu/trusty64" + + config.vm.network :private_network, ip: "192.168.11.2" + config.ssh.forward_agent = true + + ############################################################# + # Ansible provisioning (you need to have ansible installed) + ############################################################# + + + if which('ansible-playbook') + config.vm.provision "ansible" do |ansible| + ansible.playbook = "ansible/playbook.yml" + ansible.inventory_path = "ansible/inventories/dev" + ansible.limit = 'all' + end + else + config.vm.provision :shell, path: "ansible/windows.sh", args: ["default"] + end + + + config.vm.synced_folder "./", "/vagrant", type: "nfs" +end diff --git a/ansible/inventories/dev b/ansible/inventories/dev new file mode 100755 index 0000000..86d8f3b --- /dev/null +++ b/ansible/inventories/dev @@ -0,0 +1,2 @@ +[phansible-web] +192.168.11.2 diff --git a/ansible/playbook.yml b/ansible/playbook.yml new file mode 100755 index 0000000..33e3fda --- /dev/null +++ b/ansible/playbook.yml @@ -0,0 +1,11 @@ +--- +- hosts: all + sudo: true + vars_files: + - vars/all.yml + roles: + - server + - vagrant_local + - php + - xdebug + - app diff --git a/ansible/roles/app/tasks/main.yml b/ansible/roles/app/tasks/main.yml new file mode 100755 index 0000000..c330e48 --- /dev/null +++ b/ansible/roles/app/tasks/main.yml @@ -0,0 +1,5 @@ +--- +# application tasks to be customized and to run after the main provision +- name: update file db + sudo: yes + shell: updatedb diff --git a/ansible/roles/php/handlers/main.yml b/ansible/roles/php/handlers/main.yml new file mode 100755 index 0000000..915cc8a --- /dev/null +++ b/ansible/roles/php/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart php5-fpm + service: name=php5-fpm enabled=yes state=restarted diff --git a/ansible/roles/php/tasks/configure.yml b/ansible/roles/php/tasks/configure.yml new file mode 100755 index 0000000..c334a60 --- /dev/null +++ b/ansible/roles/php/tasks/configure.yml @@ -0,0 +1,9 @@ +--- +#- stat: path=/etc/php5/fpm/php.ini +# register: phpfpm + +- stat: path=/etc/php5/cli/php.ini + register: phpcli + +- include: php-cli.yml + when: phpcli.stat.exists diff --git a/ansible/roles/php/tasks/main.yml b/ansible/roles/php/tasks/main.yml new file mode 100755 index 0000000..b554426 --- /dev/null +++ b/ansible/roles/php/tasks/main.yml @@ -0,0 +1,25 @@ +--- +- name: Add ppa Repository + sudo: yes + apt_repository: repo=ppa:ondrej/{{ php.ppa }} + +- name: Update apt + sudo: yes + apt: update_cache=yes + +- name: Install php5 + sudo: yes + apt: pkg=php5 state=latest + +- name: Install PHP Packages + sudo: yes + apt: pkg={{ item }} state=latest + with_items: php.packages + when: php.packages is defined + +- name: Install pear + sudo: yes + apt: pkg=php-pear state=latest + +- include: configure.yml +- include: pecl.yml diff --git a/ansible/roles/php/tasks/pecl.yml b/ansible/roles/php/tasks/pecl.yml new file mode 100755 index 0000000..399219f --- /dev/null +++ b/ansible/roles/php/tasks/pecl.yml @@ -0,0 +1,26 @@ +- name: Install + apt: pkg="php5-dev" state=present + when: php.pecl_packages is defined + +- name: Install Package + shell: echo "\n\n\n\n\n\n\n\n\n" | pecl install {{ item }} + register: pecl_result + changed_when: "'already installed' not in pecl_result.stdout" + failed_when: "pecl_result.stderr or ('ERROR' in pecl_result.stdout)" + with_items: php.pecl_packages + when: php.pecl_packages is defined + +- name: Create extension .ini file + template: > + src="extension.tpl" + dest="/etc/php5/mods-available/{{ item }}.ini" + owner="root" + group="root" + mode=0644 + with_items: php.pecl_packages + when: php.pecl_packages is defined + +- name: Enable extension + shell: php5enmod {{ item }} + with_items: php.pecl_packages + when: php.pecl_packages is defined diff --git a/ansible/roles/php/tasks/php-cli.yml b/ansible/roles/php/tasks/php-cli.yml new file mode 100755 index 0000000..e1cfffa --- /dev/null +++ b/ansible/roles/php/tasks/php-cli.yml @@ -0,0 +1,10 @@ +--- +- name: ensure timezone is set in cli php.ini + lineinfile: dest=/etc/php5/cli/php.ini + regexp='date.timezone =' + line='date.timezone = {{ server.timezone }}' + +- name: enabling opcache cli + lineinfile: dest=/etc/php5/cli/php.ini + regexp=';opcache.enable_cli=0' + line='opcache.enable_cli=1' diff --git a/ansible/roles/php/templates/extension.tpl b/ansible/roles/php/templates/extension.tpl new file mode 100755 index 0000000..1b13534 --- /dev/null +++ b/ansible/roles/php/templates/extension.tpl @@ -0,0 +1,2 @@ +; Configuration for php PECL {{ item }} extension +extension={{ item }}.so diff --git a/ansible/roles/server/tasks/main.yml b/ansible/roles/server/tasks/main.yml new file mode 100755 index 0000000..f1ffc08 --- /dev/null +++ b/ansible/roles/server/tasks/main.yml @@ -0,0 +1,31 @@ +--- +- name: Update apt + sudo: yes + apt: update_cache=yes + +- name: Install System Packages + sudo: yes + apt: pkg={{ item }} state=latest + with_items: + - curl + - wget + - python-software-properties + +- name: Install Extra Packages + sudo: yes + apt: pkg={{ item }} state=latest + with_items: server.packages + when: server.packages is defined + +- name: Configure the timezone + sudo: yes + template: src=timezone.tpl dest=/etc/timezone + +- name: More Configure the timezone + sudo: yes + file: src=/usr/share/zoneinfo/{{server.timezone}} dest=/etc/localtime state=link force=yes backup=yes + +- name: Set default system language pack + shell: locale-gen {{server.locale}} + sudo: yes + diff --git a/ansible/roles/server/templates/timezone.tpl b/ansible/roles/server/templates/timezone.tpl new file mode 100755 index 0000000..cca2365 --- /dev/null +++ b/ansible/roles/server/templates/timezone.tpl @@ -0,0 +1 @@ +{{server.timezone}} diff --git a/ansible/roles/vagrant_local/tasks/main.yml b/ansible/roles/vagrant_local/tasks/main.yml new file mode 100755 index 0000000..cd53609 --- /dev/null +++ b/ansible/roles/vagrant_local/tasks/main.yml @@ -0,0 +1,11 @@ +--- +- name: Set the hostname in /etc/hostname + shell: echo {{ vagrant_local.vm.hostname }} > /etc/hostname + when: vagrant_local.vm.hostname is defined + +- name: Set the hostname + shell: hostname {{ vagrant_local.vm.hostname }} + when: vagrant_local.vm.hostname is defined + +- name: Update /etc/hosts + lineinfile: dest=/etc/hosts regexp='^127\.0\.0\.1' line='127.0.0.1 localhost {{ vagrant_local.vm.hostname }}' owner=root group=root mode=0644 diff --git a/ansible/roles/xdebug/defaults/main.yml b/ansible/roles/xdebug/defaults/main.yml new file mode 100755 index 0000000..f2d917e --- /dev/null +++ b/ansible/roles/xdebug/defaults/main.yml @@ -0,0 +1,7 @@ +--- +xdebug: + settings: + - xdebug.remote_enable=1 + - xdebug.idekey=PHPSTORM + - xdebug.remote_connect_back=1 + - xdebug.remote_port=9000 diff --git a/ansible/roles/xdebug/tasks/main.yml b/ansible/roles/xdebug/tasks/main.yml new file mode 100755 index 0000000..e38815d --- /dev/null +++ b/ansible/roles/xdebug/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- name: Install xDebug + sudo: yes + apt: pkg=php5-xdebug state=latest diff --git a/ansible/vars/all.yml b/ansible/vars/all.yml new file mode 100755 index 0000000..b5559e6 --- /dev/null +++ b/ansible/vars/all.yml @@ -0,0 +1,15 @@ +--- +server: + install: '1' + packages: [vim, htop, iotop, bwm-ng] + timezone: UTC + locale: en_US.UTF-8 +vagrant_local: + install: '1' + vm: { base_box: trusty64, hostname: design-patterns, ip: 192.168.11.2, sharedfolder: ./, enableWindows: '1', useVagrantCloud: '1', syncType: nfs } +php: + install: '1' + ppa: php5-5.6 + packages: [php5-cli, php5-intl, php5-mcrypt, php5-mysql, php5-curl, php5-json] +xdebug: + install: '1' diff --git a/ansible/windows.sh b/ansible/windows.sh new file mode 100755 index 0000000..eab5d9a --- /dev/null +++ b/ansible/windows.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# Update Repositories +sudo apt-get update + +# Determine Ubuntu Version +. /etc/lsb-release + +# Decide on package to install for `add-apt-repository` command +# +# USE_COMMON=1 when using a distribution over 12.04 +# USE_COMMON=0 when using a distribution at 12.04 or older +USE_COMMON=$(echo "$DISTRIB_RELEASE > 12.04" | bc) + +if [ "$USE_COMMON" -eq "1" ]; +then + sudo apt-get install -y software-properties-common +else + sudo apt-get install -y python-software-properties +fi + +# Add Ansible Repository & Install Ansible +sudo add-apt-repository -y ppa:ansible/ansible +sudo apt-get update +sudo apt-get install -y ansible + +# Setup Ansible for Local Use and Run +cp /vagrant/ansible/inventories/dev /etc/ansible/hosts -f +chmod 666 /etc/ansible/hosts +cat /vagrant/ansible/files/authorized_keys >> /home/vagrant/.ssh/authorized_keys +sudo ansible-playbook /vagrant/ansible/playbook.yml -e hostname=$1 --connection=local \ No newline at end of file From 60a93e228365abe6f5f65232f751b0a22b8223e6 Mon Sep 17 00:00:00 2001 From: Eddie Abou-Jaoude Date: Sat, 15 Aug 2015 12:22:19 +0100 Subject: [PATCH 4/9] Link to vagrant docs added to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f941f1b..5158b3f 100755 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ If you wish to use a ready made VM environment, you can easily create one with V $ vagrant up ``` +More information on [vagrant](https://www.vagrantup.com) + ### Install dependencies ```bash From f158b2c70173e23491e61949619eec8ba0fc9597 Mon Sep 17 00:00:00 2001 From: Eddie Abou-Jaoude Date: Sat, 15 Aug 2015 12:35:14 +0100 Subject: [PATCH 5/9] project path in VM added to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5158b3f..a38ff89 100755 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ If you wish to use a ready made VM environment, you can easily create one with V $ vagrant up ``` +Then `vagrant ssh` and `cd /vagrant` + More information on [vagrant](https://www.vagrantup.com) ### Install dependencies From faaf99a7ea9bff0c90abbd28e4609b916b21b0b7 Mon Sep 17 00:00:00 2001 From: Eddie Abou-Jaoude Date: Tue, 18 Aug 2015 12:40:49 +0100 Subject: [PATCH 6/9] Removed phpunit output from README --- README.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/README.md b/README.md index a38ff89..65d71d7 100755 --- a/README.md +++ b/README.md @@ -39,22 +39,6 @@ Read more about how to install and use `Composer` on your local machine [here](h $ ./vendor/bin/phpunit ``` -Output example - -```bash -vagrant@design-patterns:/vagrant$ ./vendor/bin/phpunit -PHPUnit 4.6.10 by Sebastian Bergmann and contributors. - -Configuration read from /vagrant/phpunit.xml - -................................................................. 65 / 71 ( 91%) -...... - -Time: 554 ms, Memory: 5.75Mb - -OK (71 tests, 128 assertions) -``` - ## Patterns The patterns can be structured in roughly three different categories. Please click on the [:notebook:](http://en.wikipedia.org/wiki/Software_design_pattern) for a full explanation of the pattern on Wikipedia. From 7a1f4eb456933f9bb0d3148038bc4b36ed196058 Mon Sep 17 00:00:00 2001 From: Eddie Abou-Jaoude Date: Tue, 18 Aug 2015 12:41:18 +0100 Subject: [PATCH 7/9] Removed php5-fpm ansible handler --- ansible/roles/php/handlers/main.yml | 3 --- 1 file changed, 3 deletions(-) delete mode 100755 ansible/roles/php/handlers/main.yml diff --git a/ansible/roles/php/handlers/main.yml b/ansible/roles/php/handlers/main.yml deleted file mode 100755 index 915cc8a..0000000 --- a/ansible/roles/php/handlers/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -- name: restart php5-fpm - service: name=php5-fpm enabled=yes state=restarted From 7a90725128f76183a84a7ade5d6861b4bcb1afe5 Mon Sep 17 00:00:00 2001 From: Eddie Abou-Jaoude Date: Tue, 18 Aug 2015 12:41:42 +0100 Subject: [PATCH 8/9] Removed commented out code for php5-fpm --- ansible/roles/php/tasks/configure.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/ansible/roles/php/tasks/configure.yml b/ansible/roles/php/tasks/configure.yml index c334a60..1b093e7 100755 --- a/ansible/roles/php/tasks/configure.yml +++ b/ansible/roles/php/tasks/configure.yml @@ -1,7 +1,4 @@ --- -#- stat: path=/etc/php5/fpm/php.ini -# register: phpfpm - - stat: path=/etc/php5/cli/php.ini register: phpcli From 87cb4e9ca6bbf18e0423f63ad6c350df96cf589c Mon Sep 17 00:00:00 2001 From: Eddie Abou-Jaoude Date: Tue, 18 Aug 2015 12:42:41 +0100 Subject: [PATCH 9/9] Removed Pear & Pecl from Ansible scripts --- ansible/roles/php/tasks/main.yml | 5 ----- ansible/roles/php/tasks/pecl.yml | 26 ----------------------- ansible/roles/php/templates/extension.tpl | 2 -- 3 files changed, 33 deletions(-) delete mode 100755 ansible/roles/php/tasks/pecl.yml delete mode 100755 ansible/roles/php/templates/extension.tpl diff --git a/ansible/roles/php/tasks/main.yml b/ansible/roles/php/tasks/main.yml index b554426..38f2f78 100755 --- a/ansible/roles/php/tasks/main.yml +++ b/ansible/roles/php/tasks/main.yml @@ -17,9 +17,4 @@ with_items: php.packages when: php.packages is defined -- name: Install pear - sudo: yes - apt: pkg=php-pear state=latest - - include: configure.yml -- include: pecl.yml diff --git a/ansible/roles/php/tasks/pecl.yml b/ansible/roles/php/tasks/pecl.yml deleted file mode 100755 index 399219f..0000000 --- a/ansible/roles/php/tasks/pecl.yml +++ /dev/null @@ -1,26 +0,0 @@ -- name: Install - apt: pkg="php5-dev" state=present - when: php.pecl_packages is defined - -- name: Install Package - shell: echo "\n\n\n\n\n\n\n\n\n" | pecl install {{ item }} - register: pecl_result - changed_when: "'already installed' not in pecl_result.stdout" - failed_when: "pecl_result.stderr or ('ERROR' in pecl_result.stdout)" - with_items: php.pecl_packages - when: php.pecl_packages is defined - -- name: Create extension .ini file - template: > - src="extension.tpl" - dest="/etc/php5/mods-available/{{ item }}.ini" - owner="root" - group="root" - mode=0644 - with_items: php.pecl_packages - when: php.pecl_packages is defined - -- name: Enable extension - shell: php5enmod {{ item }} - with_items: php.pecl_packages - when: php.pecl_packages is defined diff --git a/ansible/roles/php/templates/extension.tpl b/ansible/roles/php/templates/extension.tpl deleted file mode 100755 index 1b13534..0000000 --- a/ansible/roles/php/templates/extension.tpl +++ /dev/null @@ -1,2 +0,0 @@ -; Configuration for php PECL {{ item }} extension -extension={{ item }}.so