【问题标题】:Capistrano deploy failing on git:checkCapistrano 在 git 上部署失败:检查
【发布时间】:2016-12-03 00:04:00
【问题描述】:

尝试使用 Puma/Nginx/Capistrano 在 EC2 实例上部署 Rails 应用程序。我在关注this tutorial.

这是我的第一次部署,不知道到底发生了什么。从控制台输出来看,我的 ssh 配置似乎存在问题,但我真的不确定是否有任何帮助将不胜感激。

这是 deploy.rb

server '52.206.222.73', roles: %w{web app db}, primary: true

set :repo_url,        'git@example.com:username/myapp.git'
set :application,     'myapp'
set :user,            'deploy'
set :puma_threads,    [4, 16] 
set :puma_workers,    0   

# Don't change these unless you know what you're doing
set :pty,             true
set :use_sudo,        false
set :stage,           :production
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/#{fetch(:user)}/#{fetch(:application)}"
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.log"
set :ssh_options,     { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil 
set :puma_init_active_record, true  # Change to false when not using ActiveRecord

## Defaults:
# set :scm,           :git
# set :branch,        :master
# set :format,        :pretty
# set :log_level,     :debug
# set :keep_releases, 5

## Linked Files & Directories (Default None):
# set :linked_files, %w{config/database.yml}
# set :linked_dirs,  %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

namespace :puma do
  desc 'Create Directories for Puma Pids and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
    end 
  end   

以及 cap production deploy --trace 的输出

** Execute git:wrapper
    00:00 git:wrapper
          01 mkdir -p /tmp
        ✔ 01 deploy@52.206.222.73 0.695s
          Uploading /tmp/git-ssh-myapp-production-adam.sh 100.0%
          02 chmod 700 /tmp/git-ssh-myapp-production-adam.sh
        ✔ 02 deploy@52.206.222.73 0.921s
    ** Execute git:check
    00:04 git:check
          01 git ls-remote --heads git@example.com:username/amharic-web.git
    cap aborted!
    SSHKit::Runner::ExecuteError: Exception while executing as deploy@52.206.222.73: git exit status: 128
    git stdout: Nothing written
    git stderr: Nothing written
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
    SSHKit::Command::Failed: git exit status: 128
    git stdout: Nothing written
    git stderr: Nothing written
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/command.rb:100:in `exit_status='
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/backends/netssh.rb:148:in `execute_command'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/backends/abstract.rb:141:in `tap'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/backends/abstract.rb:74:in `execute'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/capistrano-3.6.0/lib/capistrano/git.rb:10:in `git'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/capistrano-3.6.0/lib/capistrano/git.rb:20:in `check'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/capistrano-3.6.0/lib/capistrano/tasks/git.rake:34:in `block (4 levels) in <top (required)>'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/backends/abstract.rb:93:in `with'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/capistrano-3.6.0/lib/capistrano/tasks/git.rake:33:in `block (3 levels) in <top (required)>'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/backends/abstract.rb:29:in `run'
    /Users/adam/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
    Tasks: TOP => git:check
    The deploy has failed with an error: Exception while executing as deploy@52.206.222.73: git exit status: 128
    git stdout: Nothing written
    git stderr: Nothing written
    ** Invoke deploy:failed (first_time)
    ** Execute deploy:failed

    ** DEPLOY FAILED
    ** Refer to log/capistrano.log for details. Here are the last 20 lines:

     DEBUG [34726536]   -
     DEBUG [34726536]   .
     DEBUG [34726536]   |
     DEBUG [34726536]   /
     DEBUG [34726536]   -
     DEBUG [34726536]   \
     DEBUG [34726536]   .\
     DEBUG [34726536]   .
     DEBUG [34726536]   ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
     DEBUG [34726536] Finished in 1.755 seconds with exit status 0 (successful).
      INFO [2219decf] Running /usr/bin/env mkdir -p /tmp as deploy@52.206.222.73
     DEBUG [2219decf] Command: /usr/bin/env mkdir -p /tmp
      INFO [2219decf] Finished in 0.695 seconds with exit status 0 (successful).
     DEBUG Uploading /tmp/git-ssh-myapp-production-adam.sh 0.0%
      INFO Uploading /tmp/git-ssh-myapp-production-adam.sh 100.0%
      INFO [38c56cdb] Running /usr/bin/env chmod 700 /tmp/git-ssh-myapp-production-adam.sh as deploy@52.206.222.73
     DEBUG [38c56cdb] Command: /usr/bin/env chmod 700 /tmp/git-ssh-myapp-production-adam.sh
      INFO [38c56cdb] Finished in 0.921 seconds with exit status 0 (successful).
      INFO [4ce4f406] Running /usr/bin/env git ls-remote --heads git@example.com:username/amharic-web.git as deploy@52.206.222.73
     DEBUG [4ce4f406] Command: ( export GIT_ASKPASS="/bin/echo" GIT_SSH="/tmp/git-ssh-myapp-production-adam.sh" ; /usr/bin/env git ls-remote --heads git@example.com:username/amharic-web.git )*

【问题讨论】:

  • 您能否检查您是否有从 Capistrano 实例对 EC2 实例的 SSH 访问权限?

标签: ruby-on-rails ssh amazon-ec2 capistrano puma


【解决方案1】:

运行这 2 个命令以通过您的系统授予 git 访问权限

eval ssh-agent
ssh-add ~/.ssh/id_rsa

这些命令假设您在远程 git 服务器上拥有 ssh 密钥(bitbucket/github/other)

【讨论】:

    【解决方案2】:

    我很惊讶没有来自 Git 的更具描述性的错误消息。但是,git ls-remote 命令由于某种原因失败了。在没有任何错误信息的情况下,最好的猜测是 Git 无法访问远程仓库。

    这可能是因为:

    • 您提供的 Git 存储库 URL 不正确(仔细检查没有错别字);或
    • 您的 SSH 代理没有被转发;或
    • 您的 SSH 身份不允许访问指定的存储库

    在您的本地机器上(即您运行 cap 命令的地方),尝试通过 SSH 手动运行相同的 Git 命令,看看会发生什么:

    ssh -A -i ~/.ssh/id_rsa.pub deploy@52.206.222.73 git ls-remote --heads git@example.com:username/amharic-web.git
    

    【讨论】:

    • 回购 URL 有错字。糟糕.... ssh 代理转发也没有设置,如果我早点注意到错字,这可能会造成麻烦。谢谢马特
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多