Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble deploying pg due to pg_ext.so #38

Closed
jagthedrummer opened this issue Apr 1, 2021 · 4 comments · Fixed by #42
Closed

Trouble deploying pg due to pg_ext.so #38

jagthedrummer opened this issue Apr 1, 2021 · 4 comments · Fixed by #42
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jagthedrummer
Copy link
Contributor

Describe the bug

I'm trying to follow the example for deploying the pg gem, but I'm not having much luck. I have the gem in my Gemfile and I've activated Docker and have included libpq.so.5 as shown in the example.

When I require 'pg' I get this error:

libldap_r-2.4.so.2: cannot open shared object file: No such file or directory - /opt/ruby/2.7.0/gems/pg-1.2.3/lib/pg_ext.so

In trying to debug the problem I've added some code to show the files in /opt/ruby/2.7.0/gems/pg-1.2.3/lib and pg_ext.so does seem to be there.

Files in /opt/ruby/2.7.0/gems/pg-1.2.3/lib
/opt/ruby/2.7.0/gems/pg-1.2.3/lib/pg
/opt/ruby/2.7.0/gems/pg-1.2.3/lib/pg.rb
/opt/ruby/2.7.0/gems/pg-1.2.3/lib/pg_ext.so

I've also noticed that there seem to be three copies of the file in gemLayer.zip. (Not sure if that matters.)

$ unzip -l .serverless/ruby_layer/gemLayer.zip  | grep pg_ext
   567056  04-01-2021 02:53   ruby/2.7.0/gems/pg-1.2.3/ext/pg_ext.so
   567056  04-01-2021 02:53   ruby/2.7.0/gems/pg-1.2.3/lib/pg_ext.so
   567056  04-01-2021 02:53   ruby/2.7.0/extensions/x86_64-linux/2.7.0/pg-1.2.3/pg_ext.so

Error Stack Trace

Error is just at runtime, not deploy time.

Example Config files

Gemfile:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.2'

gem 'aws-sdk-lambda', '~> 1.62'
gem 'aws-sdk-sqs', '~> 1.37'
gem 'aws-sdk-dynamodb', '~> 1.60'
gem 'aws-sdk-ssm', '~> 1.107'

gem 'pg', '~> 1.1'

gem 'activerecord', '~> 6.1', '>= 6.1.3.1'

gem 'pusher'

serverless.yml:

...
custom:
  rubyLayer:
    use_docker: true
    docker_yums:
      - postgresql-devel
      - postgresql-libs
    native_libs:
      - /usr/lib64/libpq.so.5
...

Desktop (please complete the following information):

  • OS: Mac OS
  • NodeVersion: 15.11.0
  • Ruby version 2.7.2
  • Bundler version 2.1.4

Additional context

None that seems relevant. Happy to provide additional info if there are specifics anyone would like to ask for.

@jagthedrummer jagthedrummer added the bug Something isn't working label Apr 1, 2021
@jagthedrummer
Copy link
Contributor Author

I finally realized I was reading the error backwards. It's not pg_ext.so that was missing, it was libldap_r-2.4.so.2. After much trial and error I ended up getting things to work with this expanded list of native_libs.

custom:
  rubyLayer:
    use_docker: true
    docker_yums:
      - postgresql-devel
    native_libs:
      - /usr/lib64/libpq.so.5
      - /usr/lib64/libldap_r-2.4.so.2
      - /usr/lib64/liblber-2.4.so.2
      - /usr/lib64/libsasl2.so.3
      - /usr/lib64/libssl3.so
      - /usr/lib64/libsmime3.so
      - /usr/lib64/libnss3.so

@navarasu
Copy link
Owner

navarasu commented Apr 3, 2021

Test case failed for this code example. The current example that we have for pg gem is valid for the ruby 2.5 version. Looks like these extra lib dependencies needed only when we are using ruby 2.7

@navarasu
Copy link
Owner

navarasu commented Apr 3, 2021

I have reverted these changes. Please add it in a separate folder as pg deploy for 2.7 example if possible. I will update the docs from my side.

@navarasu
Copy link
Owner

navarasu commented May 3, 2021

@jagthedrummer I have added your pg example for 2.7 separately and updated testcase

navarasu added a commit that referenced this issue May 15, 2021
#38 Added example for pg using ruby2.7 and updated testcases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants