Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bitbucket private repository on heroku

I have a rails app which requires a gem. I host this gem on bitbucket in a private repository.

In my Gemfile I added the gem like following:

gem "my-gem", :git => "[email protected]:my-username/my-gem.git", :branch => 'master'

I want to deploy my rails app on heroku with

git push heroku master

Now I always get following error

Fetching [email protected]:my-username/my-git-repo.git
Host key verification failed.
fatal: The remote end hung up unexpectedly

I understand the error, because the repository is set to private. But how can I solve this problem?

I already read this question: Deploying to Heroku using git on bitbucket, but I don´t really get the answer :)..

like image 710
Matthias Avatar asked Aug 08 '13 13:08

Matthias


People also ask

How do I make my repository private in bitbucket?

From the repository, click Repository settings in the sidebar. Locate Access level on the Repository details page. Add or remove the checkmark from This is a private repository based on your preferred privacy status. Click Save repository details.

How do I deploy Heroku with an existing Git repository?

You simply add your Heroku app as a remote to an existing Git repository, then use git push to send your code to Heroku. Heroku then automatically builds your application and creates a new release.

How do I host a GitHub repo on Heroku?

To deploy your app to Heroku, use the git push command to push the code from your local repository's main branch to your heroku remote. For example: $ git push heroku main Initializing repository, done.


2 Answers

Bitbucket allows for HTTP basic auth on repository URLs similar to github. Specify the URL for the gem as https://username:[email protected]/username/gemrepo.git.

It does mean having your username and password in your Gemfile, which itself is version controlled, and that's not a good practice, but on the other hand that's what Heroku recommends, so...

like image 183
Nitzan Shaked Avatar answered Oct 15 '22 21:10

Nitzan Shaked


The proper way to achieve this is using bundle config, which saves the configuration on your home directory .bundle/config so it stays outside the repo.

bundle config bitbucket.org user:pwd

And then on Heroku you have to set a simple configuration in a special way:

heroku config:set BUNDLE_BITBUCKET__ORG=user:pwd

And in your Gemfile you just use the URL without the credentials.

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

like image 28
Zequez Avatar answered Oct 15 '22 22:10

Zequez