I want to protect my database.yml
file by keeping it out of version control. Thus, I have two tasks in my Capistrano deploy recipe:
我希望保护我的database.yml文件,使其不受版本控制。因此,我在Capistrano部署配方中有两个任务:
task :copy_db_config do
# copy local config file if it exists and is more
# recent than the remote one
end
task :symlink_db_config do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
Can you help fill in the first task?
你能帮忙填写第一个任务吗?
2 个解决方案
#1
I don't have functioning code for you here and now but..
我现在和你现在没有正常运行的代码但是..
you can the the local timestamp by using ruby. File class has a function ctime which let's You know when it was changed.
你可以使用ruby来获取本地时间戳。文件类有一个函数ctime,让你知道它什么时候被改变了。
Run the same command on the servers database.yml
在服务器database.yml上运行相同的命令
If the local one is newest, capistrano has a method for secure upload
如果本地最新,capistrano有一个安全上传的方法
upload("products.txt", "/home/medined", :via => :scp)
upload(“products.txt”,“/ home / medined”,:via =>:scp)
#2
I had the same problem, but I approached it differently. Maybe it will be helpful.
我遇到了同样的问题,但我的处理方式不同。也许它会有所帮助。
The setup task copies database.yml.example to database.yml. The deploy task does not touch database.yml. I have separate tasks for changing the database names, usernames, and passwords. Here's an example:
安装任务将database.yml.example复制到database.yml。部署任务不会触及database.yml。我有单独的任务来更改数据库名称,用户名和密码。这是一个例子:
desc "Change the database name"
task :change_db_database, :roles => :app do
database = prompt('Enter new database name: ')
run <<-CMD
cd #{shared_path}/config &&
perl -i -pe '$env = $1 if /^(\\w+)/; s/database:.*/database: #{database}/ if $env eq "#{ENV['CONNECTION'] || ENV['TARGET']}"' database.yml
CMD
end
I run these after setup but before the first deploy on new boxes. Then any time after that when I need to change database parameters, I use these tasks instead of copying in a new file.
我在安装后但在第一次部署新盒子之前运行这些。然后在我需要更改数据库参数之后的任何时候,我使用这些任务而不是在新文件中复制。
#1
I don't have functioning code for you here and now but..
我现在和你现在没有正常运行的代码但是..
you can the the local timestamp by using ruby. File class has a function ctime which let's You know when it was changed.
你可以使用ruby来获取本地时间戳。文件类有一个函数ctime,让你知道它什么时候被改变了。
Run the same command on the servers database.yml
在服务器database.yml上运行相同的命令
If the local one is newest, capistrano has a method for secure upload
如果本地最新,capistrano有一个安全上传的方法
upload("products.txt", "/home/medined", :via => :scp)
upload(“products.txt”,“/ home / medined”,:via =>:scp)
#2
I had the same problem, but I approached it differently. Maybe it will be helpful.
我遇到了同样的问题,但我的处理方式不同。也许它会有所帮助。
The setup task copies database.yml.example to database.yml. The deploy task does not touch database.yml. I have separate tasks for changing the database names, usernames, and passwords. Here's an example:
安装任务将database.yml.example复制到database.yml。部署任务不会触及database.yml。我有单独的任务来更改数据库名称,用户名和密码。这是一个例子:
desc "Change the database name"
task :change_db_database, :roles => :app do
database = prompt('Enter new database name: ')
run <<-CMD
cd #{shared_path}/config &&
perl -i -pe '$env = $1 if /^(\\w+)/; s/database:.*/database: #{database}/ if $env eq "#{ENV['CONNECTION'] || ENV['TARGET']}"' database.yml
CMD
end
I run these after setup but before the first deploy on new boxes. Then any time after that when I need to change database parameters, I use these tasks instead of copying in a new file.
我在安装后但在第一次部署新盒子之前运行这些。然后在我需要更改数据库参数之后的任何时候,我使用这些任务而不是在新文件中复制。