Skip to content

Commit

Permalink
Merge pull request #441 from openeyes/release/v1.16
Browse files Browse the repository at this point in the history
Release/v1.16
  • Loading branch information
mikepargeter authored Sep 28, 2016
2 parents 8a665e6 + 5181d5f commit 5a465fd
Show file tree
Hide file tree
Showing 2,948 changed files with 196,218 additions and 146,161 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ tags
/protected/models/elements/ElementExample.php
/protected/modules/sample
/protected/modules/eyedraw
/protected/modules/PASAPI
/protected/runtime/
/protected/tests/report/
/protected/tests/test_results/
Expand Down Expand Up @@ -90,3 +89,5 @@ bin/phploc
bin/phpmd
bin/validate-json
bin/yiic

build/logs
72 changes: 65 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,74 @@ Issues in the core should be logged through the [github issues system](https://g

Dev Setup
---------
To make life easier and also help ensure consistency in environments we use [Vagrant](http://vagrantup.com) + [Ansible](https://www.ansible.com) to build our development environments, the basic requirements for this are to have the following installed and available on the host machine:

To begin development, the simplest approach is:
* [Vagrant](http://vagrantup.com)
* [Virtualbox](http://virtualbox.org) or [VMWare Fusion](http://www.vmware.com/products/fusion.html)

1. clone the repository
1. run vagrant up
1. run devsetup:
Running `vagrant up` the first time will install any missing vagrant plugins:

vagrant ssh
cd /var/www/protected
./yiic devsetup --resetfile=../features/testdata.sql
* [vagrant-auto_network](https://github.com/oscar-stack/vagrant-auto_network)
* [vagrant-hostsupdater](https://github.com/cogitatio/vagrant-hostsupdater)
* [vagrant-cachier](https://github.com/fgrehm/vagrant-cachier)


Once the plugins have been installed you will need to run `vagrant up` again and then go and make a cup of tea whilst a base box is installed and configured. You'll be asked for your root password (Linux / OSX) as part of the set up process as your `/etc/hosts` files is updated with the machine IP and hostname.

Once the build has finished you can access OpenEyes using the link:

[http://openeyes.vm](http://openeyes.vm)

**Note:** [Google Chrome](https://www.google.com/chrome/) is the supported browser for OpenEyes.

## Command Line Options

To allow for multiple environments to be built at the same time the hostname and the servername (used in the VM GUI to identify machines) can be changed via the command line as below when building the VM:

--hostname="openeyes.dev.local"
--servername="My Open Eyes Dev Server"

Full usage:

$ vagrant --hostname="openeyes.dev.local" --servername="My Open Eyes Dev Server" up

If either are omitted the default vales of "openeyes.vm"" and "OpenEyes Dev Server" are used for the hostname and servername respectively.

**Note:** if the options are omitted the default values are used, the command line options have to be before the vagrant command for them to work.

#### XDebug

Is enabled in Apache by default and carries an up to 1 second time penalty on requests, if you don't need or won't be using XDebug at all then commenting changing lines 85 - 86 in `ansible/vars/all.yml` to comment out the package name will ensure it isn't installed.

# php_xdebug:
# - php5-xdebug

By default Xdebug is disabled on the CLI due to [documented](https://getcomposer.org/doc/articles/troubleshooting.md#xdebug-impact-on-composer) performance issues when using composer.

#### Windows 10

You will need to have downloaded VC++ for Vagrant to be able to download base boxes for the build see this issue for more information [https://github.com/mitchellh/vagrant/issues/6754](https://github.com/mitchellh/vagrant/issues/6754)

### Useful Vagrant Commands

* `vagrant up` - Will build the environment if it hasn't already been built
* `vagrant provision` - Will update the machine with any Ansible configuration changes
* `vagrant status` - Will tell you the status of the box
* `vagrant halt` - Halt's the machine (going home for the night)
* `vagrant suspend` - Will suspend the machine
* `vagrant destroy` - Will remove the machine build

And if that's not enough there is the Vagrant [documentation](https://www.vagrantup.com/docs/) and also `vagrant help`

#### Todo:

Additional / Outstanding tasks to be completed:

* Tidy up the PHP build implementation
* Full Windows platform testing
* Configuration optimisation to make it easier to make changes to the build from a single file
* Changes to support AWS provisioning (although this may be better left to a build specific Ansible playbook)
* Tailor the roles better to the OE build rather than coding around more generic [Ansible Galaxy](https://galaxy.ansible.com) based roles.

Printing
--------
Expand Down
140 changes: 87 additions & 53 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,68 +1,102 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

$puppet_install_script = <<SCRIPT
apt-get install --yes lsb-release
DISTRIB_CODENAME=$(lsb_release --codename --short)
DEB="puppetlabs-release-${DISTRIB_CODENAME}.deb"
DEB_PROVIDES="/etc/apt/sources.list.d/puppetlabs.list"
if [ ! -e $DEB_PROVIDES ]
then
# Print statement useful for debugging, but automated runs of this will interpret any output as an error
# print "Could not find $DEB_PROVIDES - fetching and installing $DEB"
wget -q http://apt.puppetlabs.com/$DEB
sudo dpkg -i $DEB
fi
sudo apt-get update
sudo apt-get install --yes puppet=3.8.4-1puppetlabs1
SCRIPT

# quick solution (hopefully) for installing the chromedriver for use with selenium
$chromedriver_install_script = <<SCRIPT
if [ ! -e "/usr/bin/chromedriver" ]
then
sudo apt-get install unzip
wget -N http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip -P /tmp/
unzip -o /tmp/chromedriver_linux64.zip -d /tmp
chmod a+x /tmp/chromedriver
sudo mv /tmp/chromedriver /usr/local/share/chromedriver
sudo ln -fs /usr/local/share/chromedriver /usr/bin/chromedriver
fi
SCRIPT
Vagrant.require_version ">= 1.8.1"

require 'getoptlong'

opts = GetoptLong.new(
[ '--hostname', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--servername', GetoptLong::OPTIONAL_ARGUMENT ]
)

hostname = 'openeyes.vm'
servername = 'OpenEyes Dev Server'

opts.each do |opt, arg|
case opt
when '--hostname'
hostname = arg
when '--servername'
servername = arg
end
end

PLUGINS = %w(vagrant-auto_network vagrant-hostsupdater vagrant-cachier)

PLUGINS.reject! { |plugin| Vagrant.has_plugin? plugin }

unless PLUGINS.empty?
print "The following plugins will be installed: #{PLUGINS.join ", "} continue? [Y/n]: "
unless ['no', 'n'].include? $stdin.gets.strip.downcase
PLUGINS.each do |plugin|
system("vagrant plugin install #{plugin}")
puts
end
end
puts "Please run again"
exit 1
end

# Check to determine whether we're on a windows or linux/os-x host,
# http://stackoverflow.com/questions/26811089/vagrant-how-to-have-host-platform-specific-provisioning-steps
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
end

AutoNetwork.default_pool = "172.16.0.0/24"

Vagrant.configure("2") do |config|

vagrant_version = Vagrant::VERSION.sub(/^v/, '')
if vagrant_version < "1.3.0"
abort(sprintf("You need to have at least v1.3.0 of vagrant installed. You are currently using v%s", vagrant_version));
end
config.vm.box = "ubuntu/trusty64"

config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network "private_network", :auto_network => true

config.vm.network :forwarded_port, host: 8888, guest: 80
config.vm.network :forwarded_port, host: 3333, guest: 3306
config.vm.network "private_network", ip: "192.168.0.100"
config.vm.synced_folder "./", "/var/www/openeyes", id: "vagrant-root",
owner: "vagrant",
group: "www-data",
mount_options: ["dmode=775,fmode=664"]

config.vm.synced_folder "./", "/var/www", id: "vagrant-root"
config.vm.hostname = hostname
config.hostsupdater.remove_on_suspend = true

# for display
config.vm.network :forwarded_port, guest: 5900, host: 5900
# Prefer VMware Fusion before VirtualBox
config.vm.provider "vmware_fusion"
config.vm.provider "virtualbox"

config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", 2024]
# to enable selenium testing
config.vm.provider(:virtualbox) do |v|
v.customize [
"modifyvm", :id,
"--name", servername,
"--memory", 1024,
"--natdnshostresolver1", "on",
"--cpus", 2,
]
v.gui = true
end

config.vm.provision "shell", inline: $puppet_install_script
config.vm.provision "shell", inline: $chromedriver_install_script
# VMWare Fusion
config.vm.provider(:vmware_fusion) do |v, override|
override.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
v.vmx["displayname"] = servername
v.vmx["memsize"] = "1024"
v.vmx["numvcpus"] = "2"
# v.gui = true
end

config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet"
puppet.manifest_file = "default.pp"
puppet.module_path = "puppet/modules"
puppet.facter = { 'mode' => "dev", 'runsubfolder' => false }
# puppet.options = "--verbose --debug"
end
end
if OS.windows?
config.vm.provision :shell, path: "ansible/windows.sh", args: ["default"]
else
config.vm.provision "ansible_local" do |ansible|
ansible.playbook = "ansible/playbook.yml"
# ansible.verbose = "vvv" # Debug
end
end

config.cache.synced_folder_opts = {
mount_options: ["rw", "vers=3", "tcp", "nolock"]
}

end
6 changes: 6 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[ssh_connection]
pipelining=True

[galaxy]
server=https://galaxy-qa.ansible.com
ansible_roles=./roles
9 changes: 9 additions & 0 deletions ansible/install_roles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# install_roles.yml

# From galaxy
- src: geerlingguy.apache
- src: geerlingguy.composer
- src: geerlingguy.mysql
- src: geerlingguy.nodejs
- src: geerlingguy.php
- src: pludoni.wkthmltox
2 changes: 2 additions & 0 deletions ansible/inventories/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[phansible-web]
192.168.33.99
1 change: 1 addition & 0 deletions ansible/playbook.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default
27 changes: 27 additions & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: OpenEyes Development Server

hosts: all

become: true
become_method: sudo

vars_files:
- vars/all.yml

pre_tasks:
- include: tasks/init-debian.yml
when: ansible_os_family == 'Debian'
- include: tasks/init-redhat.yml
when: ansible_os_family == 'RedHat'

roles:
- server
- vagrant_local
- geerlingguy.apache
- geerlingguy.mysql
- geerlingguy.nodejs
- geerlingguy.php
- geerlingguy.composer
- pludoni.wkthmltox
- app
3 changes: 3 additions & 0 deletions ansible/roles/apache/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart apache
service: name=apache2 enabled=yes state=restarted
29 changes: 29 additions & 0 deletions ansible/roles/apache/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Install Apache
become: true
apt: pkg=apache2 state=latest

- name: Install Apache Modules
apache2_module: state=present name={{ item }}
notify: restart apache
with_items:
- rewrite
- vhost_alias
- headers
- expires
- filter

- shell: apache2 -v
register: apache_version

- name: Change default apache2.4 site
become: true
template: src=vhost24.conf.tpl dest=/etc/apache2/sites-available/000-default.conf
notify: restart apache
when: apache_version.stdout.find('Apache/2.4.') != -1

- name: Change default apache2.2 site
become: true
template: src=vhost22.conf.tpl dest=/etc/apache2/sites-available/default
notify: restart apache
when: apache_version.stdout.find('Apache/2.2.') != -1
14 changes: 14 additions & 0 deletions ansible/roles/apache/templates/vhost22.conf.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Default Apache virtualhost template

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot {{ apache.docroot }}
ServerName {{ apache.servername }}

<Directory {{ apache.docroot }}>
AllowOverride All
Options -Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
13 changes: 13 additions & 0 deletions ansible/roles/apache/templates/vhost24.conf.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Default Apache virtualhost template

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot {{ apache.docroot }}
ServerName {{ apache.servername }}

<Directory {{ apache.docroot }}>
AllowOverride All
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
9 changes: 9 additions & 0 deletions ansible/roles/app/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
php_xdebug_remote_enable: "false"
php_xdebug_remote_connect_back: "false"
php_xdebug_remote_host: localhost
php_xdebug_remote_port: "9000"
php_xdebug_remote_log: /tmp/xdebug.log
php_xdebug_remote_autostart: "false"
php_xdebug_idekey: XDEBUG
php_max_nesting_level: 200
5 changes: 5 additions & 0 deletions ansible/roles/app/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: restart apache
service:
name: "{{ apache_service }}"
state: restarted
Loading

0 comments on commit 5a465fd

Please sign in to comment.