Ruby on Rails API: error occurred while installing pg (1.4.1)

0

Attempting to deploy this Rails API and keep sticking when EB goes to install the PG gem.

So far I have tried:

  • Removing the specific gem requirement
gem "pg"
-instead of-
gem "pg", "~> 1.4.1"
  • Zipping my deployment w/ and wo/ a gemfile.lock

Unfortunately that's about as far as I got as googling only turned up threads that seem to be very aged:

The last link has a sudo command that I didn't attempt as Im not even sure where, and tend to be weary of running sudo commands w/o understanding what I'm commanding the sudo to do.

Ruby Version: 3.0.4 Rails Version: 7.0.3

GEMFILE:

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

ruby "3.0.4"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.3"

# Use postgresql as the database for Active Record
gem "pg", "~> 1.4.1"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
# gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem "rack-cors"

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
end

gem 'pry', '~> 0.13.1'
gem 'dotenv-rails', groups: [:development, :test]
gem 'solargraph', group: :development

GEMFILE.LOCK:

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (7.0.3)
      actionpack (= 7.0.3)
      activesupport (= 7.0.3)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailbox (7.0.3)
      actionpack (= 7.0.3)
      activejob (= 7.0.3)
      activerecord (= 7.0.3)
      activestorage (= 7.0.3)
      activesupport (= 7.0.3)
      mail (>= 2.7.1)
      net-imap
      net-pop
      net-smtp
    actionmailer (7.0.3)
      actionpack (= 7.0.3)
      actionview (= 7.0.3)
      activejob (= 7.0.3)
      activesupport (= 7.0.3)
      mail (~> 2.5, >= 2.5.4)
      net-imap
      net-pop
      net-smtp
      rails-dom-testing (~> 2.0)
    actionpack (7.0.3)
      actionview (= 7.0.3)
      activesupport (= 7.0.3)
      rack (~> 2.0, >= 2.2.0)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.2.0)
    actiontext (7.0.3)
      actionpack (= 7.0.3)
      activerecord (= 7.0.3)
      activestorage (= 7.0.3)
      activesupport (= 7.0.3)
      globalid (>= 0.6.0)
      nokogiri (>= 1.8.5)
    actionview (7.0.3)
      activesupport (= 7.0.3)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.1, >= 1.2.0)
    activejob (7.0.3)
      activesupport (= 7.0.3)
      globalid (>= 0.3.6)
    activemodel (7.0.3)
      activesupport (= 7.0.3)
    activerecord (7.0.3)
      activemodel (= 7.0.3)
      activesupport (= 7.0.3)
    activestorage (7.0.3)
      actionpack (= 7.0.3)
      activejob (= 7.0.3)
      activerecord (= 7.0.3)
      activesupport (= 7.0.3)
      marcel (~> 1.0)
      mini_mime (>= 1.1.0)
    activesupport (7.0.3)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 1.6, < 2)
      minitest (>= 5.1)
      tzinfo (~> 2.0)
    ast (2.4.2)
    backport (1.2.0)
    benchmark (0.2.0)
    bootsnap (1.12.0)
      msgpack (~> 1.2)
    builder (3.2.4)
    coderay (1.1.3)
    concurrent-ruby (1.1.10)
    crass (1.0.6)
    debug (1.5.0)
      irb (>= 1.3.6)
      reline (>= 0.2.7)
    diff-lcs (1.5.0)
    digest (3.1.0)
    dotenv (2.7.6)
    dotenv-rails (2.7.6)
      dotenv (= 2.7.6)
      railties (>= 3.2)
    e2mmap (0.1.0)
    erubi (1.10.0)
    globalid (1.0.0)
      activesupport (>= 5.0)
    i18n (1.10.0)
      concurrent-ruby (~> 1.0)
    io-console (0.5.11)
    irb (1.4.1)
      reline (>= 0.3.0)
    jaro_winkler (1.5.4)
    json (2.6.2)
    kramdown (2.4.0)
      rexml
    kramdown-parser-gfm (1.1.0)
      kramdown (~> 2.0)
    loofah (2.18.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    marcel (1.0.2)
    method_source (1.0.0)
    mini_mime (1.1.2)
    mini_portile2 (2.8.0)
    minitest (5.16.2)
    msgpack (1.5.3)
    net-imap (0.2.3)
      digest
      net-protocol
      strscan
    net-pop (0.1.1)
      digest
      net-protocol
      timeout
    net-protocol (0.1.3)
      timeout
    net-smtp (0.3.1)
      digest
      net-protocol
      timeout
    nio4r (2.5.8)
    nokogiri (1.13.6)
      mini_portile2 (~> 2.8.0)
      racc (~> 1.4)
    nokogiri (1.13.6-x86_64-darwin)
      racc (~> 1.4)
    nokogiri (1.13.6-x86_64-linux)
      racc (~> 1.4)
    parallel (1.22.1)
    parser (3.1.2.0)
      ast (~> 2.4.1)
    pg (1.4.1)
    pry (0.13.1)
      coderay (~> 1.1)
      method_source (~> 1.0)
    puma (5.6.4)
      nio4r (~> 2.0)
    racc (1.6.0)
    rack (2.2.4)
    rack-test (2.0.2)
      rack (>= 1.3)
    rails (7.0.3)
      actioncable (= 7.0.3)
      actionmailbox (= 7.0.3)
      actionmailer (= 7.0.3)
      actionpack (= 7.0.3)
      actiontext (= 7.0.3)
      actionview (= 7.0.3)
      activejob (= 7.0.3)
      activemodel (= 7.0.3)
      activerecord (= 7.0.3)
      activestorage (= 7.0.3)
      activesupport (= 7.0.3)
      bundler (>= 1.15.0)
      railties (= 7.0.3)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.4.3)
      loofah (~> 2.3)
    railties (7.0.3)
      actionpack (= 7.0.3)
      activesupport (= 7.0.3)
      method_source
      rake (>= 12.2)
      thor (~> 1.0)
      zeitwerk (~> 2.5)
    rainbow (3.1.1)
    rake (13.0.6)
    regexp_parser (2.5.0)
    reline (0.3.1)
      io-console (~> 0.5)
    reverse_markdown (2.1.1)
      nokogiri
    rexml (3.2.5)
    rubocop (1.31.1)
      json (~> 2.3)
      parallel (~> 1.10)
      parser (>= 3.1.0.0)
      rainbow (>= 2.2.2, < 4.0)
      regexp_parser (>= 1.8, < 3.0)
      rexml (>= 3.2.5, < 4.0)
      rubocop-ast (>= 1.18.0, < 2.0)
      ruby-progressbar (~> 1.7)
      unicode-display_width (>= 1.4.0, < 3.0)
    rubocop-ast (1.18.0)
      parser (>= 3.1.1.0)
    ruby-progressbar (1.11.0)
    solargraph (0.45.0)
      backport (~> 1.2)
      benchmark
      bundler (>= 1.17.2)
      diff-lcs (~> 1.4)
      e2mmap
      jaro_winkler (~> 1.5)
      kramdown (~> 2.3)
      kramdown-parser-gfm (~> 1.1)
      parser (~> 3.0)
      reverse_markdown (>= 1.0.5, < 3)
      rubocop (>= 0.52)
      thor (~> 1.0)
      tilt (~> 2.0)
      yard (~> 0.9, >= 0.9.24)
    strscan (3.0.3)
    thor (1.2.1)
    tilt (2.0.10)
    timeout (0.3.0)
    tzinfo (2.0.4)
      concurrent-ruby (~> 1.0)
    unicode-display_width (2.2.0)
    webrick (1.7.0)
    websocket-driver (0.7.5)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    yard (0.9.28)
      webrick (~> 1.7.0)
    zeitwerk (2.6.0)

PLATFORMS
  ruby
  x86_64-darwin-21
  x86_64-linux

DEPENDENCIES
  bootsnap
  debug
  dotenv-rails
  pg
  pry (~> 0.13.1)
  puma (~> 5.0)
  rails (~> 7.0.3)
  solargraph
  tzinfo-data

RUBY VERSION
   ruby 3.0.4p208

BUNDLED WITH
   2.2.33

Database.yml: (config)

# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On macOS with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # https://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: devHub_API_development

  # The specified database role being used to connect to postgres.
  # To create additional roles in postgres see `$ createuser --help`.
  # When left blank, postgres will use the default role. This is
  # the same name as the operating system user running Rails.
  #username: devHub_API

  # The password associated with the postgres role (username).
  #password:

  # Connect on a TCP socket. Omitted by default since the client uses a
  # domain socket that doesn't need configuration. Windows does not have
  # domain sockets, so uncomment these lines.
  #host: localhost

  # The TCP port the server listens on. Defaults to 5432.
  # If your server runs on a different port number, change accordingly.
  #port: 5432

  # Schema search path. The server defaults to $user,public
  #schema_search_path: myapp,sharedapp,public

  # Minimum log levels, in increasing order:
  #   debug5, debug4, debug3, debug2, debug1,
  #   log, notice, warning, error, fatal, and panic
  # Defaults to warning.
  #min_messages: notice

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: devHub_API_test

# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
#   DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
production:
  url: <%= ENV['DATABASE_URL'] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
# production:
#   <<: *default
#   database: devHub_API_production
#   username: devHub_API
#   password: <%= ENV['DEVHUB_API_DATABASE_PASSWORD'] %>

I'm more than happy to provide any additional details, since I'm so lost on this issue I'm not even 100% sure what info/files would be helpful to provide. More than anything I'd really love to understand the what and why here!

Thank you so much for your time/help! James

2 Antworten
0

Also would be likely helpful to see the logs, whoops!

----------------------------------------
/var/log/eb-engine.log
----------------------------------------
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/rubygems/ext/ext_conf_builder.rb:26:in
`build'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/rubygems/ext/builder.rb:164:in
`build_extension'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/rubygems/ext/builder.rb:198:in
`block in build_extensions'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/rubygems/ext/builder.rb:195:in
`each'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/rubygems/ext/builder.rb:195:in
`build_extensions'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/rubygems/installer.rb:851:in
`build_extensions'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/rubygems_gem_installer.rb:71:in
`build_extensions'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/rubygems_gem_installer.rb:28:in
`install'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:204:in
`install'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer/gem_installer.rb:54:in
`install'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:186:in
`do_install'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:171:in
`install_serially'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:97:in
`call'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:71:in
`call'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:259:in
`install_in_parallel'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:209:in
`install'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:89:in
`block in run'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/process_lock.rb:12:in
`block in lock'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/process_lock.rb:9:in
`open'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/process_lock.rb:9:in
`lock'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:71:in
`run'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:23:in
`install'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/cli/install.rb:62:in
`run'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:255:in `block
in install'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/settings.rb:131:in
`temporary'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:254:in
`install'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in
`run'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in
`invoke_command'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in
`dispatch'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:31:in
`dispatch'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in
`start'
  /opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:25:in `start'
/opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/gems/bundler-2.3.15/exe/bundle:48:in
`block in <top (required)>'
/opt/rubies/ruby-3.0.4/lib/ruby/site_ruby/3.0.0/bundler/friendly_errors.rb:117:in
`with_friendly_errors'
/opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/gems/bundler-2.3.15/exe/bundle:36:in
`<top (required)>'
  /opt/elasticbeanstalk/.rbenv/versions/3.0.4/bin/bundle:25:in `load'
  /opt/elasticbeanstalk/.rbenv/versions/3.0.4/bin/bundle:25:in `<main>'

An error occurred while installing pg (1.4.1), and Bundler cannot continue.

In Gemfile:
  pg
 

2022/07/06 16:54:07.332933 [INFO] Executing cleanup logic
2022/07/06 16:54:07.333069 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed to install dependency gems that you defined in 'Gemfile'. For details, see 'eb-engine.log'. The deployment failed.","timestamp":1657126447332,"severity":"ERROR"},{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1657126447332,"severity":"ERROR"}]}]}

2022/07/06 16:54:07.333247 [INFO] Platform Engine finished execution on command: app-deploy

2022/07/06 16:54:53.559449 [INFO] Starting...
2022/07/06 16:54:53.559495 [INFO] Starting EBPlatform-PlatformEngine
2022/07/06 16:54:53.559514 [INFO] reading event message file
2022/07/06 16:54:53.559664 [INFO] Engine received EB command cfn-hup-exec

2022/07/06 16:54:53.678576 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-1:489110557771:stack/awseb-e-hi2wpdaddr-stack/1adae7c0-fd44-11ec-8165-0a0fb8a2f08b -r AWSEBAutoScalingGroup --region us-east-1
2022/07/06 16:54:54.008860 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-1:489110557771:stack/awseb-e-hi2wpdaddr-stack/1adae7c0-fd44-11ec-8165-0a0fb8a2f08b -r AWSEBBeanstalkMetadata --region us-east-1
2022/07/06 16:54:54.298990 [INFO] checking whether command tail-log is applicable to this instance...
2022/07/06 16:54:54.299003 [INFO] this command is applicable to the instance, thus instance should execute command
2022/07/06 16:54:54.299008 [INFO] Engine command: (tail-log)

2022/07/06 16:54:54.299061 [INFO] Executing instruction: GetTailLogs
2022/07/06 16:54:54.299066 [INFO] Tail Logs...
2022/07/06 16:54:54.299307 [INFO] Running command /bin/sh -c tail -n 100 /var/log/web.stdout.log
2022/07/06 16:54:54.301041 [INFO] Running command /bin/sh -c tail -n 100 /var/log/eb-engine.log
beantwortet vor 2 Jahren
0

Hi James,

I don't have a definitive answer, but I am currently getting the same error messages as you. I downloaded all of the logs (rather than the last 100 lines) and when I inspected my eb-engine.log, there was some additional information which has pointed me to my particular issue -

checking for PQconninfo() in libpq-fe.h... no
Your PostgreSQL is too old. Either install an older version of this gem or
upgrade your database to at least PostgreSQL-9.3.
*** extconf.rb failed ***

As you can see, I need to install a later version of PostgreSQL. So far, I've seen the following: https://stackoverflow.com/questions/61148791/postgresql-on-elastic-beanstalk-amazon-linux-2

Which has led me to: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

Hopefully that leads you in the right direction. If you're having the same issue, I can update my response to reflect the resolution of it.

All the best,

Dan.

Dan
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen