ruby-on-rails Rails Dockerfile不再构建,无法安装racc

bnl4lu3b  于 2023-03-31  发布在  Ruby
关注(0)|答案(1)|浏览(128)

我已经在rails API上使用相同的Dockerfile几个月了,突然它不再构建了。每次尝试安装racc时,我都会收到一个错误:

#11 7.201 Installing racc 1.6.0 with native extensions
#11 7.598 Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
#11 7.598
#11 7.598     current directory: /usr/local/bundle/gems/racc-1.6.0/ext/racc/cparse
#11 7.598 /usr/local/bin/ruby -I /usr/local/lib/ruby/2.7.0 -r
#11 7.598 ./siteconf20211027-1-1m7t8pg.rb extconf.rb
#11 7.598 checking for rb_block_call()... *** extconf.rb failed ***
#11 7.598 Could not create Makefile due to some reason, probably lack of necessary
#11 7.598 libraries and/or headers.  Check the mkmf.log file for more details.  You may
#11 7.598 need configuration options.

奇怪的是,直到今天下午,它还能正常工作。这是我的dockerfile:

FROM ruby:2.7.4-alpine

ENV APP_PATH /api
ENV RAILS_PORT 3000

# install dependencies for application these are specific to alpine
RUN apk -U add --no-cache --update \
build-base \
git \
vim \
postgresql-dev \
postgresql-client \
ruby-diff-lcs \
libxml2-dev \
libxslt-dev \
linux-headers \
nodejs \
yarn \
imagemagick \
tzdata \
less \
ruby-nokogiri \
&& rm -rf /var/cache/apk/* \
&& mkdir -p $APP_PATH 

# navigate to app directory
WORKDIR $APP_PATH

COPY Gemfile ${APP_PATH}/Gemfile
COPY Gemfile.lock ${APP_PATH}/Gemfile.lock

RUN mkdir -p ${APP_PATH}/log && touch ${APP_PATH}/log/development.log

RUN bundle install

COPY . $APP_PATH
RUN gem install foreman

还有我的Gemfile

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

ruby '2.7.4'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4', '>= 6.1.4.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

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

# Devise and Json Web Token deps
gem 'devise'
gem 'devise-jwt'
gem 'fast_jsonapi'

# QR Code Generator
gem "rqrcode", "~> 2.0"

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]
  gem 'faker'
  gem 'rspec-rails'
  # testing stuff
  gem 'factory_bot_rails'
  gem 'shoulda-matchers'
  gem 'database_cleaner'
end

group :development do
  gem 'listen', '~> 3.3'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

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

任何帮助或建议都很感激。谢谢!

ql3eal8s

ql3eal8s1#

Ruby 2.7已经支持racc版本1.4.x作为“原生gem”。

gem "racc", "~> 1.4.0"

继续清除Gemfile.lock,然后运行bundle更新它。
这应该可以防止bundler尝试更新racc,并提供racc版本1.4.x作为依赖项,从而防止“build gem native extension”错误。
这里有一个链接,指向一些关于这个racc问题和其他常见nokogiri问题的有用文档。

相关问题