Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting started with chef, and running composer install on deploy

We're looking to deploy a few Laravel4 based PHP apps on amazon with OpsWorks, this requires a few things:

  • Grab code from git
  • Download composer.phar from getcomposer.com
  • Run php composer.phar install
  • Change permissions on a few specific folders

I'm completely fresh with it comes to chef, so initially looking for a place to get to grips with the basics of chef, and then how to achieve the tasks above, would appreciate any pointers.

like image 837
duellsy Avatar asked Apr 18 '13 00:04

duellsy


2 Answers

I'm no Chef guru (I usually use Puppet) but try the following:

Grab code from git

You may want to execute a wget command (see examples below).

If you want something more sophisticated see http://docs.opscode.com/resource_deploy.html

deploy_revision "/path/to/application" do
  repo 'ssh://name-of-git-repo/repos/repo.git'
  migrate false
  purge_before_symlink %w{one two folder/three}
  create_dirs_before_symlink []
  symlinks(
    "one"   => "one",
    "two"   => "two",
    "three" => "folder/three"
  )
  before_restart do
    # some Ruby code
  end
  notifies :restart, "service[foo]"
  notifies :restart, "service[bar]"
end

Download composer.phar from getcomposer.com

I would execute a wget.

I lifted some code from here: http://cookingclouds.com/2012/06/23/chef-simple-cookbook-example/

It's basically just doing a wget in a specific folder, extracting the contents of the tar & updating some permissions on the new files. It only does this if the folder doesn't already exist.

# Run a bash shell -  download and extract composer
bash "install_composer" do
     user "root"
     cwd "/folder/to/extact/to"
     code <<-EOH
       wget http://getcomposer.com/composer.tar.gz
       tar -xzf composer.tar.gz
       chown -R user:group /folder/to/extact/to
     EOH
     not_if "test -d /folder/to/extact/to"
end

Run php composer.phar install

http://docs.opscode.com/resource_execute.html

execute "composer install" do
  command "php composer.phar install && touch /var/log/.php_composer_installed"
  creates "/var/log/.php_composer_installed"
  action :run
end

This will only run it once, otherwise you can remove the "creates" and it will run it each time.

Change permissions on a few specific folders

http://docs.opscode.com/resource.html

directory "/tmp/folder" do
  owner "root"
  group "root"
  mode 0755
  action :create
end

If the directory already exists, nothing will happen. If the directory was changed in any way, the resource is marked as updated.

Finally

I find the search handy, browsing stuff on the Chef site seems to be hopeless (too much stuff to dig through). http://docs.opscode.com/search.html

like image 157
Drew Khoury Avatar answered Nov 15 '22 10:11

Drew Khoury


I would go pretty much with Drew Khoury's answer, with one change. To download compose.phar, you can use the remote_file resource instead of doing a wget in a bash script.

like image 22
aagdbl Avatar answered Nov 15 '22 11:11

aagdbl