Heroku在部署期间销毁pg gem

时间:2018-01-12 04:47:44

标签: ruby-on-rails ruby heroku

我正在尝试部署基于Ruby on Rails的Heroku应用程序,并且遇到了一些问题。虽然在过去的部署中不存在这些问题,但Heroku会在部署后随机删除pg gem。这是我的宝石文件:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.3'
# User rails12 factor for heroku's native ruby support tweaks
gem 'rails_12factor'
# Use wdm for Windows poll changes
gem 'wdm', '>= 0.1.0' if Gem.win_platform?
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Bootstrap 3 for themeing and templating
gem 'bootstrap-sass'
# Use bootstrapformfor to allow forms to be auto-formatted as per bootstrap standards
gem 'bootstrap_form'
# Use JQuery code optimized for Bootstrap usage
gem 'jquery-rails'
# Use Dragonfly for image upload and handling
gem 'dragonfly', '~> 1.1.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease
gem 'jbuilder', '~> 2.5'
# Use Devise for account management and authorization
gem 'devise'
# Use Cancancan for permissions enforcement
gem 'cancancan'
# Use rolify for role assignment to user accounts
gem 'rolify'
# Windows does not include zoneinfo files so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  # Postgres for active record
  gem 'pg'
end

以下是部署日志:

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.3.4
###### WARNING:
       Removing `Gemfile.lock` because it was generated on Windows.
       Bundler will do a full resolve so native gems are handled properly.
       This may result in unexpected gem versions being used in your app.
       In rare occasions Bundler may not be able to resolve your dependencies at all.
       https://devcenter.heroku.com/articles/bundler-windows-gemfile
-----> Installing dependencies using bundler 1.15.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4
       The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
       Fetching gem metadata from https://rubygems.org/..........
       Fetching version metadata from https://rubygems.org/..
       Fetching dependency metadata from https://rubygems.org/.
       Resolving dependencies...
       Using rake 12.3.0
       Using concurrent-ruby 1.0.5
       Fetching minitest 5.11.1
       Using thread_safe 0.3.6
       Using builder 3.2.3
       Using erubi 1.7.0
       Using mini_portile2 2.3.0
       Using crass 1.0.3
       Using rack 2.0.3
       Fetching nio4r 2.2.0
       Using websocket-extensions 0.1.3
       Using mini_mime 1.0.0
       Using arel 8.0.0
       Fetching public_suffix 3.0.1
       Installing public_suffix 3.0.1
       Installing minitest 5.11.1
       Installing nio4r 2.2.0 with native extensions
       Using execjs 2.7.0
       Using bcrypt 3.1.11
       Using rb-fsevent 0.10.2
       Using ffi 1.9.18
       Using bootstrap_form 2.7.0
       Using bundler 1.15.2
       Using cancancan 2.1.2
       Using coffee-script-source 1.12.2
       Using method_source 0.9.0
       Using thor 0.20.0
       Using orm_adapter 0.5.0
       Fetching multi_json 1.13.1
       Using puma 3.11.0
       Using rails_serve_static_assets 0.0.5
       Using rails_stdout_logging 0.0.5
       Fetching rolify 5.2.0
       Installing multi_json 1.13.1
       Installing rolify 5.2.0
       Using tilt 2.0.8
       Fetching turbolinks-source 5.1.0
       Using i18n 0.9.1
       Using nokogiri 1.8.1
       Installing turbolinks-source 5.1.0
       Using tzinfo 1.2.4
       Using rack-test 0.8.2
       Using warden 1.2.7
       Using sprockets 3.7.1
       Using websocket-driver 0.6.5
       Using mail 2.7.0
       Fetching autoprefixer-rails 7.2.4
       Fetching uglifier 4.1.3
       Installing autoprefixer-rails 7.2.4
       Installing uglifier 4.1.3
       Using rb-inotify 0.9.10
       Using coffee-script 2.4.1
       Fetching addressable 2.5.2
       Using rails_12factor 0.0.3
       Using loofah 2.1.1
       Using activesupport 5.1.4
       Fetching turbolinks 5.1.0
       Installing turbolinks 5.1.0
       Installing addressable 2.5.2
       Using sass-listen 4.0.0
       Using rails-html-sanitizer 1.0.3
       Using rails-dom-testing 2.0.3
       Using globalid 0.4.1
       Using activemodel 5.1.4
       Using jbuilder 2.7.0
       Fetching dragonfly 1.1.4
       Fetching sass 3.5.5
       Installing dragonfly 1.1.4
       Installing sass 3.5.5
       Using activejob 5.1.4
       Using actionview 5.1.4
       Using activerecord 5.1.4
       Using actionpack 5.1.4
       Using actionmailer 5.1.4
       Using railties 5.1.4
       Using sprockets-rails 3.2.1
       Using coffee-rails 4.2.2
       Using responders 2.4.0
       Using jquery-rails 4.3.1
       Fetching devise 4.4.0
       Installing devise 4.4.0
       Using bootstrap-sass 3.3.7
       Using sass-rails 5.0.7
       Using actioncable 5.1.4
       Using rails 5.1.4
       Bundle complete! 25 Gemfile dependencies, 72 gems now installed.
       Gems in the groups development and test were not installed.
       Bundled gems are installed into ./vendor/bundle.
       Bundle completed (8.28s)
       Cleaning up the bundler cache.
       Removing rolify (5.1.0)
       Removing turbolinks (5.0.1)
       Removing autoprefixer-rails (7.1.6)
       Removing sass (3.5.3)
       Removing mime-types-data (3.2016.0521)
       Removing nio4r (2.1.0)
       Removing minitest (5.10.3)
       Removing devise (4.3.0)
       Removing mimemagic (0.3.2)
       Removing cocaine (0.5.8)
       Removing pg (0.21.0)
       Removing uglifier (3.2.0)
       Removing multi_json (1.12.2)
       Removing paperclip (5.0.0)
       Removing turbolinks-source (5.0.3)
       Removing mime-types (3.1)
       Removing climate_control (0.2.0)
       The latest bundler is 1.16.1, but you are currently running 1.15.2.
       To update, run `gem install bundler`
-----> Installing node-v6.11.1-linux-x64
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
  ETCETCETC

请注意它是如何随机删除&#39;&#39;初始捆绑后的宝石。有人能指出我正确的方向吗?

4 个答案:

答案 0 :(得分:3)

将您的pg gem设置为要求Gemfile中的版本0.2x:

gem 'pg', '~> 0.20'

发生了什么事情,系统错误地尝试使用较新的,不兼容的pg版本。 pg 1.0.0于2018年1月10日发布,但目前还不支持rails。由于您没有指定要使用的pg版本,因此您的系统正在尝试使用新版本的pg,删除旧版本,然后失败。

有关详情,请参阅this rails issuethis rails issuethis fix (Revert to pg 0.21.0 as Rails does not support pg 1.0.0 yet)

答案 1 :(得分:0)

将您的pg gem移出开发环境。

答案 2 :(得分:0)

从开发中删除gem pg

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'  
end

并将其置于发展之外

# Postgres for active record
  gem 'pg'

答案 3 :(得分:0)

尝试以下

comment.owner移除gem 'pg'并将其保留在group :development之外的Gemfile上,然后运行bundler group,然后按照以下步骤操作

bundle update

那将有效

如果您再次有点困惑,请参阅Heroku documentation并从头开始

由于