开发者

capistrano - write database.yml

I try to write an capistrano deploy script to set the database credentials through user input.

In my deploy file:

after "deploy:update_code", "db:write_credentials"
namespace :db do
task :write_credentials do
    @username = Capistrano::CLI.password_prompt('mysql_username: ')
    @password = Capistrano::CLI.password_prompt('mysql_password: ')
    @config = YAML::load(File.open("#{current_path}/config/database.yml"))['production']
    @config["username"] = @username
    @config["password"] = @password
  end
end

After running 'cap deploy' and entering the username and password the script fails with 开发者_如何转开发the message "No such file or directory - /var/www/rails_app/current/config/database.yml (Errno::ENOENT)".

The file under this path exists on the server, I also have it in my git repo.

I can't figure out why the file can't be found. Any hints?


The Yaml::load is executed locally on your machine from which you run cap deploy this is why that file is not found it is not being searched remotely.

Take a look at this gem: capistrano-recipes, if you want you can use that. Otherwise to learn how they're doing here

For completeness here are how you can read a remote file in a cap recipe

file = capture "cat #{shared_path}/config/database.yml"

capture will execute a remote command and return its output as a string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜