capistrano版本升级令人困惑

时间:2014-01-15 13:11:40

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

我正在努力将capistrano v2升级到v3 5天。我正在尝试从我的本地机器部署到ec2实例开发环境。我无法继续前进。我的踪迹在这里

$ cap development deploy:check

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).

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

配置/部署/ 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关键问题

  3. git和ssh键与我正在部署的同一个应用程序使用capistrano 2。升级到capistrano v3会让人头疼。我能连续做什么请指导我完成正确的步骤

1 个答案:

答案 0 :(得分:4)

我花了一些时间与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键的问题?创建.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

P.S。在某些VPS上没有安装git,所以最好检查一下:

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

如果没有找到:

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