部署(私人仓库)

时间:2016-02-07 17:54:02

标签: ruby-on-rails git github capistrano digital-ocean

我正在尝试将我的Ruby on Rails应用程序部署到Digital Ocean上托管的生产服务器上。将我的存储库设置为“Public”时没有问题,但是当我在“Private”上设置我的存储库时我得到了“致命:身份验证失败”错误:

SSHKit::Runner::ExecuteError: Exception while executing on host 178.62.16.69: git exit status: 128
git stdout: remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/ryzalyusoff/xxxxxx.git/'
git stderr: Nothing written

SSHKit::Command::Failed: git exit status: 128
git stdout: remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/ryzalyusoff/xxxxxx.git/'
git stderr: Nothing written

Tasks: TOP => git:check
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host 178.62.16.69: git exit status: 128
git stdout: remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/ryzalyusoff/xxxxxx.git/'
git stderr: Nothing written

enter image description here

那么,我该怎么办才能部署到我的生产服务器而无需在“公共”上设置我的回购?

谢谢!

------------------------- 更新1 ------------- ---------------

我已经生成了公钥并将其放在我的github帐户上。我通过使用以下命令对其进行了测试证实了这一点:

ssh -T git@github.com

enter image description here

------------------------- 更新2 ------------- ---------------

我已将 set:repo_url 更改为ssh,但错误仍然存​​在。这是我的 deploy.rb文件

# Change these
server '178.62.16.69', port: 22, roles: [:web, :app, :db], primary: true

set :repo_url,        'git@github.com:ryzalyusoff/xxxxxx.git'
set :application,     'xxxxxx'
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,             false
set :use_sudo,        false
set :stage,           :production
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/#{fetch(:user)}/apps/#{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

set :whenever_identifier, ->{ "myapp_#{fetch(:stage)}" }

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

  before :start, :make_dirs
end

namespace :deploy do
  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) do
      unless `git rev-parse HEAD` == `git rev-parse origin/master`
        puts "WARNING: HEAD is not the same as origin/master"
        puts "Run `git push` to sync changes."
        exit
      end
    end
  end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart', 'puma:start'
      invoke 'deploy'
    end
  end

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:restart'
    end
  end

  before :starting,     :check_revision
  after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :restart

end

错误

enter image description here

2 个答案:

答案 0 :(得分:1)

Capistrano假设您将通过SSH密钥转发向Git进行身份验证。这意味着您在本地计算机上使用的密钥将是您执行cap deploy时服务器使用的密钥。

当然,只有在使用SSH连接到Git时才会有效。根据您的错误消息,看起来您不是。您好像使用https:网址而不是SSH网址。

将您的:repo_url更改为SSH风格,您应该做得很好。

E.g。

set :repo_url, "git@github.com:ryzalyusoff/xxxxxx.git"

答案 1 :(得分:0)

您需要创建一个ssh密钥并使用您的公钥提供github。

$ssh-keygen -t rsa

将文本* .pub复制到剪贴板并将其添加到您的github帐户。