我正在使用capistrano v3
我有2台服务器,其中一台有两个要部署的存储库,另一台只有一台。所以我通过过滤角色来设置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
它在两种情况下都成功部署了repo
但是当我跑步时
$cap --roles=admin staging deploy
它开始运行api角色并开始部署而不是管理员。
答案 0 :(得分:1)
我认为通过为每个@font-face{
font-family: 'Frutiger';
src: url('/FrutigerLTW01-47LightCn.eot');
src: url('/FrutigerLTW01-47LightCn.woff') format('woff');
font-weight: lighter;
font-style: normal;
}
组合创建一个单独的舞台会更好。 Capistrano的设计假设它们只有一个值。角色过滤并不意味着按照您的尝试方式工作。
换句话说,创建三个阶段:
repo_url/application
在每个阶段定义适当的deploy/staging_webartists.rb
deploy/staging_webapi.rb
deploy/staging_webadmin.rb
和:repo_url
。 E.g:
:application
然后通过指定所需的阶段来代替角色过滤:
# deploy/staging_webartists.rb
set :repo_url, 'git@bitbucket.org:something/repo1.git'
set :application, 'webartists'