minkruben
minkruben

Reputation: 3

How do I run my custom recipes on AWS OpsWorks?

I've created a GitHub repo for my simple custom recipe:

laravel/
  |- recipes/
     |  - deploy.rb
  |- templates/
     |- default
        |  - database.php.erb

I've added the repo to Custom Chef Recipes as https://github.com/minkruben/Laravel-opsworks.git

I've added laravel::deploy to the deploy "cycle".

This is my deploy.rb:

node[:deploy].each do |app_name, deploy|
 if deploy[:application] == "platform"
 script "set_permissions" do
  interpreter "bash"
  user "root"
  cwd "#{deploy[:deploy_to]}/current/app"
  code <<-EOH
  chmod -R 777 storage
  EOH
end


template "#{deploy[:deploy_to]}/current/app/config/database.php" do
  source "database.php.erb"
  mode 0660
  group deploy[:group]

  if platform?("ubuntu")
    owner "www-data"
  elsif platform?("amazon")   
    owner "apache"
  end

  variables(
    :host =>     (deploy[:database][:host] rescue nil),
    :user =>     (deploy[:database][:username] rescue nil),
    :password => (deploy[:database][:password] rescue nil),
    :db =>       (deploy[:database][:database] rescue nil)
  )

 only_if do
   File.directory?("#{deploy[:deploy_to]}/current")
 end
end

end
end

When I log into the instance by SSH with the ubuntu user, app/storage folder permission isn't changed & app/config/database.php is not populated with database details.

Am I missing some critical step somewhere? there are no errors in the log. The recipe is clearly recognized and loaded, but doesn't seem to be executed.

Upvotes: 0

Views: 1589

Answers (1)

Anthony
Anthony

Reputation: 86

With OpsWorks, you have 2 options:

  1. Use one of Amazon's built-in layers, in which case the deployment recipe is provided by Amazon and you can extend Amazon's logic with hooks: http://docs.aws.amazon.com/opsworks/latest/userguide/workingcookbook-extend-hooks.html
  2. Use a custom layer, in which case you are responsible for providing all recipes including deployment: http://docs.aws.amazon.com/opsworks/latest/userguide/create-custom-deploy.html

The logic you have here looks more like a hook than a deployment recipe. Why? Because you are simply modifying an already-deployed app vs. specifying the deployment logic itself. This seems to suggest you are using one of Amazon's built-in layers and that Amazon is providing the deployment recipe for you.

If the above assumption is correct, then you are on path #1. Re-implementing your logic as a hook should do the trick.

Upvotes: 2

Related Questions