32

I'm aware of the recent mimemagic issues, which I managed to resolve on one of my Rails projects by bundle updating to 0.3.7 - but for some reason, I can't resolve it on the project below.

I have a Rails 6 project which I'm setting up for the first time on a new laptop. My laptop doesn't have the correct Ruby setup, so I've added a Dockerfile to my project like so:-

Dockerfile

FROM ruby:2.7
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
WORKDIR /radius
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle update mimemagic
RUN bundle install
COPY . /myapp


COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000


CMD ["rails", "server", "-b", "0.0.0.0"]

Gemfile

# frozen_string_literal: true

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

ruby '2.7.2'
gem 'airbrake'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'dotenv-rails'
gem 'rails', '~> 6.0.3.6'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
gem 'shortener'

# Use Honeybadger for error reporting/monitoring
gem 'honeybadger', '~> 4.0'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'newrelic_rpm'

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

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

group :development, :test do
  gem 'awesome_print'
  gem 'byebug', platforms: %i[mri mingw x64_mingw]
  gem 'pry-byebug'
  # Version specified as workaround for this issue https://github.com/rails/rails/issues/35417
  gem 'rspec-rails', '~> 4.0.0.beta2'
end

group :development do
  gem 'factory_bot_rails', '~> 4.0'
  gem 'fasterer'
  gem 'haml_lint', require: false
  gem 'listen', '>= 3.0.5', '< 3.2'
  gem 'rails_best_practices'
  gem 'reek'
  gem 'rubocop'
  gem 'scss_lint', require: false
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'web-console', '>= 3.3.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'rspec_junit_formatter'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
  gem 'webmock'
end

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

gem 'administrate', '0.12.0'
gem 'bootstrap', '~> 4.3', '>= 4.3.1'
gem 'devise', '~> 4.6', '>= 4.6.1'
gem 'devise-bootstrapped',  github: 'excid3/devise-bootstrapped',
                            branch: 'bootstrap4'
gem 'devise_masquerade', '~> 0.6.2'
gem 'font-awesome-sass', '~> 5.6', '>= 5.6.1'
gem 'friendly_id', '~> 5.2', '>= 5.2.5'
gem 'gibbon'
gem 'gmaps4rails'
gem 'gravatar_image_tag', github: 'mdeering/gravatar_image_tag'
gem 'httparty'
gem 'mini_magick', '~> 4.9', '>= 4.9.2'
gem 'name_of_person', '~> 1.1'
gem 'omniauth-facebook', '~> 5.0'
gem 'omniauth-github', '~> 1.3'
gem 'omniauth-twitter', '~> 1.4'
gem 'pundit', '~> 1.1.0'
gem 'sidekiq', '~> 5.2', '>= 5.2.5'
gem 'sitemap_generator', '~> 6.0', '>= 6.0.1'
gem 'underscore-rails'
gem 'whenever', require: false

I then try:-

docker-compose build
docker-compose up

Along with every combination of the following:-

  • Using bundle update mimemagic in my dockerfile
  • Adding the gem specifically to my Gemfile with gem 'mimemagic', '~> 0.3.7'
  • Manually changing my Gemfile.lock mimemagic version from 0.3.5 to 0.3.7
  • Adding RUN apt-get install shared-mime-info to my Dockefile

and I simply get one of the below:-

Could not find mimemagic-0.3.x in any of the sources
web_1  | Bundler::GemNotFound: You have requested:
web_1  |   mimemagic ~> 0.3.7
web_1  | 
web_1  | The bundle currently has mimemagic locked at 0.3.5.
web_1  | Try running `bundle update mimemagic`

I've also tried bumping rails to 6.0.3.6 and running the docker build again, which gives me activesupport issues:-

web_1  | Bundler::VersionConflict: Bundler could not find compatible versions for gem "activesupport":
web_1  |   In snapshot (Gemfile.lock):
web_1  |     activesupport (= 6.0.3.5)
web_1  | 
web_1  |   In Gemfile:
web_1  |     rails (~> 6.0.3.6) was resolved to 6.0.3.6, which depends on
web_1  |       activesupport (= 6.0.3.6)
web_1  | 
web_1  |     dotenv-rails was resolved to 2.7.6, which depends on
web_1  |       railties (>= 3.2) was resolved to 6.0.3.5, which depends on
web_1  |         activesupport (= 6.0.3.5)
web_1  | 
web_1  | Running `bundle update` will rebuild your snapshot from scratch, using only
web_1  | the gems in your Gemfile, which may resolve the conflict.

What exactly do I need to do to get this gem to install?

s89_
  • 1,533
  • 3
  • 25
  • 40
  • Likely it's that version of rails which is locking mimemagic. Check your Gemfile.lock. Use the latest version. If it's a new project there's no reason to use an old version, nor a release candidate. `gem 'rails', '~> 6.1'`. And you should do your bundle updates *before* deploying. – Schwern Mar 28 '21 at 18:34
  • It's not quite a new project - newish. It's being set up on this laptop for the first time though. I've tried bumping it to rails 6.0.3.6 and it gives me activesupport errors mentioned in my post. – s89_ Mar 28 '21 at 18:41
  • @Schwern And what do you mean do bundle updates before deploying? I'm not deploying this project anywhere. – s89_ Mar 28 '21 at 18:46
  • You're deploying/installing it on Docker. The point of a Gemfile.lock is to lock the versions of your gems to get consistent installs. `bundle update` just before `bundle install` defeats the point. It's also slow, you don't need to bundle update in Docker, you can do that anywhere. Anyhow, what *else* is in your Gemfile? dotenv-rails is not a rails dependency. – Schwern Mar 28 '21 at 18:52
  • @Schwern a few other things - added them to the post. Still, the issue remains with Rails' activesupport dependency, regardless of the dot-env one. – s89_ Mar 28 '21 at 18:58
  • I can't say for sure without your Gemfilie.lock, but `bundle update` Works For Me™ with that Gemfile. mimemagic isn't even in the dependency tree. – Schwern Mar 28 '21 at 19:00
  • @Schwern is that running it from your Dockefile with `docker-compose build`? Or outside of Docker? – s89_ Mar 28 '21 at 19:05
  • Outside of Docker. It shouldn't matter. 6.0.3.6 dropped the mimemagic dependency. – Schwern Mar 28 '21 at 19:05
  • The problem is I don't have the correct Ruby version installed at the moment, and have had issues trying to install it - hence why I'm using the Dockerfile. So I can't run bundle update outside of Docker. – s89_ Mar 28 '21 at 19:07
  • Start Docker without bundling and installing, get a shell to your Docker, use the shell to fix it interactively. – Schwern Mar 28 '21 at 19:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/230485/discussion-between-s89-and-schwern). – s89_ Mar 28 '21 at 19:13
  • @Schwern is it possible to start docker in it's current state? It's just auto exiting even if I remove the bundle install, because of the aforementioned gem issues. – s89_ Mar 28 '21 at 19:22
  • Answered here https://stackoverflow.com/questions/66837647/heroku-loaderror-cannot-load-such-file-mimemagic-overlay/66837726?noredirect=1#comment118156791_66837726 – sam Mar 28 '21 at 23:58
  • Does this answer your question? [Heroku: LoadError: cannot load such file -- mimemagic/overlay](https://stackoverflow.com/questions/66837647/heroku-loaderror-cannot-load-such-file-mimemagic-overlay) – Eyeslandic Apr 02 '21 at 14:28

6 Answers6

47
bundle update --conservative mimemagic 

also try with newer version rather than locking it. it worked for us with 0.3.9, but now there is 0.3.10(have not tried it),

user1678123
  • 486
  • 5
  • 5
7

Solved it using:

bundle update mimemagic

I was getting the error Your bundle is locked to mimemagic (0.3.5) from rubygems on bundle install.

This updated mimemagic version to 0.3.10 and added nokigiri and rake dependencies in Gemfile.lock for me.

Faisal Raza
  • 1,337
  • 1
  • 10
  • 16
4

You can modify your Gemfile as below:

gem 'mimemagic', github: 'mimemagicrb/mimemagic', ref: '01f92d86d15d85cfd0f20dabd025dcbd36a8a60f' 

More details are here

  • You should edit this answer to incorporate your other answer, since that answer is from a question which was marked as a duplicate of this one. – Peter O. Apr 27 '21 at 12:30
4

For my case this was the solution from macOS: 'You will require a copy of the Freedesktop.org shared-mime-info database to be available. If you're on Linux, it's probably available via your package manager, and will probably be in the location it's being looked for when the gem is installed.

macOS users can install the database via Homebrew with brew install shared-mime-info.' https://github.com/mimemagicrb/mimemagic

1

rename/remove the Gemfile.lock

mv Gemfile.lock oldGemfile.lock

Bundle install

bundle install
Babatunde Mustapha
  • 2,131
  • 20
  • 21
0

Other solutions may update more gems than you'd like.

Another solution is to edit your Gemfile.lock

Find the line that says mimemagic (0.3.5)

Replace with mimemagic (0.3.10)

Or whatever is the highest 0.3.x version you find here: https://github.com/mimemagicrb/mimemagic/tags

Paul Odeon
  • 4,407
  • 1
  • 37
  • 37