Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 角色筛选在capistrano中不起作用_Ruby On Rails_Ruby_Deployment_Capistrano_Capistrano3 - Fatal编程技术网

Ruby on rails 角色筛选在capistrano中不起作用

Ruby on rails 角色筛选在capistrano中不起作用,ruby-on-rails,ruby,deployment,capistrano,capistrano3,Ruby On Rails,Ruby,Deployment,Capistrano,Capistrano3,我用的是CapistranoV3 我有两台服务器,其中一台要部署两个存储库,另一台只有一个。因此,我通过筛选角色为部署设置capistrano 我的staging.rb文件具有此配置 # server-based syntax # ====================== server '172.28.128.3', user: 'vagrant', roles: %w{api} server '172.28.128.3', user: 'vagrant', roles: %w{admin

我用的是CapistranoV3

我有两台服务器,其中一台要部署两个存储库,另一台只有一个。因此,我通过筛选角色为部署设置capistrano

我的staging.rb文件具有此配置

# server-based syntax 
# ======================
server '172.28.128.3', user: 'vagrant', roles: %w{api}
server '172.28.128.3', user: 'vagrant', roles: %w{admin}
server '172.28.128.4', user: 'vagrant', roles: %w{apg}

# role-based syntax
# ==================
role :api, %w{vagrant@172.28.128.3}
role :admin, %w{vagrant@172.28.128.3}
role :apg, %w{vagrant@172.28.128.4}

# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
 set :ssh_options, {
   keys: %w(/home/anyname/.ssh/id_rsa),
   forward_agent: true,
   auth_methods: %w(publickey),
   user: 'vagrant'
  }
我已在deploy.rb中添加了此任务

# config valid only for current version of Capistrano
lock '3.4.0'

set :branch, 'master'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

# Default deploy_to directory is /var/www/my_app_name
#set :deploy_to, '/var/www/{fetch(:application)}'
#ser :repo_path, ':Q'
# Default value for :scm is :git
set :scm, :git

# Default value for :format is :pretty
set :format, :pretty

# Default value for :log_level is :debug
# set :log_level, :debug

# Default value for :pty is false
set :pty, true

# Default value for :linked_files is []
#set :linked_files, fetch(:linked_files, []).push('composer.lock')

# Default value for linked_dirs is []
#set :linked_dirs, fetch(:linked_dirs, []).push('vendor')

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
set :keep_releases, 5

namespace :deploy do

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
    # Here we can do anything such as:
    # within release_path do
    #   execute :rake, 'cache:clear'
    # end
   end
 end

  desc "select git url"
  task :select_repo do
    on roles(:all) do |host|
      if host.roles.include?(:apg)
        set :repo_url, 'git@bitbucket.org:something/repo1.git'
        set :application, 'webartists'
      elsif host.roles.include?(:api)
        set :repo_url, 'git@bitbucket.org:something/repo2.git'
        set :application, 'webapi'
        set :linked_files, fetch(:linked_files, []).push('composer.lock')
        set :linked_dirs, fetch(:linked_dirs, []).push('vendor')
      elsif host.roles.include?(:admin)
        set :repo_url, 'git@bitbucket.org:something/repo3.git'
        set :application, 'webadmin'
      end
    end
  end
  before :deploy, "deploy:select_repo"
end
当我跑的时候

$cap --roles=api staging deploy

$cap --roles=apg staging deploy
它在这两种情况下都成功地部署了回购

但是当我跑的时候

$cap --roles=admin staging deploy

它开始运行api角色,并开始部署该角色而不是管理员角色。

我认为为每个
repo\u url/应用程序的组合创建一个单独的阶段会更好。Capistrano的设计假设它们只有一个值。角色筛选并不意味着以您尝试的方式工作

换句话说,创建三个阶段:

deploy/staging_webartists.rb
deploy/staging_webapi.rb
deploy/staging_webadmin.rb
并在每个阶段定义适当的
:repo_url
:应用程序
。例如:

# deploy/staging_webartists.rb
set :repo_url, 'git@bitbucket.org:something/repo1.git'
set :application, 'webartists'
然后,不进行角色筛选,而是通过指定所需阶段进行部署:

cap staging_webartists deploy