Upgrading Bundler Version on Heroku - ruby-on-rails

I need an updated version of bundler on my heroku application (cedar 14) and I haven't seen any reason why I can't do this. I'm stuck at 1.6.6 which is a couple months old and I need the most up to date version.
I need to specify a source: option for one of my gems and the older version of bundler doesn't allow this. Additionally, running heroku run gem update bundler successfully updates but 'heroku run bundle -v' yields 1.6.6.
Why?

You can modify the bundler version used by specifying the Ruby Buildpack on Heroku:
If you see that a different version of Bundler is being used by your
application than is listed in the Ruby Support article, your
application might be configured to use the master branch of the Ruby
buildpack for deployments.
To check which buildpack is configured, use the heroku buildpacks
command:
> heroku buildpacks
> === hidden-temple-25627 Buildpack URL https://github.com/heroku/heroku-buildpack-ruby.git
The example output shows that an unreleased version of the buildpack
is being used. To switch to the supported version, set the buildpack
as follows:
heroku buildpacks:set heroku/ruby Buildpack set. Next release on
hidden-temple-25627 will use heroku/ruby. Run git push heroku master
to create a new release using this buildpack.
You can verify that the new buildpack has been set by typing:
> heroku buildpacks
> === hidden-temple-25627 Buildpack URL heroku/ruby
Another reason your app might not be using the currently supported
Bundler version is if it is configured to deploy using a different
buildpack URL. This will happen if the BUILDPACK_URL config var is
set.
> heroku config:get BUILDPACK_URL BUILDPACK_URL:
> https://github.com/heroku/heroku-buildpack-ruby.git
If you see any value, then you are using a custom buildpack. If this
value is set to a “multi buildpack” such as
https://github.com/heroku/heroku-buildpack-multi then you will need to
check the .buildpacks file to see what buildpacks are used in
deployment. If you are using this method of deployment we recommend
that you instead follow the guidance in the Using Multiple Buildpacks
for an App article.
The officially deployed Ruby buildpack will sometimes lag behind
master for a few days.
Other than that it can not be directly configured:
Why can’t the Bundler version be configured?
Different versions of Bundler have different known bugs and slightly
different behavior. The Bundler version on Heroku is carefully
curated. A balance needs to be struck between supporting new Bundler
features and stability. The work we put into curating the Bundler
version ensures maximum stability, and avoids deprecation and
notification cycles on Bundler as it changes, or as bugs are fixed or
security issues are patched by Heroku.
The Ruby experience on Heroku is provided by the Heroku Ruby
Buildpack. This is the tool that installs a version of Bundler and
runs all the commands needed to get your application set up. The
buildpack relies on publicly exposed internals of Bundler. It is
tested and known to work against the currently specified version of
Bundler. If you were to take a modern buildpack and use it with an
older version of bundler, you would be likely to see unpredictable
results.
https://devcenter.heroku.com/articles/bundler-version

Related

Rails + Docker - How use Heroku stack image but update the Ruby version?

While doing local Rails 6 development, via Docker, using the latest Heroku stack image as the starting point (FROM heroku/heroku:20-build), what does a Dockerfile need in order to replace the 'old' version of ruby in the stack image with a newer version from a Heroku ruby buildpack?
For Dockerized Rails development, starting with a Heroku stack image seem like the right way to maintain dev/prod parity to minimize those hard to debug "it worked locally then broke on Heroku" issues.
However, even the latest version of a Heroku stack image (20-build) does not include the current "default" version of ruby (2.7.3 at the moment)... even worse what it comes with is 2.7.0 and avoiding any ".0" version is generally wise.
Looking at the github pages for Heroku's buildpack (https://github.com/heroku/heroku-buildpack-ruby) I see no clues how the buildpack can be used to install a newer version of Ruby to a Dockerfile.
I know from an article I found online that Heroku has Ruby 2.7.3 available at https://heroku-buildpack-ruby.s3.amazonaws.com/heroku-18/ruby-2.7.3.tgz
However I cannot see how in the Dockerfile to replace the existing 2.7.0 with that version 2.7.3 without breaking everything.
On older Heroku stacks and buildpacks you could do something like this:
apt remove -y --purge ruby && curl -s --retry 3 -L https://heroku-buildpack-ruby.s3.amazonaws.com/heroku-18/ruby-2.7.3.tgz | tar -xz
but doing this with heroku/heroku:20-build does not successfully install the new version of ruby in the right path and it breaks rubygems so that a simple gem list throws an error (undefined method rubyforge_project=' for class Gem::Specification' (NameError))
(I considered but dislike the idea of installing some ruby version manager like rbenv in the app's Dockerfile... the app only needs one version of ruby, and it introduces another pointless dependency, so hopefully there is a reasonable way to simply upgrade ruby in the image)

Rails bundle error when pushing to Elastic Beanstalk

I had an app deployed on Heroku and I am currently trying to create the same app on AWS.
I've copied my folder, created a complete separated repo on Github and installed ebcli, the setup looks fine.
When I try to run eb deploy, I have this error:
[Instance: i-03051e2a022886184] Command failed on instance. Return code: 1 Output: (TRUNCATED)...:in find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems.rb:308:inactivate_bin_path'
from /opt/rubies/ruby-2.5.3/bin/bundle:23:in `'.
I've looked online and it says it comes from incompatibility between your gemlock file bundler version and actual bundler version.
I've tried to change my bundler version to this one, but I gave up and came back to 2.0.1 because I had to install too many dependencies otherwise.
I removed the gemlock, bundle again, but I still got the same error when trying to deploy.
With my heroku version, it always worked.
Any idea how to solve that?
Thanks a lot
We moved from Heroku to AWS a few months back as well and it will likely take some some custom scripting to get things to work.
It would help to know more about your EB environment, but I am assuming you are using Ruby 2.5 with Puma on Amazon Linux 2.9.0 (?)
Not sure what bundle version comes with that, But I don’t think it’s 2.x. so you have to add an .ebextensions file too install your preferred bundled version.
# .ebextensions/01_install_bundler.config
container_commands:
install_bundler:
command: “gem install bundler —-version 2.0.0”
More info on AWS Linux customizations
End of the day, we are much happier with our AWS environment (lower cost, better performance), but requires more work to get it set up
Actually the problem exists because the bundler version in the eb env is older than the one being used in the project source.
So the solution is to use a bundler version less or equal the eb env installed version.
First uninstalled the current bundler:
gem uninstall bundle
and then install the desired one:
gem install bundler -v 1.16.6
See more details

Heroku/Rails: How to install the GNU Scientific Library (GSL) on Heroku?

I need to install the GSL library on Heroku running a Rails (4.0.2) app to use some gems that depend on it.
Goal:
Install the GSL library to work with GSL and Similarity gems in Heroku.
Tried approaches:
Installing Ruby / GSL in Heroku Application: Heroku crashes after deploy. GSL gem is unable to find the lib. Trace: http://pastebin.com/CPcMUdCa
Tomwolfe's Heroku's Ruby buildpack adapted for using couchbase: Same issue.
Building Dependency Binaries for Heroku Applications: Vulcan is deprecated. More info on Heroku's Devcenter and on Github
I've tried following these steps (compiling binaries):
GSL 1.15 downloaded from ftp://ftp.gnu.org/gnu/gsl/gsl-1.15.tar.gz
Uncompressed and cd gsl-1.15
./configure
make clean
make
sudo make install
It works on my local environment but not in Heroku. Heroku doesn't allow sudo but it allows access with heroku run. The problem is that the file system is ephemeral and the dyno will only live as long as your console session.
Update:
I've also tried building my own Heroku Buildpack but I couldn't make it work. I tried using multipacks. I'm not a Heroku Buildpack expert so maybe it's the problem, I'm learning more about it to make a simple repository with an example and an extended explanation of this issue.
I had to use gsl1.16 on heroku and here is how I solved it:
First added gsl1.16 buildpack to the lists of buildpacks like
heroku buildpacks:add --index:3 git://github.com/gregory/heroku-gsl-buildpack.git#gsl-1.16
Which adds to my list of buildpacks, in my case got nodejs and ruby already. Hence --index=3
Then had to set LD_LIBRARY_PATH on heroku like
heroku config:set LD_LIBRARY_PATH=/app/vendor/gsl/lib
which points to 1.16. Seen around that some people use /app/vendor/gsl1/lib but wasn't my case.
and that's it.
I made a heroku buildpack a couple months ago for 1.15 and 1.16
just do:
heroku buildpacks:set git://github.com/gregory/heroku-gsl-buildpack.git#gsl-1.16
or
heroku buildpacks:set git://github.com/gregory/heroku-gsl-buildpack.git#gsl-1.15
You'll need to use a custom buildpack. Buildpacks allow you to define any additional dependencies outside of your project and package them with your slug which is used by the dynos. The buildpack you linked to (https://github.com/tomwolfe/heroku-buildpack-gsl-ruby) would be your best bet in getting everything working. I would open issues on their github repo if you are having issues, hopefully they can help you out

When does Heroku update its gems?

I know that my local machine and Heroku are using the same version of the gem, but I'm wondering if it's possible that Heroku hasn't grabbed the latest bug fix tracked here.
Is it possible that my local machine has a newer delayed_job 3.0.0 gem than Heroku does? The fix was committed on the 12th.
When does Heroku update its gems?
This seems likely because I can send email from my local rails app, but on Heroku, I run into problems detailed in the link above. I'm on the bamboo-mri-1.9.2 stack btw.
It short, it doesn't. If you're using Bundler you're stipulating which versions are used in your Gemfile (which in turn defines version numbers in your Gemfile.lock, both of which should be committed to Git).
If you're not using Bundler, and are still using the .gems file at the root of your project, Heroku will use the most recent it has, unless you define a different version in which case it will use that.
More info can be found here: http://devcenter.heroku.com/articles/gems
You should be able to specify a git repository in your Gemfile.
e.g.,
gem "delayed_job", :git => "git://github.com/collectiveidea/delayed_job.git", :ref => "80ca31f9eb"
using the commit with the fix.
(edit: wrong git repo, whoops.)

Reducing slug size on the Heroku Bamboo stack

I have seen a number of questions and answers on how to reduce your Heroku slug size but I can't get it to budge. In How to reduce heroku slug size? it is mentioned that there is a bug in Bundler that means that unused gems are not cleaned out.
One of the comments on that question says:
Note that this issue has now been fixed with Bundler. Opening a support ticket is no longer necessary
I have a few questions:
Does this mean that an updated version of Bundler is now used on the
Heroku Bamboo stack with this fix in it?
Do I have any control over which version of Bundler is being used by Heroku?
Is Heroku running on a newer version of Bundler then the "release" version?
Does this mean that an updated version of Bundler is now used on the Heroku Bamboo stack with this fix in it?
No, as far as I am aware the Bundler has not changed on Bamboo
Do I have any control over which version of Bundler is being used by Heroku?
No
Is Heroku running on a newer version of Bundler then the "release" version?
Sometimes, for instance, at the moment they are running a Bundler rc on Cedar.
For reducing slug size, check the Dev Center article: http://devcenter.heroku.com/articles/slug-size
You may be experiencing the same problem reported in this blog post from a few months ago - http://dazedthots.blogspot.com/2011/07/reducing-slug-size-heroku.html

Resources