heroku上的bitbucket私有存储库

我有一个需要gem的rails应用程序。 我在bitbucket上将这个gem托管在私有存储库中。

在我的Gemfile中,我添加了以下gem:

gem "my-gem", :git => "git@bitbucket.org:my-username/my-gem.git", :branch => 'master' 

我想在heroku上部署我的rails应用程序

 git push heroku master 

现在我总是得到以下错误

 Fetching git@bitbucket.org:my-username/my-git-repo.git Host key verification failed. fatal: The remote end hung up unexpectedly 

我理解错误,因为存储库设置为私有。 但是我该如何解决这个问题呢?

我已经读过这个问题: 在bitbucket上使用git部署到Heroku ,但我没有真正得到答案:) ..

Bitbucket允许在类似于github的存储库URL上进行HTTP基本身份validation。 将gem的URL指定为https://username:password@bitbucket.org/username/gemrepo.git

确实意味着在你的Gemfile中拥有你的用户名和密码,它本身就是版本控制的,这不是一个好习惯,但另一方面,这是Heroku推荐的,所以……

我有同样的问题,但我最终做了以下作为在Gemfile提供Bitbucket密码的解决方法。

基本的想法是将Bitbucket中的gem克隆到本地目录中,将其添加到您的应用程序并将其打包到vendor/cache以便Heroku可以使用它。 我的确切步骤如下:

  1. 将您的gem克隆到本地目录:

    git clone git@bitbucket.org:me/my_private_gem.git /home/me/my_private_gem

  2. 将gem添加到Gemfile作为’假’Bitbucket repo:

    gem 'my_private_gem', :git => 'git@bitbucket.org:me/my_private_gem.git', :branch => 'master' # this repo will not be used

  3. 配置Bundler以对照本地存储库(在步骤1中克隆gem的位置):

    bundle config local.my_private_gem /home/me/my_private_gem

  4. 像往常一样运行bundle install ,你应该看到这样的东西:

    使用git@bitbucket.org中的my_private_gem(0.0.1):me / my_private_gem.git(at / home / me / my_private_gem)

  5. 将所有gem打包到/vendor

    bundle package --all

  6. 添加/vendor到您的仓库

    git add vendor && git commit -m 'add my_private_gem to /vendor/cache'

  7. 推送到Heroku(不要忘记先提交更新的GemfileGemfile.lock ),你应该看到如下内容:

    使用来自git://github.com/my_private_gem/my_private_gem.git的my_private_gem(0.0.1)(在/ tmp / build_19fmj3tup0zy2 / vendor / cache / my_private_gem-8bc6f436e2c8)

参考文献:

  • Bundler – 本地Git Repos
  • Bundler – 包

实现此目的的正确方法是使用bundle config ,它将配置保存在主目录.bundle/config ,使其保持在repo之外。

bundle config bitbucket.org user:pwd

然后在Heroku上,你必须以一种特殊的方式设置一个简单的配置 :

heroku config:set BUNDLE_BITBUCKET__ORG=user:pwd

在您的Gemfile中,您只需使用没有凭据的URL。

gem 'gemname', git: "https://bitbucket.org/User/gemname.git"

我建议使用ENV vars而不是像以下新用户:

https://#{ENV['BITBUCKET_USER']}:#{ENV['BITBUCKET_PWD']}....

然后使用以下设置:

heroku config:add BITBUCKET_X=value

对于您的开发环境,您可以使用dotenv gem来定义凭据。

另请参阅: 如何指定从私有github存储库中提取的gem?