capistrano从一个本地目录部署到另一个本地目录

时间:2011-11-29 10:52:43

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

我想在本地计算机上部署应用程序。例如,我有我的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))

4 个答案:

答案 0 :(得分:8)

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

答案 1 :(得分:2)

也许您因为只安装了客户端而错过了在您的计算机上连接的SSH服务器。

测试ssh 127.0.0.1,如果仍然出现连接拒绝错误,请使用:

sudo apt-get install openssh-server

安装ssh服务器。

答案 2 :(得分:1)

我也遇到了这个问题,因为我已将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

答案 3 :(得分:0)

您需要安装ssh服务器才能使本地部署正常工作,例如openssh(要安装sudo apt-get install openssh-server

配置/部署/ 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"

配置/ 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

使用

运行它
cap staging deploy