While trying to deploy my new rails project, i keep getting these error:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
An error occurred while installing pg (1.4.6), and Bundler cannot continue.
Make sure that gem install pg -v '1.4.6' --source 'https://rubygems.org/' succeeds before
bundling
In Gemfile:
pg
Error Failed to install dockerfile-rails gem, exiting: exit status 5
Longer answer: if you want to deploy using postgresql on fly.io (good choice!) you are going to need to include the pg gem. In order to install the pg gem, you will need to have postgresql installed on your machine. You won’t need to have it running on your machine, but you will need to have it installed.
You are going to need a machine on which you can install postgresql. If you can’t find one, you can use Sign In · Fly . The command to install postgresql libraries there is:
Once ready: run ‘fly deploy’ to deploy your Rails app.
/app/bin/friendsapp $ fly deploy
Update available 0.0.463 → v0.0.488.
Run “flyctl version update” to upgrade.
==> Verifying app config
→ Verified app config
==> Building image
Remote builder fly-builder-dry-pond-5853 ready
==> Creating build context
→ Creating build context done
==> Building image with Docker
→ docker host: 20.10.12 linux x86_64
Sending build context to Docker daemon 34.06kB
[+] Building 2.9s (17/19)
=> [internal] load remote build context 0.0s
=> copy /context / 0.1s
=> resolve image config for docker.io/docker/dockerfile:1 0.6s
=> CACHED docker-image://docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7 0.0s
=> [internal] load metadata for Docker 0.2s
=> [base 1/3] FROM Docker 0.0s
=> CACHED [base 2/3] WORKDIR /rails 0.0s
=> CACHED [base 3/3] RUN gem update --system --no-document && gem install -N bu 0.0s
=> CACHED [stage-2 1/4] RUN apt-get update -qq && apt-get install --no-install- 0.0s
=> CACHED [stage-2 2/4] RUN useradd rails --home /rails --shell /bin/bash 0.0s
=> CACHED [build 1/7] RUN apt-get update -qq && apt-get install --no-install-re 0.0s
=> CACHED [build 2/7] COPY --link Gemfile Gemfile.lock ./ 0.0s
=> CACHED [build 3/7] RUN bundle install && bundle exec bootsnap precompile --g 0.0s
=> [build 4/7] COPY --link . . 0.0s
=> [build 5/7] RUN bundle exec bootsnap precompile app/ lib/ 1.0s
=> [build 6/7] RUN chmod +x bin/* && sed -i ‘s/ruby.exe$/ruby/’ bin/* 0.3s
=> ERROR [build 7/7] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile 0.5s
[build 7/7] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile: #17 0.481 /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/definition.rb:524:in materialize': Could not find nokogiri-1.14.1 in locally installed gems (Bundler::GemNotFound) #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/definition.rb:197:in specs’ #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/definition.rb:254:in specs_for' #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/runtime.rb:18:in setup’ #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler.rb:170:in setup' #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/setup.rb:23:in block in <top (required)>’ #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/ui/shell.rb:159:in with_level' #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/ui/shell.rb:111:in silence’ #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/setup.rb:23:in <top (required)>' #17 0.482 from /usr/local/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:88:in require’ #17 0.482 from /usr/local/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:88:in require' #17 0.482 from /rails/config/boot.rb:3:in <top (required)>’ #17 0.482 from ./bin/rails:3:in require_relative' #17 0.482 from ./bin/rails:3:in ’
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile]: exit code: 1
[/quote]
Once ready: run ‘fly deploy’ to deploy your Rails app.
/app/bin/friendsapp $ fly deploy
Update available 0.0.463 → v0.0.488.
Run “flyctl version update” to upgrade.
==> Verifying app config
→ Verified app config
==> Building image
Remote builder fly-builder-dry-pond-5853 ready
==> Creating build context
→ Creating build context done
==> Building image with Docker
→ docker host: 20.10.12 linux x86_64
Sending build context to Docker daemon 34.06kB
[+] Building 2.9s (17/19)
=> [internal] load remote build context 0.0s
=> copy /context / 0.1s
=> resolve image config for docker.io/docker/dockerfile:1 0.6s
=> CACHED docker-image://docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7 0.0s
=> [internal] load metadata for Docker 0.2s
=> [base 1/3] FROM Docker 0.0s
=> CACHED [base 2/3] WORKDIR /rails 0.0s
=> CACHED [base 3/3] RUN gem update --system --no-document && gem install -N bu 0.0s
=> CACHED [stage-2 1/4] RUN apt-get update -qq && apt-get install --no-install- 0.0s
=> CACHED [stage-2 2/4] RUN useradd rails --home /rails --shell /bin/bash 0.0s
=> CACHED [build 1/7] RUN apt-get update -qq && apt-get install --no-install-re 0.0s
=> CACHED [build 2/7] COPY --link Gemfile Gemfile.lock ./ 0.0s
=> CACHED [build 3/7] RUN bundle install && bundle exec bootsnap precompile --g 0.0s
=> [build 4/7] COPY --link . . 0.0s
=> [build 5/7] RUN bundle exec bootsnap precompile app/ lib/ 1.0s
=> [build 6/7] RUN chmod +x bin/* && sed -i ‘s/ruby.exe$/ruby/’ bin/* 0.3s
=> ERROR [build 7/7] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile 0.5s
[build 7/7] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile: #17 0.481 /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/definition.rb:524:in materialize': Could not find nokogiri-1.14.1 in locally installed gems (Bundler::GemNotFound) #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/definition.rb:197:in specs’ #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/definition.rb:254:in specs_for' #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/runtime.rb:18:in setup’ #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler.rb:170:in setup' #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/setup.rb:23:in block in <top (required)>’ #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/ui/shell.rb:159:in with_level' #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/ui/shell.rb:111:in silence’ #17 0.482 from /usr/local/bundle/gems/bundler-2.4.8/lib/bundler/setup.rb:23:in <top (required)>' #17 0.482 from /usr/local/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:88:in require’ #17 0.482 from /usr/local/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:88:in require' #17 0.482 from /rails/config/boot.rb:3:in <top (required)>’ #17 0.482 from ./bin/rails:3:in require_relative' #17 0.482 from ./bin/rails:3:in ’
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile]: exit code: 1
It is not clear to me whether you installed postgresql locally or are running from the terminal, but I can see that your code was created using Microsoft Windows. If you are running from the terminal, you might want to look into WSL which will enable you to use VSCode. If you try this, Problem with login - #2 by rubys may help.
Back to your question. I see bundle install was cached, and yet a file listed in your bundle isn’t present. That normally means that a previous failure left the builder in a bad state. The easiest fix is generally: