chef-cap-demo
chef-cap-demo copied to clipboard
Chef and Capistrano Guided Exploration
Intoduction
This project provides an example of setting up a server with Chef and deploying a Ruby on Rails application do it with Capistrano
Getting Started
- Install VirtualBox
- Install Vagrant
-
git clone [email protected]:smartlogic/chef-cap-demo.git
-
cd chef-cap-demo
-
bundle install
-
vagrant up
-
vagrant ssh-config --host chef_cap_demo >> ~/.ssh/config
Chef
-
cd chef-repo
-
bundle install
Vagrant boxes already have chef installed, but lets install with our own bootstrap
file to provide a good example for when you aren't using Vagrant.
See chef-repo/.chef/bootstrap/precise32_vagrant.erb
to see how Chef gets installed
-
bundle exec knife bootstrap -p 2222 -x vagrant -d precise32_vagrant chef_cap_demo
-
bundle exec knife cook vagrant@chef_cap_demo
Check to see if you can login as the deploy user
ssh -l deploy chef_cap_demo
Chef cookbook for the app
Create a chef cookbook for your application
-
git checkout app_cookbook
-
bundle exec knife cook vagrant@chef_cap_demo
ssh -l chefcapapp chef_cap_demo
Capistrano
Setup Capistrano
-
cd ..
-
git checkout cap_setup
-
bundle
-
bundle exec cap chef_cap_demo deploy:setup deploy:migrations
Capistrano tasks
Create a capistrano task to run our rake task as part of deploy
-
git checkout cap_data
-
bundle exec cap chef_cap_demo deploy
Proof
- Open http://localhost:8080
- See the messages left by Chef and Capistrano
-
cd chef-repo
-
bundle exec knife cook vagrant@chef_cap_demo
- Refresh http://localhost:8080
- Observe a new message from the Chef run
-
cd ..
-
bundle exec cap chef_cap_demo deploy
- Refresh http://localhost:8080
- Observe a new message from the Capistrano run
- Both Chef and Capistrano created and will maintain a singleton entry that is not duplicated by additional runs
Starting over
-
vagrant destroy
-
vagrant up
- Back to the Chef section