2

I have a rails app that uses the RGeo gem and I'm having a hard time getting the gem to install with support for the underlying GEOS library which my app requires to work properly.

Typically you can run RGeo::Geos.supported? from the rails console and it will return true if GEOS is supported, false otherwise. This works on my devel machine (OS X) but always returns false on my Dokku container.

I am using build packs to pull these libraries in, here is the contents of my .buildpack file:

https://github.com/cyberdelia/heroku-geo-buildpack.git#1.3
https://github.com/heroku/heroku-buildpack-ruby.git#v141

This does seem to at least partially work since the gem is picking up the PROJ.4 library. This can be checked by running RGeo::CoordSys::Proj4.supported? in the rails console, which returns true on my Dokku deployment.

When I deploy the app the build pack appears to be working without any issues:

-----> Cleaning up...
-----> Building demoapp from herokuish...
-----> Adding BUILD_ENV to build environment...
-----> Multipack app detected
=====> Downloading Buildpack: https://github.com/cyberdelia/heroku-geo-buildpack.git
=====> Detected Framework: geos/gdal/proj
   Using geos version: 3.4.2
   Using gdal version: 1.11.1
   Using proj version: 4.8.0_1
-----> Vendoring geo libraries done
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-ruby.git
=====> Detected Framework: Ruby
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.2.3
-----> Installing dependencies using bundler 1.9.7
   Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment

I am using the latest version of Dokku (0.4.10) and the app is currently running on Ruby 2.2.3, Rails 4.2.5.

Edit (for clarification): I need this method call (RGeo::Geos.supported?) to return true in the rails console in my app container. Only then will my app work correctly, currently it is returning false which means that the RGeo gem did not find the GEOS (libgeos) library during installation. There are no errors during the deployment and the log output (relevant section included above) reports that GEOS 3.4.2 is installed via the buildpack. Without GEOS support I'm unable to even seed my database since part of that process involves reading in shapfiles and storing them as geometries via PostGIS. My app also uses many other features that require GEOS via RGeo so it is a requirement that RGeo::Geos.supported? returns true in the console, meaning that GEOS is available via the RGeo gem and features like reading in shapefiles, etc will work.

sethdeckard
  • 499
  • 11
  • 24
  • RGeo need some additional packages like libgeos. Have you installed it? – Oleh Sobchuk Jan 10 '16 at 17:59
  • I realize this and that is the problem at hand. BTW, libgeos is the same thing as the GEOS library mentioned in my question. If you read the question again you'll notice that the buildpack does install GEOS, which you can also see in the output of the deployment: Using geos version: 3.4.2. So I'm trying to figure out what is going wrong with this process or if there is a work around to using the geo buildpack with Dokku. – sethdeckard Jan 10 '16 at 18:42
  • Just to provide some more background: this is the first time I have used Dokku and by extension Docker. I know how to get this working on a single server installing all the required libraries via the system's package manager. The question is how to get it working in Dokku where a new Docker container is being created each time you deploy. – sethdeckard Jan 10 '16 at 22:48
  • Where exactly are you seeing errors? I don't see any errors in that logging output, and you haven't shown how this *isn't* working. – Jose Diaz-Gonzalez Jan 11 '16 at 12:34
  • @JoseDiaz-Gonzalez, yes I have... see above where I state that RGeo::Geos.supported? returns false in the console. This would return true if gem was able to find the geos library during installation. – sethdeckard Jan 11 '16 at 14:42
  • @JoseDiaz-Gonzalez, I've added a summary at the bottom of the question, hope that clears things up a bit. You are right there are no errors in the logging output, that's why it's hard to figure out what is going wrong during the deployment. The RGeo gem does silently fail if it can't find GEOS but that is by their design since only parts of the gem use and require that library. – sethdeckard Jan 11 '16 at 14:59
  • Ah okay. Question: what happens if you try and deploy to heroku? What is the difference between the two `supported?` calls? – Jose Diaz-Gonzalez Jan 12 '16 at 13:30
  • I just setup a deployment to Heroku and the library reports the same, false for RGeo::Geos.supported? and true for RGeo::CoordSys::Proj4.supported? So I guess that narrows it down to the geo buildpack itself. Is there any alternative to using this buildpack? I just need to have these native libraries installed in a standard location before the rgeo gem is installed. – sethdeckard Jan 12 '16 at 16:23
  • You can try using the dokku-apt plugin to install packages into your buildpack. It's linked to in our documentation :) – Jose Diaz-Gonzalez Jan 13 '16 at 01:48
  • Nice, I didn't see that plugin but I was able to get it working using it. I'll post the full solution and give you credit, thanks. – sethdeckard Jan 13 '16 at 15:32
  • I actually like this solution a lot better because it makes things more clear. The .buildpack file pointing the geo buildpack doesn't really describe what is being installed unless you go look at that repo on Github. With the apt-packages file you simply have a list of the libraries you actually need and it's really self-explanatory. Thanks again. – sethdeckard Jan 13 '16 at 15:52

1 Answers1

0

As pointed out by Jose in the comments you can use the apt-get plugin to install packages into your container during deployment. This allows you to bypass the current problems with the geo buildpack completely.

After installing the plugin to my Dokku instance, I created an apt-packages file in the root of my project with the following contents:

libgeos-dev
libgeos++-dev
libgdal-dev
libproj-dev

I removed the geo buildpack (https://github.com/cyberdelia/heroku-geo-buildpack.git#1.3) from my .buildpacks file since that is no longer being used. It's now possible to just get rid of the .buildpacks file altogether and simply create a BUILDPACK_URL environment variable dokku config:set pointing to the ruby buildpack repo.

After deploying, the RGeo gem now reports GEOS is available since it was now able to build the native extensions during installation:

irb(main):001:0> RGeo::Geos.supported?
=> true

PROJ.4 still works as well, since I included the library in the apt-packages file:

irb(main):002:0> RGeo::CoordSys::Proj4.supported?
=> true
sethdeckard
  • 499
  • 11
  • 24
  • Hi @sethdeckard, I'm stuck with the same kind of issue. I try your solution but I'm not sure to well understand the part about adding dokku config. In fact my interrogation is about the url to use for BUILDPACK_URL – Denis Morin Jul 21 '21 at 20:15
  • @DenisMorin I've since migrated this app to k8s, using just Docker containers which gives you complete control over what exactly is installed. If possible, I would try to go that route if you can as it will save a lot of headaches (and create new ones :)). It looks like the original "build pack" is no longer supported (that was more of a Heroku thing at that time, supported by Dokku as well). I believe even Heroku supports straight up Docker deploys these days. – sethdeckard Jul 22 '21 at 23:16