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 :)..
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.
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.
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.
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...
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With