在Rails部署中,有时我们错过了在定期部署项目后执行rake db:migrate,rake db:seed或任何rake作业。我试图用Rails结构添加这样的脚本,它将在部署后自动调用RakeJob和所有这类脚本。
就像这种顺序一样: -
rake db:migrate
rake db:seed
rake(这里Rake是所有佣金工作的组合)
答案 0 :(得分:0)
我通常部署到Heroku。我不确定您要部署到哪里,但这里是我的部署脚本的副本
#vim lib/tasks/deploy.rake
namespace :deploy do
#rake deploy:production # Deploy to production
desc "Deploy to production"
task :production do
puts "THIS IS DEPLOYING TO PRODUCTION!!!"
puts "********* CAREFUL! *********"
sleep 10
backup_environment_db("heroku-prod")
deploy_sha_to_environment(ARGV[1], "heroku-prod")
system("open http://www.example.com/")
end
def deploy_sha_to_environment(sha, environment)
if sha = ARGV[1]
puts "About to push #{sha} to #{environment}."
message = `git log --format=%B -n 1 #{sha}`
puts "#{sha} -- #{message}"
sleep 2
Bundler.with_clean_env do
system "git push --force git@heroku.com:#{environment}.git #{sha}:master"
system "heroku run rake db:migrate --app #{environment}"
system "heroku restart --app #{environment}"
end
else
puts
puts "*** sha required! (pass it as an argument) ***"
puts
Rake.application.invoke_task("codeship:statuses")
exit
end
end
end
我希望这有助于