Search code examples
rubyrubygemsbundlercredentialsbuildpack

Buildpacks Pack: Passing Bundler Config to the Buildpack


I'm trying to build my solutions using the Buildpacks Pack tool as a CLI and using the "buildpacks:18" image to create the builder.

Everything works fine except for the Ruby one, since one of my applications is using a private gem repository.

Normally, doing bundle config $address "$user:$token"(replacing every $ for actual values) the build process would work locally, without Buildpacks. Normal Ruby stuff.

However, when using the Buildpack Builder/Image it just won't read the config on my local machine and keeps returning:

Bundler Output: Authentication is required for rubygems.pkg.github.com.
       Please supply credentials for this source. You can do this by running:
        bundle config set rubygems.pkg.github.com username:password

 !
 !     Failed to install gems via Bundler.

So I'm guessing it should be passed to the Buildpack image. Is that the best practice? If so... how? Because the Buildpacks documentation is heavy on Heroku usage but not that much when using the Pack tool, which is an abstraction.

I've thought of and searched for ways of doing it with variables or by mapping my local file (which then would be less practical on an abstracted CI/CD pipeline) but still I'm unable to get a clear answer regarding this and hardcoding the creds on the gemfile is a big no-no (following best practices). I'm trying to avoid doing a "custom image" because it feels like an overkill, so maybe there is a way that I'm missing completely.

Thanks in advance for any help.


Solution

  • You'll need to run pack build with an environment variable in the form BUNDLE_GEMS__<HOST>__<TLD>=<user>:<token> using the -e flag. For example:

    pack build -e BUNDLE_GEMS__EXAMPLE__COM=itme:xxx myapp
    

    For more information see the Heroku guide to bundler configuration (which still applies when using pack for the most part)