Skip to content

Commit

Permalink
Merge pull request #4 from cakephp/add-vagrant
Browse files Browse the repository at this point in the history
Add vagrantfile and some sample data
  • Loading branch information
lorenzo authored Dec 3, 2016
2 parents 335c244 + 90374fa commit faf9e00
Show file tree
Hide file tree
Showing 28 changed files with 743 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,28 @@ the [bookmarker tutorial](http://book.cakephp.org/3.0/en/quickstart.html).
5. Configure your database credentials in ``app.php``. Make sure to use the same database name as in step 4.
6. Start the server `bin/cake server -p 8765`.
7. Go to http://localhost:8765 in your browser.

# Using Vagrant

If you don't have a local development environment setup, you can use Vagrant to
create one. After installing Vagrant run:

```
vagrant up
```

This will download a new vagrant image, and run ansible to provision the
bookmarking application. Once ansible is complete, you should have a working
application available at http://192.168.33.99 .

### Logging In

You can login to the application at http://192.168.33.99/users/login. The
username is `[email protected]` and the password is `password`.

## Before you run Ansible a second time

After the initial provisioning run if you want to re-run ansible, make sure to
remove `mysql.dump` in `ansible/vars/all.yml` or ansible will reset your
database state to whats in the SQL dump file.

56 changes: 56 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
##################################################
# 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 = "bookmarker"
v.customize [
"modifyvm", :id,
"--name", "bookmarker",
"--memory", 512,
"--natdnshostresolver1", "on",
"--cpus", 1,
]
end

config.vm.box = "ubuntu/trusty64"

config.vm.network :private_network, ip: "192.168.33.99"
config.ssh.forward_agent = true

# If ansible is in your path it will provision from your HOST machine
# If ansible is not found in the path it will be instaled in the VM and provisioned from there
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
1 change: 1 addition & 0 deletions ansible/files/authorized_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
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
13 changes: 13 additions & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- hosts: all
sudo: true
vars_files:
- vars/all.yml
roles:
- server
- vagrant_local
- apache
- mysql
- php
- composer
- 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
sudo: yes
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
sudo: yes
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
sudo: yes
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>
12 changes: 12 additions & 0 deletions ansible/roles/app/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Create web app config file.
template:
args:
src: app.php.tpl
dest: "/vagrant/config/app.php"

- name: Install composer dependencies
command: "composer install --no-interactive"
args:
creates: "/vagrant/vendor/autoload.php"
chdir: "/vagrant"
Loading

0 comments on commit faf9e00

Please sign in to comment.