尝试部署到heroku失败,运行最新版本的Rails 8.0 ruby 3.2.2。我是初学者,所以我不知道该怎么做

问题描述 投票:0回答:1

运行推送命令部署到heroku,我不断收到失败消息。我尝试阅读该问题,似乎未指定 ruby 版本。我在 Heroku 上读到它假定 2.5 及以上版本的默认版本,所以这毕竟不是问题。我认为由于heroku 的要求,gem pg 是问题所在。无论如何,任何意见都是值得赞赏的,因为我已经尽力解决这个问题,但到目前为止还无法做到这一点。

git push heroku HEAD:master      
Enumerating objects: 117, done.
Counting objects: 100% (117/117), done.
Delta compression using up to 8 threads
Compressing objects: 100% (104/104), done.
Writing objects: 100% (117/117), 46.53 KiB | 6.65 MiB/s, done.
Total 117 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), done.
remote: Updated 103 paths from ad68afd
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-24 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Ruby app detected
remote: -----> Installing bundler 2.5.6
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: 
remote: ###### WARNING:
remote: 
remote:        No ruby version specified in the Gemfile.lock
remote:        
remote:        We could not determine the version of Ruby from your Gemfile.lock.
remote:        
remote:          $ bundle platform --ruby
remote:          No ruby version specified
remote:        
remote:          $ bundle -v
remote:          Bundler version 2.5.6
remote:        
remote:        
remote:        Ensure the above command outputs the version of Ruby you expect. If you have a ruby version specified in your Gemfile, you can update the Gemfile.lock by running the following command:
remote:        
remote:          $ bundle update --ruby
remote:        
remote:        Make sure you commit the results to git before attempting to deploy again:
remote:        
remote:          $ git add Gemfile.lock
remote:          $ git commit -m "update ruby version"
remote: 
remote: -----> Using Ruby version: ruby-3.1.6
remote: -----> Installing dependencies using bundler 2.5.6
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
remote:        Fetching gem metadata from https://rubygems.org/.........
remote:        activesupport-8.0.0 requires ruby version >= 3.2.0, which is incompatible with
remote:        the current version, 3.1.6
remote:        Bundler Output: Fetching gem metadata from https://rubygems.org/.........
remote:        activesupport-8.0.0 requires ruby version >= 3.2.0, which is incompatible with
remote:        the current version, 3.1.6
remote: 
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: 8414643d8039fe52725693b0806b9fc259324153
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 8414643d8039fe52725693b0806b9fc259324153
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote: 
remote: Verifying deploy...
remote: 
remote: !   Push rejected to radiant-hamlet-84739.
remote: 
To https://git.heroku.com/radiant-hamlet-84739.git
 ! [remote rejected] HEAD -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/radiant-hamlet-84739.git'

我尝试在 StackOverflow 和 google 上查找其他帖子,但运气不佳。 有人请看一下我的错误并提出解决方案吗?我将不胜感激。

这是我的宝石文件:

[# Use sqlite3 as the database for Active Record
gem "sqlite3" 
# Use the Puma web server \[https://github.com/puma/puma\]
gem "puma", ">= 5.0"
# Use JavaScript with ESM import maps \[https://github.com/rails/importmap-rails\]
gem "importmap-rails"
# Hotwire's SPA-like page accelerator \[https://turbo.hotwired.dev\]
gem "turbo-rails"
# Hotwire's modest JavaScript framework \[https://stimulus.hotwired.dev\]
gem "stimulus-rails"
# Build JSON APIs with ease \[https://github.com/rails/jbuilder\]
gem "jbuilder"

# 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\[ windows jruby \]

# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable
gem "solid_cache"
gem "solid_queue"
gem "solid_cable"

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

# Deploy this application anywhere as a Docker container \[https://kamal-deploy.org\]
gem "kamal", require: false

# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma \[https://github.com/basecamp/thruster/\]
gem "thruster", require: false

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

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

  # Static analysis for security vulnerabilities \[https://brakemanscanner.org/\]
  gem "brakeman", require: false

  # Omakase Ruby styling \[https://github.com/rails/rubocop-rails-omakase/\]
  gem "rubocop-rails-omakase", require: false
end

group :development do
  # Use console on exceptions pages \[https://github.com/rails/web-console\]
  gem "web-console"
end

group :test do
  # Use system testing \[https://guides.rubyonrails.org/testing.html#system-testing\]
  gem "capybara"
  gem "selenium-webdriver"
end

group :production do 
  gem 'pg', '~> 1.5', '>= 1.5.9'
end][1]

最好的,

enter code here

ruby-on-rails github heroku
1个回答
0
投票

您需要从 gemfile 中删除 SQLite gem,或者至少将其从默认部分移至

group :development, :test
。安装 gem 失败,因为 gem 所需的库在设计上不存在。

SQLite 在内存中运行,并将其数据存储在磁盘上的文件中。虽然这种策略非常适合开发,但 Heroku 的 Cedar 堆栈有一个临时文件系统。您可以向其中写入,也可以从中读取,但内容会定期清除。如果您要在 Heroku 上使用 SQLite,您将至少每 24 小时丢失一次整个数据库。
即使 Heroku 的磁盘持久运行 SQLite 仍然不适合。由于 SQLite 不作为服务运行,因此每个 dyno 将运行一个单独的运行副本。每个副本都需要自己的磁盘支持存储。这意味着为您的应用程序提供动力的每个测功机将具有一组不同的数据,因为磁盘不同步。 https://devcenter.heroku.com/articles/sqlite3

还要确保您已在

config/database.yml
中重新配置了数据库适配器。

虽然您可以在生产中使用 Postgres,在开发/测试中使用 SQLite,但我不推荐这种方法,因为它们之间存在许多差异,ActiveRecord 无法完全抽象掉。您不想通过炸毁您的生产环境来了解它们。

Rails 8 可能需要额外的重新配置,因为现在默认使用 SQLite 来替换 ActionCable 和框架其他部分的 Redis/Memcached。

© www.soinside.com 2019 - 2024. All rights reserved.