Home > Enterprise >  Minimal `Gemfile/Gemfile.lock` for Heroku environment
Minimal `Gemfile/Gemfile.lock` for Heroku environment

Time:11-02

I’m updating the environment on Heroku and one of the buildpack we use is based on Ruby, which is no longer available by default in the new heroku-22 environment/stack (nor required by our PHP app).

From the docs:

[...] end users should add the Ruby buildpack prior to the buildpack in question (they will also need to ensure minimal Gemfile / Gemfile.lock files exist, so that the Ruby buildpack passes detection).

However I have no clue what those files should include as I have zero experience with Ruby. What would be a valid set of minimal Gemfiles to trigger Ruby installation on Heroku?

CodePudding user response:

I suggest you don't use that buildpack at all. It's ancient, and third-party buildpacks are always a bit questionable, even if it's just because they often stop getting updated.

Here's what it claims to do:

This is a Heroku buildpack for vendoring just the mysql binary from the mysql-client-core deb package.

If you just need a mysql binary, you can use the apt buildpack to install it without worrying about Ruby or anything like that.

  1. Add it as your first buildpack:

    heroku buildpacks:add --index 1 heroku-community/apt
    
  2. Create an Aptfile in the root directory of your project that lists the Ubuntu packages you wish to install, e.g.

    mysql-client-core-8.0
    

    Note that the buildpack does not do dependency resolution. If any packages you list have their own dependencies you may have to list them explicitly.

  3. Commit, and redeploy.

You should see the Ubuntu packages you listed get installed before your main buildpack runs.


In any case, if you really want to make your application compatible with the Ruby buildpack you should be able to simply include an empty Gemfile in the root of your project:

The Heroku Ruby Support will be applied to applications only when the application has a Gemfile in the root directory. Even if an application has no gem dependencies it should include an empty Gemfile to document that your app has no gem dependencies.

A Gemfile.lock is not required.

Note that you'll need to manually add the buildpacks you require. I believe you'll want Ruby first, then the MySQL buildpack in your question, then whatever language your application is written in, which appears to be PHP:

heroku buildpacks:set heroku/php  # Main buildpack; we insert others before it below
heroku buildpacks:add --index 1 heroku/ruby
heroku buildpacks:add --index 2 https://github.com/thoughtbot/heroku-buildpack-mysql.git
heroku buildpacks
# => Should print the buildpacks in the expected order

CodePudding user response:

It looks like an empty Gemfile is not enough and a Gemfile.lock is actually required as well:

The buildpack will detect your app as Ruby if it has a Gemfile and Gemfile.lock files in the root directory.

After some trial and error I figure out the following files seem to work:

# Gemfile
source 'https://rubygems.org'
# Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  ruby

DEPENDENCIES

BUNDLED WITH
   1.17.3
  • Related