关于这意味着什么,文档似乎有点稀疏。
我正在尝试设置由多级 capistrano 脚本部署的应用程序。
编辑:我正在尝试将相同的应用程序两次部署到同一台服务器。唯一真正的区别(除了 git 分支)是我想将每个副本部署到不同的文件夹。第一个实例是一个登台,我可以在与第二个实例完全相同的环境中测试应用程序,第二个实例是一个生产实例。capistrano 能做到这一点吗?
我运行暂存部署没有任何问题。但是,当我运行任何指定生产阶段的任务时(例如部署:设置,在这种情况下),我收到以下错误:
`deploy:setup' is only run for servers matching {:except=>{:no_release=>true}}, but no servers matched
这是我的 Deploy.rb
require "rvm/capistrano"
require "bundler/capistrano"
require "capistrano/ext/multistage"
#server "direct.measuremyho.me", :web, :app, :db, primary: true
set :stages, %w{staging production} # Set staging and production environment
set :default_stage, "staging" # Use staging environment as the default one to prevent accidentally deploying to production
set :application, "mmh"
set :user, "mmh"
set :deploy_via, :remote_cache
#set :deploy_to, "/var/www/#{application}"
set :use_sudo, false
set :keep_releases, 3
set :scm, "git"
set :repository, "git@localhost:#{application}.git"
set :local_repository, "git@direct.measuremyho.me:#{application}.git"
#set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy:update_code", "deploy:migrate"
after "deploy", "deploy:cleanup"
namespace :deploy do
%w[start stop].each do |command|
desc "#{command} nginx server"
task command, roles: :app, except: {no_release: true} do
sudo "#{try_sudo} service nginx #{command}"
end
end
desc "restart passenger server"
task :restart, roles: :app, except: { no_release: true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
task :setup_config, roles: :app do
# link the nginx config file in the app
# sudo "ln -nfs #{current_path}/config/nginx.conf "\
# "/opt/nginx/conf/nginx.conf"
# make the shared rails config directory
run "mkdir -p #{shared_path}/config"
# ftp the database.yml file to that directory
put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
# make the shared uploads directory
run "mkdir -p #{shared_path}/uploads"
# tell the user to edit database.yml
puts "==> IMPORTANT!!! Now edit database.yml in "\
"#{shared_path}/config <==="
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "rm -rf #{release_path}/public/uploads"
run "ln -nfs #{shared_path}/uploads #{release_path}/public/"
end
after "deploy:finalize_update", "deploy:symlink_config"
end
我的登台.rb
set :application_directory, "staging"
set :rails_env, "staging"
set :main_server, 'direct.measuremyho.me'
set :branch do
default_tag = `git tag`.split("\n").last
tag = Capistrano::CLI.ui.ask "Tag to deploy (make sure to push the tag first): [#{default_tag}] "
tag = default_tag if tag.empty?
branch = "release/#{tag}"
branch
end
# Do not modify
# Set up the server
server "#{main_server}", :web, :app, :db, :primary => true
set :deploy_to, "/var/www/mmh/#{application_directory}"
我的生产.rb
set :application_directory, "production"
set :rails_env, "production"
set :main_server, 'direct.measuremyho.me'
set :branch, "master"
# Do not modify
# Set up the server
server "#{main_server}", :web, :app, :db, :primary => true
set :deploy_to, "/var/www/mmh/#{application_directory}"
我的问题是,为什么要设置这个?此外,我可以做些什么来避免设置这个变量,以便我可以使用部署命令。
如果我错过了任何相关信息,请告诉我。