3

i am using mina for deploying my application. I specify the env(staging/production) where i want to deploy the app.

mina deploy on=staging --verbose

i have saved the app env in deploy.rb as

app_env = ENV['on'] || 'staging'

i have a rake task that takes production database backup. As of now, i run that rake task explicitly on my console as

bundle exec rake deploy:backup_prod_db --trace

I want to run that task on every production deployment. How do i do it?

4

2 回答 2

2

mina 对此有特殊的语法。从 mina 控制台帮助页面:

Server tasks:
  ...
  mina rails[arguments]   # Execute a Rails command in the current deploy
  mina rake[arguments]    # Execute a Rake command in the current deploy
  mina run[command]       # Runs a command in the server
  ...

所以从命令行:

$ mina 'rake[deploy:backup_db]'

或者在 mina deploy 配置文件 ( config/deploy.rb) 中定义任务:

task :backup_db do
  invoke :'rake[deploy:backup_db]'
end
于 2016-12-16T17:54:07.803 回答
1

让它工作。变化是

...
app_env = ENV['on'] || 'staging'
...

desc "Deploys the current version to the server."
task :deploy => :environment do
  deploy do
    # Put things that will set up an empty directory into a fully set-up
    # instance of your project.
    invoke 'production_backup' if app_env == 'production'
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:assets_precompile'

    to :launch do
      invoke 'application:restart'
    end
  end
end

task :production_backup do
  queue "cd #{deploy_to}/current ; bundle exec rake deploy:backup_db"
end
于 2013-12-11T10:56:53.780 回答