【问题标题】:capistrano deploy from one local directory to anothercapistrano 从一个本地目录部署到另一个
【发布时间】:2011-11-29 10:52:43
【问题描述】:

我想在我的本地机器上部署应用程序。例如,我的 Rails APP 位于: /home/thesis/dev/myapp 但我想 cap deploy:setup/home/thesis/deploy/。我已经尝试过了,但是 capistrano 尝试连接到localhost,但根本不需要它。我该如何解决?

这是我的 deploy.rb

role :app, "localhost"
role :web, "localhost"
role :db,  "localhost", :primary => true

set(:deploy_to) { "/home/thesis/dev/myapp" }
set :bundle_without,  [:development, :test]
set :use_sudo, false

set :repository, "."
set :scm, :none
set :deploy_via, :copy

set :copy_dir, "/home/thesis/deploy/tmp"
set :copy_remote_dir, "/home/thesis/deploy/tmp"

它会掉落:

connection failed for: localhost (Errno::ECONNREFUSED: Connection refused - connect(2))

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 capistrano


    【解决方案1】:

    localhost 问题是因为您在 role 定义中设置了它。由于您在本地执行所有这些操作,并且由于 Capistrano 需要角色,您可以设置以下内容:

    role :app, ""
    

    我还认为您设置的 copy_dircopy_remote_dir 值不正确。我建议删除这些并让 Capistrano 使用它的默认值。

    这是一个适合你的完整配置:

    role :app, ""
    
    set :use_sudo, false
    set :application, 'thesis'     # you'll need to specify an app name
    set :repository, "."
    set :scm, :none
    set :deploy_to, "/home/thesis/deploy/"   # the destination dir
    set :deploy_via, :copy
    
    # override deploy:restart since this isn't a Rails app
    namespace :deploy do
      task :restart do
        # no-op
      end
    end
    

    【讨论】:

    • 这应该不起作用,因为:deploy_code 任务使用 SSH 连接。连接到“”会抛出异常。
    • @Jani 在我的脑海中浮现——通过在本地设置 SSHD 等等来平局。
    • 这项工作没有通过 ssh 吗? @BryanH 有一个很好的观点,但这个答案被标记为已接受。
    • 它不起作用,因为它仍然尝试通过 SSH 连接到本地主机。解决方案是按照@BryanH 的建议设置本地 SSH 服务器。
    • 问题是 ssh 服务器未配置。以下@Bruno Peres 的回答是正确答案。
    【解决方案2】:

    您的机器上可能缺少用于连接的 SSH 服务器,因为您只安装了客户端。

    测试ssh 127.0.0.1,如果还是出现连接拒绝错误,使用:

    sudo apt-get install openssh-server

    安装 ssh 服务器。

    【讨论】:

      【解决方案3】:

      我也遇到了这个问题,因为我将 SSH 端口设置为 13000,而不是默认端口 22。 并添加了 /etc/hosts.deny

      sshd:ALL
      

      /etc/hosts.allow 添加

      sshd:#some allowed IPs
      

      我处理的是:

      1) 添加到 deploy.rb

      ssh_options[:port] = 13600
      

      2) 将 localhost 添加到 hosts.allow

      sshed:127.0.0.1 localhost # others allowed IPs
      

      【讨论】:

        【解决方案4】:

        您需要安装 ssh 服务器才能进行本地部署,例如 openssh(sudo apt-get install openssh-server 安装)

        config/deploy/staging.rb

        set :stage, :staging
        
        role :app, %w{127.0.0.1}
        role :web, %w{127.0.0.1}
        role :db,  %w{127.0.0.1}
        
        server '127.0.0.1', user: 'your-username', roles: %w{web app}
        set :branch, "staging"
        

        config/deploy.rb

        set :deploy_to ,'/home/your/app/path/deploy'
        # Path of tests to be run, use array with empty string to run all tests
        set :tests, ['']
        
        namespace :deploy do
          desc "Runs test before deploying, can't deploy unless they pass"
          task :run_tests do
            test_log = "log/capistrano.test.log"
            tests = fetch(:tests)
            tests.each do |test|
              puts "--> Running tests: '#{test}', please wait ..."
              unless system "bundle exec rspec #{test} > #{test_log} 2>&1"
                puts "--> Aborting deployment! One or more tests in '#{test}' failed. Results in: #{test_log}"
                exit;
              end
              puts "--> '#{test}' passed"
            end
            puts "--> All tests passed, continuing deployment"
            system "rm #{test_log}"
          end
        
          # Only allow a deploy with passing tests to be deployed
          before :deploy, "deploy:run_tests"
        end
        

        使用 with 运行它

        cap staging deploy
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-05-04
          • 2014-06-18
          • 2013-03-31
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多