Skip to content

Instantly share code, notes, and snippets.

@bigtiger
Last active December 2, 2022 00:21
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bigtiger/be41fffcd103d7e98c5fe4fdff0af3f9 to your computer and use it in GitHub Desktop.
Save bigtiger/be41fffcd103d7e98c5fe4fdff0af3f9 to your computer and use it in GitHub Desktop.
How We Deployed Image Processing to Heroku in Support of a Rails 6 Application

How We Deployed Image Processing to Heroku in Support of a Rails 6 Application

Our app was already deployed and working on Heroku with MiniMagick. There were a few features of Image Processing that were appealing, performance and autorotation, and it appeared to be a straightforward swap.

Locally, we had run brew install vips on our MacBooks to get it running. That was early in the process and a detail long forgotten. When I deployed to Heroku @juliancheal pointed out that the staging environment was failing with an ActiveSupport::MessageVerifier::InvalidSignature error.

We were able to quickly identify the missing libvips dependency.

Figuring out how to install libvips to support rubyvips to support Image Processing was not trivial and therefore this guidepost exists.

The heroku/ruby buildpack does not include libvips. In order to add it we need to add a buildpack that includes libvips. There are many to choose from in the Heroku Elements marketplace (over 20 at the time of this writing).

It may be slightly arbitrary but, we chose the buildpack from @brandoncc because it had the most installs/activity.

heroku buildpacks:add --index 1 https://github.com/brandoncc/heroku-buildpack-vips

This buildpack also takes an environment variable to determine which version of libvips to install. We chose the latest version, 8.9.2.

heroku config:set VIPS_VERSION=8.9.2

That turned out to not be enough as libvips now had unmet dependencies. A little digging led to a Github issue thread featuring, unsurprisingly, @schneems.

To install the dependencies we followed @matpowel's suggestion and added another buildpack this time adding apt, a linux package management tool.

heroku buildpacks:add --index 1 heroku-community/apt

Note: Because of the discovery process each of these items were given an index of 1 which placed them at the top of the buildpack order. The Apt buildpack should come first.

Finally, we need to tell apt which libraries to install. We do this by creating an Aptfile in the root of our repository with the following contents:

libglib2.0-0
libglib2.0-dev
libpoppler-glib8
libheif-dev

Hopefully, this helps future readers even if it's just us.

Did we get something wrong? Is there a better way to do this? Let us know: rave@beflagrant.com


Flagrant is a team of software developers intent on making the digital more humane.

@luccastera
Copy link

Thanks @bigtiger!

I had to update the Aptfile to include libheif-dev instead of libheif for this to work.

@bigtiger
Copy link
Author

bigtiger commented Nov 8, 2021

Woohoo! I’m at RubyConf right now (say Hi if you’re around) but I’ll update this when I get back.

@bigtiger
Copy link
Author

bigtiger commented Nov 9, 2021

Updated. 🤘

@creaturenex
Copy link

Was looking for information on how to do this and look who I found! thanks @bigtiger

@creaturenex
Copy link

@bigtiger
Copy link
Author

Nice work @creaturenex!

@aroth
Copy link

aroth commented Oct 15, 2022

@bigtiger Thank you for this!

@bigtiger
Copy link
Author

@aroth Hopefully it helped! 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment