Permission errors with Ruby plugin and fluentd

A customer inquired about assistance snapping a package called fluentd (an open source log collector), and on a whim, I threw together a quick snapcraft.yaml to see if it would build using the ruby plugin.

Lo and behold, I was able to build the snap with the following part definition:

parts:
  fluentd:
    source: https://github.com/fluent/fluentd.git  
    # See 'snapcraft plugins'
    plugin: ruby

That said the build did produce a number of errors when building ruby, during bundle gem install (whatever that means). I wanted to check if anyone else has seen something similar, and is there cause for concern? I checked launchpad, but didn’t find any bugs that were applicable (although there are a couple requests for a ruby plugin which should probably be closed out). I’m using snapcraft 2.35.

I haven’t yet tried to run the application, but will do so shortly.

Here are the errors:

installing bundle gems:       //lib/ruby/gems/2.4.0 (build_info, cache, doc, extensions, gems, specifications)
                              net-telnet 0.1.1
                              power_assert 0.4.1
                              rake 12.0.0
                              did_you_mean 1.1.0
                              xmlrpc 0.2.1
                              test-unit 3.2.3
                              minitest 5.10.1
Unable to open /opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/power_assert-0.4.1.gem for writing: [Errno 13] Permission denied: '/opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/power_assert-0.4.1.gem'
Unable to open /opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/xmlrpc-0.2.1.gem for writing: [Errno 13] Permission denied: '/opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/xmlrpc-0.2.1.gem'
Unable to open /opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/test-unit-3.2.3.gem for writing: [Errno 13] Permission denied: '/opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/test-unit-3.2.3.gem'
Unable to open /opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/minitest-5.10.1.gem for writing: [Errno 13] Permission denied: '/opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/minitest-5.10.1.gem'
Unable to open /opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/net-telnet-0.1.1.gem for writing: [Errno 13] Permission denied: '/opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/net-telnet-0.1.1.gem'
Unable to open /opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/rake-12.0.0.gem for writing: [Errno 13] Permission denied: '/opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/rake-12.0.0.gem'
Unable to open /opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/did_you_mean-1.1.0.gem for writing: [Errno 13] Permission denied: '/opt/dev/fluentd/parts/fluentd/install/lib/ruby/gems/2.4.0/cache/did_you_mean-1.1.0.gem'

Note that, at least in the current rendition of Snapcraft, errors are red. What you see there are warnings. Poorly phrased warnings, yes, but in this case they’re harmless. Once Ruby is built it scatters absolute-path shebangs around, so the Ruby plugin literally crawls the entire install base, opening up files and checking for bad shebangs. The gems end up with permission 0o444, so it doesn’t have permission to look within them, thus the warnings.

Ignoring that, then, you’re not actually building fluentd at all, you’re just building ruby. All the Ruby plugin does is give you a Ruby install in the snap. Since there are many uses for the Ruby plugin (many of which aren’t to build gems), we decided to start out doing nothing. Perhaps eventually we’ll introduce, say, a gem plugin that expects a gemspec, but we don’t have that today (the Ruby plugin is pretty new). Which means that you need to tell Snapcraft to build the gem once it’s built Ruby. Try this:

parts:
  fluentd:
    source: https://github.com/fluent/fluentd.git
    plugin: ruby
    build: gem build fluentd.gemspec
    install: gem install fluentd-*.gem --env-shebang

That will give you a bin/fluentd in the snap, although I haven’t tested it. I’ll leave that to you :slight_smile: .

Thanks @kyrofa! That got me a bit further, but now it turns out that the ruby wrapper script that get generated by RubyGems for fluentd ends up with a header that looks like this:

#!/usr/bin/env ruby

Which results in a failure when I try to start fluentd. I tried removing the –env-shebang from your example, and that results in a shebang that points at the part’s install directory. I couldn’t find any other gem install option that controls this, so looks like the only viable approach is patching the resulting wrapper scripts as part of the install step?

/usr/bin/env ruby is typically what you want. Can you give me some details regarding the problem you’re seeing?

Looks like driver error on my part… ruby wasn’t being snap’d.

Brum Brum… beep beep… brum brum