部署 一个 mina 的部署脚本

mjason · 2013年05月29日 · 最后由 zealinux 回复于 2013年06月07日 · 4362 次阅读
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'    # for rvm support. (http://rvm.io)

set :domain, 'xxx.xxx.xxx'
set :deploy_to, '/xxx/xxxx/xxxx'
set :repository, '[email protected]/xxx.git'
set :shared_paths, ['config/database.yml', 'log']
set :user, 'xxx'    # Username in the server to SSH to.

task :environment do
  invoke :'rvm:use[ruby-2.0.0-p0]'
end

task :setup => :environment do
  queue! %[mkdir -p "#{deploy_to}/shared/log"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]

  queue! %[mkdir -p "#{deploy_to}/shared/config"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]
end

desc "Deploys the current version to the server."
task :deploy => :environment do
  set :branch, 'master'
  deploy do
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'  
  end
end

task :restart => :environment do
  queue """
  if [ -d #{deploy_to}/current/tmp ]
  then
    touch #{deploy_to}/current/tmp/restart.txt 
  else
    mkdir #{deploy_to}/current/tmp
    touch #{deploy_to}/current/tmp/restart.txt 
  fi
  """
end

task :deploy_to_dev => :environment do
  set :branch, 'dev'
  deploy do
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'  
  end
end

task :cat_server_log => :environment do
  queue "tail -n 200 #{deploy_to}/current/log/production.log"
end

task :remove => :environment do
  queue "rm -rf #{deploy_to}"
end

task :console => :environment do
  queue "cd #{deploy_to}/current && bundle exec rails c production"
end

不错啊,很好。想增加环境变量怎么做呢?例如: 'LANG' => 'zh_CN.UTF-8', 'RUBY_HEAP_MIN_SLOTS'=>620000。

收藏,过一阵子准备用上

@mjason rake db:create 判断怎么写

需要 登录 后方可回复, 如果你还没有账号请 注册新账号