Closed ValkyrieOps closed 3 years ago
I'm missing the context here, what do you mean from "inside an asset?"
when sensu-agent or sensu-backend make use of runtime assets the modify several environment variables, appending directories to both library search path and executable paths.
So I'm not sure what you are trying to show me with the command snippet because I don't know if you have prepared your interactive shell environment to mimic the behavior that sensu-agent does when using runtime assets before calling a check command.
My fault I should have provided a better explanation. So to clarify, I have an asset which contains several ruby scripts (built as a gem), one of which calls for libyaml. The check that utilizes this asset also includes the sensu-ruby-runtime asset to provide ruby. That check is currently failing and in order to debug (perhaps incorrectly), I have attempted to load up irb on the host the check executes on to try and step through the issue.
I've done this in the past for other assets/checks by calling ruby from the sensu-agent asset cache bin directory, followed by the failing asset/checks location. In this case when doing so I am unable to load libyaml. Similarly trying to execute gem list, or a require 'yaml' statement from the sensu-ruby-runtime bin dir fails in the same way. Apologies if this methodology is incorrect or shouldn't work to begin with.
Okay so, not all possible native C library extensions are provided by the runtime asset. Only the things needed to build ruby-runtime itself.
If you are building a ruby based asset that needs additional compiled C libraries (instead of just pure Ruby) then you'll need to provide those libraries as part of the asset you are building.
Here's an example you can work from:
https://github.com/sensu-plugins/sensu-plugins-postgres
look at the .travis,yml
and then the Dockerfiles in
asset_build_scripts/
to customize the build process.
In the case of postgres, there's a need to install the postgres C library as the ruby gem calls into that C library. You'll probably need to do something similar for the libyaml. Notice the Dockerfiles do some cleverness with ldd to extract
When using irb to test, you need to make sure you update the LD_LIBRARY_PATH to also include your asset's library directory.
Here's where I do my sales pitch for migrating to golang for Sensu assets..its just soooo much easier to maintain. But if you need to use ruby for internal use, the postgres repo should provide you with a pattern you can follow.
Thanks for the swift reply. Was actually just looking at that example you provided to see what I'm missing so we can chalk this up to a case of pebkac. Long term I agree it'll be better to migrate all the checks to golang for ease of use but unfortunately I'm stuck with some of this legacy stuff for now. Not the end of the world. I appreciate your feedback and thank you again!
OS Version CentOS 7.6.1810
Release 0.1.0
Issue Requiring 'yaml' in an asset fails. Attempting to run a require statement manually from irb gives the following output
Don't know if this is expected behavior but it seems to be hit or miss whether or not standard libraries load correctly. Running ./gem also fails in a similar fashion. Please let me know if I can provide any more info here. Thanks