This is related to the various posts tagged gitlab-runner.
I got puppet linting, syntax checking etc. is working via the GitLab runner shell executor, and the next step was to move it into containers.
There be dragons, and they didn’t google very well, so here goes.
I’m using a Red Hat UBI Ruby 2.5 container – more about that here.
Bundler::GemspecError: (gem) may be corrupted
Bundler::GemspecError: Could not read gem at [path] It may be corrupted.
I tripped over this with:
$ bundle install --gemfile=ci/Gemfile Fetching gem metadata from https://rubygems.org/.......... Resolving dependencies... Fetching rake 12.3.2 Bundler::GemspecError: Could not read gem at /opt/rh/rh-ruby25/root/usr/share/gems/cache/rake-12.3.2.gem. It may be corrupted. An error occurred while installing rake (12.3.2), and Bundler cannot continue. Make sure that `gem install rake -v '12.3.2'` succeeds before bundling.
And I assumed this was just a rake issue, so I fixed it with a specific command to install it, and that worked.
$ gem install rake -v '12.3.2' Successfully installed rake-12.3.2 Parsing documentation for rake-12.3.2 Installing ri documentation for rake-12.3.2 Done installing documentation for rake after 1 seconds 1 gem installed
I declare that fixed 🙂
bundle install uses read only cache location
Too soon 😦
bundle install runs .. it finds the version of rake we want and then ..
$ bundle install --gemfile=ci/Gemfile Fetching gem metadata from https://rubygems.org/.......... Resolving dependencies... Using rake 12.3.2 Using bundler 1.16.1 Fetching facter 2.5.1 Bundler::GemspecError: Could not read gem at /opt/rh/rh-ruby25/root/usr/share/gems/cache/facter-2.5.1.gem. It may be corrupted. An error occurred while installing facter (2.5.1), and Bundler cannot continue. Make sure that `gem install facter -v '2.5.1'` succeeds before bundling.
This is going to run and run. There’s a list of about a dozen gems needed.
Evidently gem install works, but bundle install fails. Let’s look around ..
# docker run -it registry.access.redhat.com/ubi7/ruby-25 bash bash-4.2$ id uid=1001(default) gid=0(root) groups=0(root) bash-4.2$ ls -ald /opt/rh/rh-ruby25/root/usr/share/gems/cache/ drwxr-xr-x. 2 root root 6 Apr 16 13:55 /opt/rh/rh-ruby25/root/usr/share/gems/cache/
.. because it’s trying to use cache directory which isn’t writable, and I’m not running as root inside the container. So, how to tell Ruby to behave itself. The shell executor doesn’t have this problem ..
From man bundle-install:
--no-cache Do not update the cache in vendor/cache with the newly bundled gems. This does not remove any existing cached gems, only stops the newly bundled gems from being cached during the install.
$ bundle install --no-cache --gemfile=ci/Gemfile
Didn’t work. It seems to still want to use this cache. From man bundle-config:
path (BUNDLE_PATH) The location on disk to install gems. Defaults to $GEM_HOME in development and vendor/bundler when --deployment is used
$ GEM_HOME=~/.gem bundle install --gemfile=ci/Gemfile Fetching gem metadata from https://rubygems.org/.......... Resolving dependencies... Fetching rake 12.3.2 Installing rake 12.3.2 Using bundler 1.16.1 Fetching facter 2.5.1 Installing facter 2.5.1 Fetching fast_gettext 1.1.2 Installing fast_gettext 1.1.2 [snip]
Then, we also have to remember to set that variable for any rake commands etc as well.