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

发布于 2024-12-18 10:57:52 字数 738 浏览 3 评论 0原文

我想在本地计算机上部署应用程序。例如我的 Rails APP 位于: /home/thesis/dev/myapp 但我想将 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))

I want to deploy application on my local machine. For example I have my Rails APP in:
/home/thesis/dev/myapp but I want to cap deploy:setup to /home/thesis/deploy/. I have tried that but capistrano tries to connect to localhost, but it is not needed at all. How can I solve it?

Here goes my 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"

It drops with:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

楠木可依 2024-12-25 10:57:52

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

The localhost issue is because you're setting this in the role definitions. Since you're doing all this locally, and since Capistrano requires a role, you can set the following:

role :app, ""

I also think you're setting the copy_dir and copy_remote_dir values incorrectly. I'd recommend removing these and letting Capistrano use it's defaults.

Here's a full config which should work for you:

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
淤浪 2024-12-25 10:57:52

也许您缺少连接计算机的 SSH 服务器,因为您只安装了客户端。

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

sudo apt-get install openssh-server

来安装ssh服务器。

Maybe you're missing a SSH server to connect on your on machine because you only have the client installed.

Test ssh 127.0.0.1, if you still get a connection refuse error, use:

sudo apt-get install openssh-server

To install the ssh server.

昵称有卵用 2024-12-25 10:57:52

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

I also get this problem, for I had set SSH port to 13000, not the default port 22.
And the /etc/hosts.deny added

sshd:ALL

/etc/hosts.allow added

sshd:#some allowed IPs

I processing are:

1) add to deploy.rb

ssh_options[:port] = 13600

2) add localhost to hosts.allow

sshed:127.0.0.1 localhost # others allowed IPs
甜警司 2024-12-25 10:57:52

您需要安装 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

运行它

cap staging deploy

You need to have an ssh server installed for local deployment to work, such as openssh (sudo apt-get install openssh-server to install)

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

Run it with with

cap staging deploy
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文