Ruby on rails 4 ROR+;部署后自动运行Rake作业
在Rails部署中,有时在定期部署项目后,我们没有执行rake db:migrate、rake db:seed或任何rake作业。我正在尝试使用Rails结构添加这样的脚本,它将在部署后自动调用RakeJob和所有此类脚本 就像这样循序渐进:- rake数据库:迁移 rake-db:种子Ruby on rails 4 ROR+;部署后自动运行Rake作业,ruby-on-rails-4,rake,rake-task,Ruby On Rails 4,Rake,Rake Task,在Rails部署中,有时在定期部署项目后,我们没有执行rake db:migrate、rake db:seed或任何rake作业。我正在尝试使用Rails结构添加这样的脚本,它将在部署后自动调用RakeJob和所有此类脚本 就像这样循序渐进:- rake数据库:迁移 rake-db:种子 rake(这里rake是所有rake作业的组合)我通常部署到Heroku。我不确定您要部署到哪里,但这是我的部署脚本的副本 #vim lib/tasks/deploy.rake namespace :depl
rake(这里rake是所有rake作业的组合)我通常部署到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
我希望这会有所帮助为什么不使用capistrano进行部署?这非常有帮助,您可以根据需要添加任何任务以在部署后执行