0

我为我的简单自定义配方创建了一个 GitHub 存储库:

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

我已将存储库添加到自定义厨师食谱中,为https://github.com/minkruben/Laravel-opsworks.git

我已添加laravel::deploy到部署“周期”中。

这是我的 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

当我使用 ubuntu 用户通过 SSH 登录到实例时,app/storage 文件夹权限不会更改app/config/database.php并且不会填充数据库详细信息。

我在某处错过了一些关键步骤吗?日志中没有错误。配方被清楚地识别和加载,但似乎没有被执行。

4

1 回答 1

2

使用 OpsWorks,您有 2 个选择:

  1. 使用 Amazon 的内置层之一,在这种情况下,部署配方由 Amazon 提供,您可以使用钩子扩展 Amazon 的逻辑:http: //docs.aws.amazon.com/opsworks/latest/userguide/workingcookbook-extend-钩子.html
  2. 使用自定义层,在这种情况下,您负责提供包括部署在内的所有配方:http: //docs.aws.amazon.com/opsworks/latest/userguide/create-custom-deploy.html

您在此处的逻辑看起来更像是一个钩子,而不是部署方法。为什么?因为您只是在修改已经部署的应用程序而不是指定部署逻辑本身。这似乎表明您正在使用 Amazon 的内置层之一,并且 Amazon 正在为您提供部署方法。

如果上述假设是正确的,那么您就在路径 #1 上。将您的逻辑重新实现为钩子应该可以解决问题。

于 2014-06-18T18:30:12.090 回答