ran*_*891 1 ruby-on-rails amazon-web-services amazon-elastic-beanstalk
我正在尝试将 Rails 7 应用程序 (Ruby 3.0.4) 部署到使用 Amazon Linux 2 的 Elastic Beanstalk。可能是安装 nokogiri 依赖项时出现问题?
Could not find nokogiri-1.13.7-x86_64-linux in any of the sources
Run Code Online (Sandbox Code Playgroud)
2022/07/17 13:57:15.371714 [错误] 执行命令 [app-deploy] - [stage ruby application] 期间发生错误。停止运行该命令。错误:在 Gemfile 中安装依赖项失败,出现错误 Command /bin/sh -c bundle 2.3.15 install --local 失败,出现错误退出状态 7。 Stderr:不要以 root 身份运行 Bundler。如果需要,Bundler 可以请求 sudo,并且以 root 身份安装捆绑包将会对该计算机上的所有非 root 用户破坏此应用程序。在任何源中都找不到 nokogiri-1.13.7-x86_64-linux
我在 Mac 上使用 Bundler 2.3.18,我看到 Elastic Beanstalk 使用的是 Bundler 2.3.15,我不确定这是否会导致问题?
我尝试删除所有 gem 并重新安装,然后部署到 AWS EB。
bundle clean --force然后取消注释了 Gemfile。rm -rf vendor/cache删除缓存的宝石bundle(再次重新安装gem)最初,由于 foreman 错误,我无法使用 bin/dev,因此我重新安装了 foremanrbenv local 3.0.4 && gem install foreman
阅读https://nokogiri.org/tutorials/installing_nokogiri.html后我跑了bundle lock --add-platform x86_64-linux
我尝试了这个后备解决方案https://nokogiri.org/tutorials/installing_nokogiri.html#solution_1
rm -rf vendor/cache
bundle config set force_ruby_platform true
bundle install
Run Code Online (Sandbox Code Playgroud)
如果我不在供应商/缓存下缓存 gem 文件,我将收到有关 pg gem 的错误
bundle package --all
Run Code Online (Sandbox Code Playgroud)
在我的 gemfile.lock 中,我看到 x86_64-linux 条目。
PLATFORMS
ruby
x86_64-linux
Run Code Online (Sandbox Code Playgroud)
和
nokogiri (1.13.7)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
nokogiri (1.13.7-x86_64-linux)
racc (~> 1.4)
pg (1.4.1)
Run Code Online (Sandbox Code Playgroud)
我有一个.ebextensions/options.config包含以下内容的文件。我尝试了这个答案中的内容,但它对我不起作用。
packages:
yum:
amazon-linux-extras: []
git: []
patch: []
gcc: []
libxml2: []
libxml2-devel: []
libxslt: []
libxslt-devel: []
commands:
01_A:
command: sudo amazon-linux-extras enable postgresql13
02_B:
command: sudo yum install -y postgresql-devel
Run Code Online (Sandbox Code Playgroud)
在弹性 beanstalk CLI 中我运行了:
eb create staging-env -db.engine postgres --database.instance db.t3.micro --database.username my_user --database.password my_pass --database.size 5 --database.version 13.4 --instance_type t3.micro --single
Run Code Online (Sandbox Code Playgroud)
它总是在 EC2 实例步骤失败,并且 eb-engine.log 文件将引用 nokogiri 作为原因。
在 cfn-init.cmd.log 中,我看到如下条目,表明正在安装 nokogiri 的依赖项。可能还有一个我仍然错过的依赖项?
[INFO] yum list installed libxml2
[INFO] Completed successfully.
Run Code Online (Sandbox Code Playgroud)
在 eb-engine.log 中,bundle 命令正在通过--localelastic beanstalk 选项运行。所以它只是查看vendor/cache,而 x86_64-linux nokogiri 不在那里。
error **Command /bin/sh -c bundle _2.3.15_ install --local** failed with error exit status 7. Could not find nokogiri-1.13.7-x86_64-linux in any of the sources
Run Code Online (Sandbox Code Playgroud)
我尝试在 ebextensions/options.config 文件中传递捆绑安装,但失败了。
04_bundle:
command: 'bundle install'
Run Code Online (Sandbox Code Playgroud)
这就是最终对我有用的东西。我.ebextensions/ruby.config为 nokogiri 创建了以下包依赖项。
packages:
yum:
amazon-linux-extras: []
git: []
patch: []
gcc: []
libxml2: []
libxml2-devel: []
libxslt: []
libxslt-devel: []
commands:
01_postgresql13:
command: sudo amazon-linux-extras enable postgresql13
02_postgresql-devel:
command: sudo yum install -y postgresql-devel
Run Code Online (Sandbox Code Playgroud)
我运行bundle lock --add-platform x86_64-linux(如果需要的话还有 aarch64\arm64 版本)并检查 nokogiri 是否在我的 gemfile.lock 中列出了新的 linux 版本
我删除了所有缓存的宝石vendor/cacherm -rf vendor/cache
确保一切都在 git 中提交。重要的部分是删除 gem 缓存,以便 elastic beanstalks 捆绑器不会查看缓存并被迫获取 gem 的 Linux 版本。
Fetching nokogiri 1.13.7 (x86_64-linux)
Installing nokogiri 1.13.7 (x86_64-linux)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
651 次 |
| 最近记录: |