dotenv和linked_files与capistrano 3

时间:2014-07-24 18:07:13

标签: ruby-on-rails ruby capistrano

真的很难让这个工作。我刚刚添加dotenv gem 以适应Rails 4.1 secrets.yml文件。我还在.env文件中有database.yml的密码。

添加到我的部署:

set :linked_files, %w{config/database.yml .env}

当我运行cap production deploy时,我得到:

/shared/config/database.yml does not exist on 107.170.....

如何添加database.yml?

我查看capistrano touch gem没有运气,因为在我创建空文件后,ActiveRecord会抛出错误No 'production' database

1 个答案:

答案 0 :(得分:2)

创建任务以上传您的.envdatabase.yml。请查看以下示例:

desc "Database config"
  task :setup_config, roles: :app do
  # upload you database.yml from config dir to shared dir on server
  put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
  # make symlink
  run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  # upload you database.yml from config dir to shared dir on server
  put File.read(".env"), "#{shared_path}/config/.env"
  # make symlink
  run "ln -nfs #{shared_path}/config/.env #{current_path}/.env"
end

添加beforeafter个钩子。

或使用包含相同任务的dotenv-deployment