capistrano 一个脚本同时部署到多个域名

访问量: 321

关键是:

set(:server_type) {
  puts "== 现在咱们的服务器要根据  cms 和  api 这两个子域名做部署。"
  Capistrano::CLI.ui.ask("== 希望部署哪个?? 输入: (cms/api)? ")
}

case server_type.chomp
  when 'cms'
    deploy_to = "/opt/app/topgroup_web"
  else
    deploy_to = "/opt/app/api.topgroup.mobi"
  end

set :deploy_to, deploy_to

下面是完整脚本:

# -*- encoding : utf-8 -*-
require 'capistrano-rbenv'
load 'deploy/assets'
SSH_USER = 'root'
ssh_options[:port] = ?????
set :rake, "bundle exec rake"
set :application, "topgroup web"
set :repository, "."
set :scm, :none
set :deploy_via, :copy
server = "cms.topgroup.mobi"

role :web, server
role :app, server
role :db,  server, :primary => true
role :db,  server

default_run_options[:pty] = true

# change to your username
set :user, SSH_USER

set(:server_type) {
  puts "== 现在咱们的服务器要根据  cms 和  api 这两个子域名做部署。"
  Capistrano::CLI.ui.ask("== 希望部署哪个?? 输入: (cms/api)? ")
}

case server_type.chomp
  when 'cms'
    deploy_to = "/opt/app/topgroup_web"
  else
    deploy_to = "/opt/app/api.topgroup.mobi"
  end

set :deploy_to, deploy_to

namespace :deploy do
  task :start do
    run "cd #{release_path} && bundle exec thin start -C config/thin.yml"
  end
  task :stop do
    run "cd #{release_path} && bundle exec thin stop -C config/thin.yml"
  end
  task :restart, :roles => :app, :except => { :no_release => true } do
    db_migrate
    stop
    sleep 2
    start
  end
  task :db_migrate do
    run "cd #{release_path} && bundle install"
    run "cd #{release_path} && bundle exec rake db:migrate RAILS_ENV=production"
  end

  namespace :assets do
    task :precompile do
  #    puts "======= should run precompile"
  #    command = "cd #{release_path} && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile "
  #    puts "== please run == \n #{command} \n == manually after deploy is done"
      #run "bundle install"
      #run "cd #{release_path} && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile "
    end
  end
end


desc "Copy database.yml to release_path"
task :cp_database_yml do
  puts "=== executing my customized command: "
  run "cp -r #{shared_path}/config/* #{release_path}/config/"
  #run "ln -s #{shared_path}/files #{release_path}/public/files "
  ## 因为在开发机器上会存在这个文件夹,所以需要先把它删掉,再 ln
  #run "rm #{release_path}/public/uploads -rf"
  #run "ln -s #{shared_path}/public/uploads #{release_path}/public/uploads"
  puts "=== done (executing my customized command)"
end

before "deploy:assets:precompile", :cp_database_yml

订阅/RSS Feed

Subscribe

分类/category