ruby-on-rails - Capistrano 部署到暂存和生产

标签 ruby-on-rails capistrano

我正在尝试使用 Capistrano 将 Ruby On Rails 应用程序部署到登台和生产。

两者之间的唯一区别是 :domain 和 :repository

我在这里遵循了本指南:https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension

我在网上搜索过,我找到的所有文章基本上都是我上面的内容。

我试过在 config/deploy/staging.rb 和 config/deploy/production.rb 中设置 :domain 和 :repository

我已经检查了我的拼写,以确保我拼写正确的子目录和文件的名称。

阅读本文:staging and live app with capistrano看起来我应该能够在这里声明差异。

看起来 staging.rb 文件实际上并没有被读取。我将我的“deploy.rb”更改为第一行有一个发誓词,“cap deploy”给了我预期的错误。

如果我在“staging.rb”或“production.rb”的第一行放一个脏话,我会得到同样的错误:

`method_missing': undefined local variable or method `domain'

有问题的行是:
role :web, domain

因为值(value)没有被提取。但它肯定应该在 staging.rb 或 production.rb 中的单个脏话上失败并且根本不运行吗?

如果我将 :domain 和 :repository 移回主“deploy.rb”文件,我会收到带有脏话的错误。因此,我似乎无法在“staging.rg”和“production.rb”文件中设置变量,而只能完成任务。

任何帮助将不胜感激,或者您认为我应该接受比萨饼送货工作......

部署.rb:
require 'capistrano/ext/multistage'
set :stages, %w(production staging)
set :default_stage, "staging"

set :user, 'dave'

set :applicationdir, "~/rails/example.com"

set :scm, 'git'

set :git_enable_submodules, 1 # if you have vendored rails
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true

set :keep_releases, 5
after "deploy:update", "deploy:cleanup"

# roles (servers)
role :web, domain
role :app, domain
role :db,  domain, :primary => true

after "deploy", "deploy:migrate"

# deploy config
set :deploy_to, applicationdir
set :deploy_via, :export
# set :rake, 'bundle exec rake'

# additional settings
default_run_options[:pty] = true  # Forgo errors when deploying from windows
set :ssh_options, {:forward_agent => true}
#ssh_options[:keys] = %w(/home/user/.ssh/id_rsa)            # If you are using ssh_keysset :chmod755, "app config db lib public vendor script script/* public/disp*"set :use_sudo, false


# Passenger
namespace :deploy do
   task :start do ; end
   task :stop do ; end
   task :restart, :roles => :app, :except => { :no_release => true } do
      run " touch #{File.join(current_path,'tmp','restart.txt')}"
   end
end

还有我的 config/deploy/staging.rb 文件:
set :domain, 'example.com'
set :repository,  "ssh://dave@example.com/~/rails/chamonix-mont-blanc.net"

如果我把 :domain 和 :repository 放在主要的“deploy.rb”中,它一切正常。

最佳答案

搬家 roles给您的 staging.rb文件,使其看起来像

set :domain, 'example.com'

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

set :repository,  "ssh://dave@example.com/~/rails/chamonix-mont-blanc.net"

deploy.rb 中删除角色代码.此外,您必须修改您的 production.rb相似地。

关于ruby-on-rails - Capistrano 部署到暂存和生产,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12001072/

相关文章:

capistrano - 上帝监控的delayed_job - 重启后重复进程

html - 在 "link_to"erb 标签中插入一个 HTML 元素?

ruby-on-rails - rspec-mocks 'allow' 返回未定义的方法

ruby-on-rails - 用于 RSpec 测试的带有间隔的假日期数据

ruby-on-rails - 使用 capistrano(rbenv) 部署时出现捆绑错误

ruby-on-rails - capistrano, :db role, 它是做什么用的?

ruby-on-rails - 在 Ruby 中使用 Rails 测试语法

html - 图片未上传

ruby - Capistrano 错误:<Rake::Task load:defaults => []>:Rake::Task 的未定义方法 `already_invoked'

ruby-on-rails - Noob Capistrano 关于保留上传目录的问题