简体   繁体   English

有没有办法使用 Capistrano 部署到 vagrant VM 中?

[英]Is there a way to deploy into a vagrant VM using Capistrano?

I'd like to setup a vagrant instance outside of my project directory.我想在我的项目目录之外设置一个 vagrant 实例。 Is there a way to deploy rails into the vagrant VM with capistrano as I would to my real production host?有没有办法像我在真正的生产主机上那样使用 capistrano 将 rails 部署到 vagrant VM 中?

I'm trying to use server as "localhost" but I get:我正在尝试将服务器用作“本地主机”,但我得到:

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

You can also feed Vagrant's SSH options to Capistrano (most of the :ssh_options go directly to Net::SSH, http://net-ssh.github.com/ssh/v1/chapter-2.html , see "Options") so there is no need to mess your real ~/.ssh/config 你也可以将Vagrant的SSH选项提供给Capistrano(大部分:ssh_options直接转到Net :: SSH, http :ssh_options ,参见“选项”)所以没有必要弄乱你的真实〜/ .ssh / config

set :user, 'vagrant'
set :ssh_options, {port: 2222, keys: ['~/.vagrant.d/insecure_private_key']}

role :web, "localhost" 
...

(Of course, you shouldn't really be using the insecure_private_key or the default root/vagrant passwords unless properly firewalled, but the principle remains the same.) (当然,你不应该使用insecure_private_key或默认的root / vagrant密码,除非适当防火墙,但原则保持不变。)

I figured it out. 我想到了。 In case others care to know: 如果其他人想知道:

  1. I created a separate folder and did the whole Vagrant init there. 我创建了一个单独的文件夹并在那里完成了整个Vagrant init。
  2. I configured the Vagrant file to use a bridged network. 我将Vagrant文​​件配置为使用桥接网络。
  3. I signed into my vagrant VM ( $ vagrant ssh ) and ran ifconfig to get my IP address. 我登录了我的流浪汉( $ vagrant ssh )并运行ifconfig来获取我的IP地址。
  4. I added that IP address to my Capistrano deploy file. 我将该IP地址添加到我的Capistrano部署文件中。
  5. I passed along vagrants ssh info to my local configs: vagrant ssh-config >> ~/.ssh/config 我将流浪者ssh信息传递给我的本地配置: vagrant ssh-config >> ~/.ssh/config
  6. I ran my deploy, when prompted for the SSH password, I used vagrant 我运行部署,当提示输入SSH密码时,我使用了vagrant

It worked. 有效。

I had the same issue and thanks to the solution of @Nathan I could fix the issue.我遇到了同样的问题,感谢@Nathan 的解决方案,我可以解决这个问题。 I have a different release setup.我有不同的发布设置。 Was trying to test release a ruby project in my VM with Capistrano, but had a authentication error on user@localhost.正在尝试使用 Capistrano 在我的 VM 中测试发布 ruby 项目,但在 user@localhost 上出现身份验证错误。 SSH user@localhost worked fine. SSH user@localhost 工作正常。

My build setup is Oracle Virtual Box with Ubuntu 22.04 LTS installed as VM.我的构建设置是 Oracle Virtual Box,其中 Ubuntu 22.04 LTS 安装为 VM。 To connect with SSH to your VM with Capistrano you have to do the following:要使用 Capistrano 将 SSH 连接到您的 VM,您必须执行以下操作:

  1. Go to your settings of the VM eg ubuntu 22.04 LTS; Go 到您的 VM 设置,例如 ubuntu 22.04 LTS;
  2. Go to Network and set Attached to Bridged Adapter Go 到网络并设置连接到Bridged Adapter
  3. Set Name to your local network: mine was wlp4s0将名称设置为您的本地网络:我的是wlp4s0
  4. Set Promisecuous Mode to Allow All ;将 Promsecuous 模式设置为Allow All
  5. Now restart your Ubuntu VM and check your ip under inet by running ifconfig ;现在重新启动您的 Ubuntu 虚拟机并通过运行ifconfiginet下检查您的 ip;
  6. Try to connect to your server with SSH to check if it still works ssh user_for_cap@ip_address尝试使用 SSH 连接到您的服务器以检查它是否仍然有效ssh user_for_cap@ip_address
  7. Put that ip as config in your cap file and connect with ssh_options like: server 'ip_address', user: 'user_for_cap', roles: %w[app], port: 22将 ip 作为配置放入您的 cap 文件中,并使用 ssh_options 连接,例如: server 'ip_address', user: 'user_for_cap', roles: %w[app], port: 22

It Worked!有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM