rails環境構築時のbundle installでmimemagicに関するエラーが出るときはGemfileのrailsのバージョンを上げよう


# エラー内容
Dockerを使用してRailsの環境構築を行っていたところ、mimemagicに関する依存関係のエラーが発生したので備忘として記載します。

# 原因
Gemfileにて
`gem 'rails', '6.0.3'`
と指定しており、mimemagicの依存関係に関する既知の問題が発生したため。

# 解決方法
Gemfileにてrailsのバージョンをそれぞれ
Rails 5.2.5 / 6.0.3.6 / 6.1.3.1
以降に指定し、`bundle install`する。

# 参考元
[mimemagicの最新動向](https://hackmd.io/@mametter/mimemagic-info-ja)


# エラーメッセージ
```
$ docker-compose build
db uses an image, skipping
Building back
[+] Building 32.9s (9/12)                                                                                                                                               
 => [internal] load build definition from Dockerfile                                                                                                               0.0s
 => => transferring dockerfile: 1.28kB                                                                                                                             0.0s
 => [internal] load .dockerignore                                                                                                                                  0.0s
 => => transferring context: 2B                                                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/ruby:2.7.3-alpine3.13                                                                                           2.1s
 => [auth] library/ruby:pull token for registry-1.docker.io                                                                                                        0.0s
 => [1/7] FROM docker.io/library/ruby:2.7.3-alpine3.13@sha256:b63a28fd862407f5a57486076c19003389d6a3c3f13dc6b198519064fbc12546                                     0.0s
 => [internal] load build context                                                                                                                                  0.0s
 => => transferring context: 1.73kB                                                                                                                                0.0s
 => CACHED [2/7] WORKDIR /app                                                                                                                                      0.0s
 => CACHED [3/7] COPY Gemfile* ./                                                                                                                                  0.0s
 => ERROR [4/7] RUN apk update &&     apk upgrade &&     apk add --update --no-cache linux-headers libxml2-dev make gcc libc-dev nodejs tzdata mysql-dev mysql-c  30.6s
------                                                                                                                                                                  
 > [4/7] RUN apk update &&     apk upgrade &&     apk add --update --no-cache linux-headers libxml2-dev make gcc libc-dev nodejs tzdata mysql-dev mysql-client yarn &&     apk add --update --virtual build-dependencies --no-cache build-base curl-dev &&     bundle install --jobs=4 &&     apk del build-dependencies &&     rm -rf /usr/local/bundle/cache/*     /usr/local/share/.cache/*     /var/cache/*     /tmp/*     /usr/lib/mysqld*     /usr/bin/mysql*:                                                    
#9 0.238 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz                                                                                  
#9 0.829 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz                                                                             
#9 1.447 v3.13.5-230-gacbf5da9d2 [https://dl-cdn.alpinelinux.org/alpine/v3.13/main]
#9 1.447 v3.13.5-233-g64ac98865a [https://dl-cdn.alpinelinux.org/alpine/v3.13/community]
#9 1.447 OK: 13891 distinct packages available
#9 1.693 (1/2) Upgrading musl (1.2.2-r0 -> 1.2.2-r1)
#9 2.152 (2/2) Upgrading musl-utils (1.2.2-r0 -> 1.2.2-r1)
#9 2.201 Executing busybox-1.32.1-r6.trigger
#9 2.209 OK: 20 MiB in 36 packages
#9 2.251 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
#9 2.707 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
#9 3.285 (1/31) Installing binutils (2.35.2-r1)
#9 3.850 (2/31) Installing libgomp (10.2.1_pre1-r3)
#9 3.904 (3/31) Installing libatomic (10.2.1_pre1-r3)
#9 3.946 (4/31) Installing libgphobos (10.2.1_pre1-r3)
#9 4.320 (5/31) Installing isl22 (0.22-r0)
#9 4.458 (6/31) Installing mpfr4 (4.1.0-r0)
#9 4.734 (7/31) Installing mpc1 (1.2.0-r0)
#9 4.802 (8/31) Installing gcc (10.2.1_pre1-r3)
#9 7.209 (9/31) Installing musl-dev (1.2.2-r1)
#9 7.478 (10/31) Installing libc-dev (0.7.2-r3)
#9 7.508 (11/31) Installing xz-libs (5.2.5-r0)
#9 7.567 (12/31) Installing xz-dev (5.2.5-r0)
#9 7.612 (13/31) Installing libxml2 (2.9.10-r7)
#9 7.675 (14/31) Installing libxml2-dev (2.9.10-r7)
#9 7.863 (15/31) Installing make (4.3-r0)
#9 7.903 (16/31) Installing mariadb-common (10.5.11-r0)
#9 7.972 (17/31) Installing mariadb-client (10.5.11-r0)
#9 8.447 (18/31) Installing mysql-client (10.5.11-r0)
#9 8.473 (19/31) Installing openssl-dev (1.1.1k-r0)
#9 8.551 (20/31) Installing mariadb-connector-c (3.1.11-r0)
#9 8.611 (21/31) Installing mariadb-connector-c-dev (3.1.11-r0)
#9 8.657 (22/31) Installing libaio (0.3.112-r1)
#9 8.711 (23/31) Installing pcre2 (10.36-r0)
#9 8.796 (24/31) Installing mariadb-embedded (10.5.11-r0)
#9 9.186 (25/31) Installing mariadb-dev (10.5.11-r0)
#9 9.311 (26/31) Installing nghttp2-libs (1.42.0-r1)
#9 9.368 (27/31) Installing brotli-libs (1.0.9-r3)
#9 9.420 (28/31) Installing c-ares (1.17.1-r1)
#9 9.451 (29/31) Installing nodejs (14.16.1-r1)
#9 10.34 (30/31) Installing tzdata (2021a-r0)
#9 10.51 (31/31) Installing yarn (1.22.10-r0)
#9 10.65 Executing busybox-1.32.1-r6.trigger
#9 10.66 OK: 250 MiB in 67 packages
#9 10.71 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
#9 11.18 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
#9 11.69 (1/11) Installing libmagic (5.39-r0)
#9 11.79 (2/11) Installing file (5.39-r0)
#9 11.83 (3/11) Installing g++ (10.2.1_pre1-r3)
#9 13.88 (4/11) Installing fortify-headers (1.1-r0)
#9 13.91 (5/11) Installing patch (2.7.6-r7)
#9 13.95 (6/11) Installing build-base (0.5-r2)
#9 13.99 (7/11) Installing nghttp2-dev (1.42.0-r1)
#9 14.02 (8/11) Installing brotli-dev (1.0.9-r3)
#9 14.06 (9/11) Installing libcurl (7.77.0-r1)
#9 14.12 (10/11) Installing curl-dev (7.77.0-r1)
#9 14.19 (11/11) Installing build-dependencies (20210706.031902)
#9 14.19 Executing busybox-1.32.1-r6.trigger
#9 14.20 OK: 319 MiB in 78 packages
#9 17.94 Fetching gem metadata from https://rubygems.org/.............
#9 19.63 Fetching gem metadata from https://rubygems.org/.
#9 19.64 Resolving dependencies...
#9 19.90 Fetching rake 13.0.3
#9 20.04 Installing rake 13.0.3
#9 20.08 Fetching concurrent-ruby 1.1.9
#9 20.08 Fetching thread_safe 0.3.6
#9 20.09 Fetching minitest 5.14.4
#9 20.28 Installing minitest 5.14.4
#9 20.30 Fetching zeitwerk 2.4.2
#9 20.33 Installing thread_safe 0.3.6
#9 20.38 Fetching builder 3.2.4
#9 20.41 Installing concurrent-ruby 1.1.9
#9 20.45 Installing zeitwerk 2.4.2
#9 20.48 Fetching erubi 1.10.0
#9 20.51 Installing builder 3.2.4
#9 20.57 Fetching mini_portile2 2.5.3
#9 20.63 Installing erubi 1.10.0
#9 20.63 Fetching racc 1.5.2
#9 20.66 Fetching crass 1.0.6
#9 20.70 Installing mini_portile2 2.5.3
#9 20.72 Fetching rack 2.2.3
#9 20.78 Installing crass 1.0.6
#9 20.79 Fetching nio4r 2.5.7
#9 20.91 Installing racc 1.5.2 with native extensions
#9 20.96 Installing rack 2.2.3
#9 20.98 Installing nio4r 2.5.7 with native extensions
#9 25.37 Fetching websocket-extensions 0.1.5
#9 25.49 Installing websocket-extensions 0.1.5
#9 25.50 Using bundler 2.1.4
#9 26.32 Fetching mini_mime 1.1.0
#9 26.33 Fetching method_source 1.0.0
#9 26.35 Fetching thor 1.1.0
#9 26.48 Installing method_source 1.0.0
#9 26.49 Installing mini_mime 1.1.0
#9 26.50 Installing thor 1.1.0
#9 26.54 Fetching tzinfo 1.2.9
#9 26.56 Fetching i18n 1.8.10
#9 26.59 Fetching rack-test 1.1.0
#9 26.73 Installing i18n 1.8.10
#9 26.74 Installing rack-test 1.1.0
#9 26.77 Fetching sprockets 4.0.2
#9 26.79 Installing tzinfo 1.2.9
#9 26.83 Fetching websocket-driver 0.7.5
#9 26.90 Fetching nokogiri 1.11.7 (x86_64-linux)
#9 26.95 Installing websocket-driver 0.7.5 with native extensions
#9 26.97 Installing sprockets 4.0.2
#9 27.39 Fetching mail 2.7.1
#9 27.42 Fetching activesupport 6.0.3
#9 27.77 Installing activesupport 6.0.3
#9 27.79 Installing mail 2.7.1
#9 27.80 Installing nokogiri 1.11.7 (x86_64-linux)
#9 28.30 Fetching globalid 0.4.2
#9 28.30 Fetching activemodel 6.0.3
#9 28.45 Installing globalid 0.4.2
#9 28.47 Installing activemodel 6.0.3
#9 28.48 Fetching activejob 6.0.3
#9 28.56 Fetching activerecord 6.0.3
#9 28.59 Installing activejob 6.0.3
#9 28.68 Fetching loofah 2.10.0
#9 28.68 Fetching rails-dom-testing 2.0.3
#9 28.81 Installing activerecord 6.0.3
#9 28.86 Installing rails-dom-testing 2.0.3
#9 28.87 Installing loofah 2.10.0
#9 28.91 Fetching mimemagic 0.3.10
#9 28.93 Fetching rails-html-sanitizer 1.3.0
#9 29.01 Installing mimemagic 0.3.10 with native extensions
#9 29.05 Installing rails-html-sanitizer 1.3.0
#9 29.17 Fetching actionview 6.0.3
#9 29.35 Installing actionview 6.0.3
#9 29.41 Fetching actionpack 6.0.3
#9 29.61 Installing actionpack 6.0.3
#9 29.69 Fetching actionmailer 6.0.3
#9 29.70 Fetching railties 6.0.3
#9 29.70 Fetching actioncable 6.0.3
#9 29.83 Installing actionmailer 6.0.3
#9 29.85 Installing actioncable 6.0.3
#9 29.90 Fetching sprockets-rails 3.2.2
#9 30.04 Installing sprockets-rails 3.2.2
#9 30.16 Installing railties 6.0.3
#9 30.37 Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
#9 30.37 
#9 30.37     current directory: /usr/local/bundle/gems/mimemagic-0.3.10/ext/mimemagic
#9 30.37 /usr/local/bin/ruby -I/usr/local/lib/ruby/2.7.0/rubygems -rrubygems
#9 30.37 /usr/local/bundle/gems/rake-13.0.3/exe/rake
#9 30.37 RUBYARCHDIR\=/usr/local/bundle/extensions/x86_64-linux-musl/2.7.0/mimemagic-0.3.10
#9 30.37 RUBYLIBDIR\=/usr/local/bundle/extensions/x86_64-linux-musl/2.7.0/mimemagic-0.3.10
#9 30.37 rake aborted!
#9 30.37 Could not find MIME type database in the following locations:
#9 30.37 ["/usr/local/share/mime/packages/freedesktop.org.xml",
#9 30.37 "/opt/homebrew/share/mime/packages/freedesktop.org.xml",
#9 30.37 "/opt/local/share/mime/packages/freedesktop.org.xml",
#9 30.37 "/usr/share/mime/packages/freedesktop.org.xml"]
#9 30.37 
#9 30.37 Ensure you have either installed the shared-mime-info package for your
#9 30.37 distribution, or
#9 30.37 obtain a version of freedesktop.org.xml and set FREEDESKTOP_MIME_TYPES_PATH to
#9 30.37 the location
#9 30.37 of that file.
#9 30.37 
#9 30.37 This gem might be installed as a dependency of some bigger package, such as
#9 30.37 rails, activestorage,
#9 30.37 axlsx or cucumber. While most of these packages use the functionality of this
#9 30.37 gem, some gems have
#9 30.37 included this gem by accident. Set USE_FREEDESKTOP_PLACEHOLDER=true if you are
#9 30.37 certain that you
#9 30.37 do not need this gem, and wish to skip the inclusion of freedesktop.org.xml.
#9 30.37 
#9 30.37 The FREEDESKTOP_PLACEHOLDER option is meant as a transitional feature, and will
#9 30.37 be deprecated in
#9 30.37 the next release.
#9 30.37 /usr/local/bundle/gems/mimemagic-0.3.10/ext/mimemagic/Rakefile:15:in
#9 30.37 `locate_mime_database'
#9 30.37 /usr/local/bundle/gems/mimemagic-0.3.10/ext/mimemagic/Rakefile:39:in `block in
#9 30.37 <top (required)>'
#9 30.37 /usr/local/bundle/gems/rake-13.0.3/exe/rake:27:in `<main>'
#9 30.37 Tasks: TOP => default
#9 30.37 (See full trace by running task with --trace)
#9 30.37 
#9 30.37 rake failed, exit code 1
#9 30.37 
#9 30.37 Gem files will remain installed in /usr/local/bundle/gems/mimemagic-0.3.10 for
#9 30.37 inspection.
#9 30.37 Results logged to
#9 30.37 /usr/local/bundle/extensions/x86_64-linux-musl/2.7.0/mimemagic-0.3.10/gem_make.out
#9 30.37 
#9 30.37 An error occurred while installing mimemagic (0.3.10), and Bundler cannot
#9 30.37 continue.
#9 30.37 Make sure that `gem install mimemagic -v '0.3.10' --source
#9 30.37 'https://rubygems.org/'` succeeds before bundling.
#9 30.37 
#9 30.37 In Gemfile:
#9 30.37   rails was resolved to 6.0.3, which depends on
#9 30.37     actionmailbox was resolved to 6.0.3, which depends on
#9 30.37       activestorage was resolved to 6.0.3, which depends on
#9 30.37         marcel was resolved to 0.3.3, which depends on
#9 30.37           mimemagic
------
executor failed running [/bin/sh -c apk update &&     apk upgrade &&     apk add --update --no-cache ${RUNTIME_PACKAGES} &&     apk add --update --virtual build-dependencies --no-cache ${DEV_PACKAGES} &&     bundle install --jobs=4 &&     apk del build-dependencies &&     rm -rf /usr/local/bundle/cache/*     /usr/local/share/.cache/*     /var/cache/*     /tmp/*     /usr/lib/mysqld*     /usr/bin/mysql*]: exit code: 5
ERROR: Service 'back' failed to build : Build failed
```