捆绑:在Capistrano中安装失败 - 权限或缺少存储库?

时间:2014-07-08 01:18:34

标签: ruby-on-rails ruby git capistrano

所以我有以下部署文件:

require "bundler/capistrano"

server "siteName.com", :web, :app, :db, primary: true

set :rvm_install_type, :stable
before "deploy", "rvm:install_rvm"

set :rvm_ruby_string, "2.1.0"
before "deploy", "rvm:install_ruby"

require "rvm/capistrano"

set :application, "appName"
set :user, "UserName"
set :deploy_to, "/home/#{user}/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "git@github.com:GitHubUser/GitRepo.git"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup"
after "deploy", "deploy:migrate"
# after "deploy", "deploy:install_gems"
after "deploy", "deploy:sync_data"

namespace :rails do
  task :console, :roles => :app do
    hostname = find_servers_for_task(current_task).first
    exec "ssh -l #{user} #{hostname} -t 'source ~/.rvm/scripts/rvm && cd #{current_path} && bundle exec rails console #{rails_env}'"
  end
end

namespace :deploy do
  desc "Start Application"
  task :start, :roles => :app, except: {no_release: true} do
    run "touch #{current_path}/tmp/restart.txt"
  end

  desc "Stop Application (NOOP)"
  task :stop, :roles => :app, except: {no_release: true} do
  end

  # desc "Install gems"
  # task :install_gems, roles: :app do
  # # This is a rather long command call. We Essentially tell promiscuous to publish and and all tables that need to be.
  #   exec 'bundle install'
  # end

  desc "sync data from this app to any other app listening"
  task :sync_data, roles: :app do
  # This is a rather long command call. We Essentially tell promiscuous to publish and and all tables that need to be.
    exec 'bundle exec promiscuous publish "Xaaron::User.all" && bundle exec promiscuous publish "Xaaron::Role.all" && bundle exec promiscuous publish "Xaaron::Permission.all" && bundle exec promiscuous publish "Xaaron::ApiKey.all"'
  end

  desc "Restart Application"
  task :restart, :roles => :app, except: {no_release: true} do
    run "touch #{current_path}/tmp/restart.txt"
  end

  task :setup_config, roles: :app do
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.yml.sample"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end

  task :setup_secrets_config, roles: :app do
    run "mkdir -p #{shared_path}/config"
    put File.read("config/secrets.yml.sample"), "#{shared_path}/config/secrets.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config", "deploy:setup_secrets_config"

  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end

  task :symlink_secrets_config, roles: :app do
    run "ln -nfs #{shared_path}/config/secrets.yml #{release_path}/config/secrets.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config", "deploy:symlink_secrets_config"

  # desc "Make sure local git is in sync with remote."
   task :check_revision, roles: :web 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
   before "deploy", "deploy:check_revision"
end

我遇到的具体问题是:

 * 2014-07-07 19:06:26 executing `bundle:install'
  * executing "cd /home/UserName/ApplicationName/releases/20140708010625 && bundle install --gemfile /home/UserName/ApplicationName/releases/20140708010625/Gemfile --path /home/UserName/ApplicationName/shared/bundle --deployment --quiet --without development test"
    servers: ["SiteName.com"]
    [SiteName.com] executing command
 ** [out :: SiteName.com] ERROR: Repository not found.
 ** [out :: SiteName.com] fatal: Could not read from remote repository.
 ** [out :: SiteName.com] 
 ** [out :: SiteName.com] Please make sure you have the correct access rights
 ** [out :: SiteName.com] and the repository exists.
 ** [out :: SiteName.com] Retrying git clone 'git@github.com:UserName/Repo.git' "/home/UserName/aisisplatform/shared/bundle/ruby/2.1.0/cache/bundler/git/Xaaron-e125fcc5e1c3bbf107442cab2dd93d453c419fb9" --bare --no-hardlinks --quiet due to error (2/3): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git@github.com:UserName/Repo.git' "/home/UserName/ApplicationName/shared/bundle/ruby/2.1.0/cache/bundler/git/Xaaron-e125fcc5e1c3bbf107442cab2dd93d453c419fb9" --bare --no-hardlinks --quiet` in directory /home/UserName/ApplicationName/releases/20140708010625 has failed.

它会一遍又一遍地做到这一点,直到它最终放弃并退出。所以我想,好吧我没有权限 - 或者我,因为我在我的服务器上使用了两个不同的用户,一个用于部署,一个用于常规服务器维护 - 我做了sudo -i -u UserName并且在那个用户下我已经/home/UserName/ApplicationName/shared/bundle/ruby/2.1.0/cache/并运行git clone ...并且它正好拉下了有问题的存储库。没问题。

然后我决定转到ApplicationName/current/并将有问题的宝石添加到gem文件中并运行bundle install并且它运行正常。它安装了宝石。

那么有没有办法关闭bundle:install所以我可以在服务器上自己做,因为这看起来真的不想工作......

1 个答案:

答案 0 :(得分:1)

不要捆绑:在服务器上安装自己。获得权限并以正确的方式执行。

我假设当你说"我做了sudo -i -u UserName并且在该用户"下,你指的是常规服务器维护'用户。这是对的吗?

如果是这样,看起来您使用DOESN&t进行部署的用户有权访问您的github存储库,但您正在与DOES进行常规服务器维护工作的用户有权限。< / p>

最有可能的是,这意味着在GitHub中,您已经为维护用户添加了SSH密钥,但没有为部署用户添加SSH密钥。转到https://github.com/settings/ssh并检查是否属于这种情况。

要调试此问题,我现在忘记了Capistrano,只是手动以DEPLOY用户身份登录,并尝试执行git clone。一旦你开始工作,Capistrano就应该工作。