【问题标题】:capistrano version 3 upgrade confusingcapistrano 版本 3 升级令人困惑
【发布时间】:2014-02-03 23:26:07
【问题描述】:

我正在努力将 capistrano v2 升级到 v3 5 天。我正在尝试从我的本地机器部署到 ec2 实例开发环境。我不能再进一步了。我的踪迹在这里

$cap 开发部署:检查

INFO [429e612c] Running /usr/bin/env mkdir -p /tmp/my_app_name/ on 70.22.320.14
DEBUG [429e612c] Command: ( RVM_BIN_PATH=~/.rvm/bin /usr/bin/env mkdir -p /tmp/my_app_name/ )
 INFO [429e612c] Finished in 6.208 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/my_app_name/git-ssh.sh 0.0%
 INFO Uploading /tmp/my_app_name/git-ssh.sh 100.0%
 INFO [c3a41f2e] Running /usr/bin/env chmod +x /tmp/my_app_name/git-ssh.sh on 70.22.320.14
DEBUG [c3a41f2e] Command: ( RVM_BIN_PATH=~/.rvm/bin /usr/bin/env chmod +x /tmp/my_app_name/git-ssh.sh )
 INFO [c3a41f2e] Finished in 0.720 seconds with exit status 0 (successful).
DEBUG [c5891dcc] Running /usr/bin/env git ls-remote git@github.com:example/webapp.git
 on 70.22.320.14
DEBUG [c5891dcc] Command: ( RVM_BIN_PATH=~/.rvm/bin GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/my_app_name/git-ssh.sh /usr/bin/env git ls-remote  git@github.com:example/webapp.git
DEBUG [c5891dcc]    /usr/bin/env: 
DEBUG [c5891dcc]    git
DEBUG [c5891dcc]    : No such file or directory
DEBUG [c5891dcc]    
DEBUG [c5891dcc] Finished in 0.664 seconds with exit status 127 (failed).

config/deploy.rb

set :application, 'my_app_name'
set :repo_url, '.'
set :branch, 'master'
set :scm, :git
set :deploy_to, "/home/ec2-user/capistrano-3/}"
set :ssh_options, {:keys => ["#{ENV['HOME']}/.ssh/my_pem.pem"], :forward_agent =>true}
set :keep_releases, 5
set :rvm_type, :user
set :rvm_ruby_version, '2.0.0-p353'
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
set :whenever_command, "bundle exec whenever"
set :git_shallow_clone, 1
set :deploy_via, :copy

set :log_level, :debug
set :pty, true
set :linked_files, %w{config/database.yml}


SSHKit.config.command_map[:rake]  = "bundle exec rake"
SSHKit.config.command_map[:rails] = "bundle exec rails"

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      # execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end

  after :finishing, 'deploy:cleanup'

end

config/deploy/development.rb

set :stage, :development


role :app, %w{ec2-user@70.22.320.14}
role :web, %w{ec2-user@70.22.320.14}
role :db,  %w{ec2-user@70.22.320.14}
role :all,  %w{ec2-user@70.22.320.14}

server 'ec2-user@70.22.320.14', user: 'ec2-user', roles: %w{web app}

Capfile

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

我的问题:

  1. 我的 git 路径不被接受

  2. ssh 密钥问题

git 和 ssh 密钥与 capistrano 2 一起用于我正在部署的同一应用程序。升级到 capistrano v3 会让人更加头疼。我可以连续做什么。请指导我完成正确的步骤

【问题讨论】:

  • 不需要SSHKit.config.command_map :rake:railscapistrano/bundler 会负责。
  • 另外,只需要serverrole :app/:web/:db 之一。在这种情况下,我认为 server 会覆盖特定的 :app/:web/:db

标签: ruby-on-rails git amazon-web-services ssh capistrano


【解决方案1】:

我花了一些时间在 capistrano3 上苦苦挣扎,这里有一些提示,它们可能有用:

1) 官方手册capistranorb.com。有一些关于你应该连续做什么的提示。关于身份验证和授权的部分也很有帮助。有一些关于在工作站和服务器上配置 ssh 的提示。我已按照本指南进行操作,它对我有帮助。尝试按照本指南从头开始构建您的 deploy.rb。

还有有用的指南:guide1guide2

2) 这是我的 Capfile。注意 rvm1/capistrano3 和 capistrano3/unicorn。非常有用的宝石。

    require 'capistrano/setup'

    require 'capistrano/deploy'
    require 'capistrano3/unicorn'
    require 'rvm1/capistrano3'
    require 'capistrano/rvm'
    require 'capistrano/bundler'
    require 'capistrano/rails/assets'
    require 'capistrano/rails/migrations'

3) 你可以试试命令:

ssh ubuntu@ec2....amazonaws.com -v 

ssh git@github.com -v   # from your EC2 server

了解当您尝试连接到 EC2 服务器时会发生什么。可能是pem key的问题?创建 .pub 密钥并尝试使用它。不要忘记将它添加到 ~/ssh/authorized_keys

cat id_rsa_aws.pub | ssh ubuntu@....amazonaws.com "cat >>   
/home/ubuntu/.ssh/authorized_keys"

配置你的 ssh-agent,不要忘记在你的 ~/.bash_profile 中添加如下内容:

eval $(ssh-agent)
ssh-add ~/.ssh/id_rsa_deploy_github
ssh-add ~/.ssh/id_rsa_digital_ocean

如果你对 ssh 有问题,可能你应该看看这个ssh-guide

您还可以观看我正在使用 capistrano3 的应用程序。或许你能找到适合你的东西:#project

附:在某些 VPS 上未安装 git,因此最好检查一下:

deployer@ec2***.amazonaws.com$ which git

如果没有找到:

deployer@ec2***.amazonaws.com$ sudo apt-get install git

【讨论】:

  • 我的远程服务器不包含 git。所以我在我的遥控器中添加了 git。现在我的问题解决了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-04
  • 2022-01-21
  • 2022-01-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多