You may want to use a gem in your app which is private and stored in a custom Git repository. Note that if this repository is on GitHub, you should follow the page specific to it. Otherwise, if you’re using GitLab, Bitbucket or your own server, you’re at the right place.
The recommended method to achieve this operation is to use the SSH Private Key Buildpack. This page explains how to use this buildpack.
Set the private SSH key in the app environment
The buildpack expects a private key stored in an environment variable named
in base64. It also need the location of the gems you’ll be installing using the
scalingo env-set "SSH_KEY=$(cat private_key | base64 -w 0)" scalingo env-set "SSH_HOSTSemail@example.com"
Obviously, this key should have the permission to clone your private gem repository.
Gemfile: use the SSH URL
The gems you want to checkout should be defined in your
Gemfile with the following syntax:
gem "name-of-gem", git: "firstname.lastname@example.org:namespace/private-gem.git"
Configure the buildpack
To use the private key buildpack, your application should be using the multi buildpack, allowing to chain multiple buildpacks. Chain the private key buildpack, and the ruby buildpack:
$ cat << EOF > .buildpacks https://github.com/Scalingo/ssh-private-key-buildpack.git https://github.com/Scalingo/ruby-buildpack.git EOF
Commit the files and that’s it. At the next deployment your private gem will be downloaded as expected.