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
Bitbucket allows for HTTP basic auth on repository URLs similar to github. Specify the URL for the gem as https://username:password@bitbucket.org/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...
I would suggest to use ENV vars instead of a new user like:
https://#{ENV['BITBUCKET_USER']}:#{ENV['BITBUCKET_PWD']}....
Then set them using:
heroku config:add BITBUCKET_X=value
For your development environment you can use the dotenv gem to define the credentials.
See also: How can I specify a gem to pull from a private github repository?
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"
I had the same problem, but I ended up doing the following as a workaround to providing the Bitbucket password in the Gemfile
.
The basic idea is to clone the gem from Bitbucket into a local directory, add it to your app and package it into vendor/cache
so Heroku can use it. My exact steps are below:
Clone your gem to a local directory:
git clone git@bitbucket.org:me/my_private_gem.git /home/me/my_private_gem
Add the gem to your Gemfile
as a 'fake' Bitbucket repo:
gem 'my_private_gem', :git => 'git@bitbucket.org:me/my_private_gem.git', :branch => 'master' # this repo will not be used
Configure Bundler to work against the local repository (where you cloned the gem in step 1):
bundle config local.my_private_gem /home/me/my_private_gem
Run bundle install
as usual, you should see something like this:
Using my_private_gem (0.0.1) from git@bitbucket.org:me/my_private_gem.git (at /home/me/my_private_gem)
Package all your gems into /vendor
bundle package --all
Add /vendor
to your repo
git add vendor && git commit -m 'add my_private_gem to /vendor/cache'
Push to Heroku (don't forget to commit your updated Gemfile
and Gemfile.lock
first), you should see something like the following:
Using my_private_gem (0.0.1) from git://github.com/my_private_gem/my_private_gem.git (at /tmp/build_19fmj3tup0zy2/vendor/cache/my_private_gem-8bc6f436e2c8)
References: