Fix libmagic not being able to find magic files
What does this MR do?
This fixes a problem in UBI-8
builds that prevented ruby-magic
from
initializing. Any Rails code that needs to do MIME file detection
previously would fail with a 500 error.
This happened because ruby-magic downloads and installs the libmagic
library (https://github.com/file/file). libmagic
attempts to load
magic.mgc
from $PREFIX/share/magic/magic.mgc
if no environment
variables are set. In UBI-8
builds since we ran bundle install
in one
directory and copied the installed files into /srv/gitlab/vendor
, the
compiled libmagic
library would look in the original, non-existent
directory.
To fix this, we now install everything out of /srv/gitlab
to avoid
moving paths.
Quick verification:
$ docker run -it registry.gitlab.com/gitlab-org/build/cng/gitlab-webservice-ee:sh-fix-libmagic-ubi8-ubi8 bash
irb(main):001:0> require 'magic'
=> true
irb(main):002:0> Magic.new
=> #<Magic:0x00007f87bef19a58 @flags=0, @paths=["/srv/gitlab/vendor/bundle/ruby/2.7.0/gems/ruby-magic-0.4.0/ports/x86_64-pc-linux-gnu/libmagic/5.39/share/misc/magic"]>
Related issues
gitlab-org/charts/gitlab#2788 (closed)
Checklist
See Definition of done.
For anything in this list which will not be completed, please provide a reason in the MR discussion
Required
-
Merge Request Title, and Description are up to date, accurate, and descriptive -
MR targeting the appropriate branch -
MR has a green pipeline on GitLab.com
Expected (please provide an explanation if not completing)
-
Test plan indicating conditions for success has been posted and passes -
Documentation created/updated -
Integration tests added to GitLab QA -
The impact any change in container size has should be evaluated