gpt4 book ai didi

ruby-on-rails - Capistrano - 将一个应用程序部署到同一台服务器两次,用于登台和生产

转载 作者:行者123 更新时间:2023-12-04 05:44:50 25 4
gpt4 key购买 nike

关于这意味着什么,文档似乎有点稀疏。

我正在尝试设置由多级 capistrano 脚本部署的应用程序。

编辑:我正在尝试将同一个应用程序部署两次到同一个服务器。唯一真正的区别(git 分支除外)是我想将每个副本部署到不同的文件夹。第一个实例是一个登台,我可以在与第二个实例(生产实例)完全相同的环境中测试应用程序。 capistrano 能做到这一点吗?

我运行暂存部署没有任何问题。但是,当我运行任何指定我的生产阶段的任务时(例如 deploy:setup,在这种情况下)我收到以下错误:

`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}"

我的问题是,为什么要设置这个?此外,我可以做些什么来避免设置此变量,以便我可以使用部署命令。

如果我错过了任何相关信息,请告诉我。

最佳答案

我已经通过替换以下行解决了这个问题:

server "#{main_server}", :web, :app, :db, :primary => true

和:
server "#{main_server}", :web, :app, :db, :primary => true, :no_release => false

在我的 production.rb 文件中。

但是,这是一个 hacky 解决方案,我想了解我应该如何正确地将 Rails 应用程序两次部署到同一台服务器上,以用于暂存和生产目的。或者,为什么我不应该这样做,以及替代方案是什么。所以,我没有回答这个问题。

我正在尝试扩展 this通过提供包含其步骤的教程,以及设置自托管 git 存储库而不是 github 和部署脚本,以便在同一服务器上暂存和生产应用程序版本,这是一个有用的答案。所以这个问题回答了这个过程的一个关键部分。我试图了解对于这种情况的最佳实践是什么。

欢迎评论;我会将它们添加到这个答案中。

关于ruby-on-rails - Capistrano - 将一个应用程序部署到同一台服务器两次,用于登台和生产,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19920938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com