There are several Ruby wrapper gems for pdftk. Among them, is there any gem that installs the pdftk binary automatically cross major OSs at installation of itself? I want to require it in a library, and I can manually install pdftk on my own machine, but I want to avoid the mess of the users of my library being required to manually install pdftk binary.
Why not use a native solution such as CombinePDF...?
Depends on what you need, it might actually serve you better.
Related
I can gem open #{gem_name} (command line) to see the source of installed gems. But how do I view the source of e.g. openssl which is in ruby core?
(Without going to the github repo... is there a command to view it locally?)
There isn't one. The reason most probably is that gems shipped with Ruby aren't treated in a different way than the core code. That said, the libraries are located under ext/.
If you want to find specific code (assuming it's Ruby and not C), you can always do
foo.method(:bar).source_location
Foo.instance_method(:bar).source_location
I have written a ruby service that I want to package and distribute internally to a specific environment (a standardized linux host). After digging around a bit for the best ways to create a distribution, I've come across a lot of blogs and answers here that recommend bundler and gem packaging as well as a lot of binary distribution options (e.g. traveling-ruby), but these all seem like a bit too much for a relatively simple service that will get deployed to a known environment. I want to create a distribution that doesn't require dependencies to be resolved at deploy time (e.g. bundle install --deployment is not the approach I want).
So with this in mind, is there an available framework that is commonly in use by ruby apps that would create a redistributable package with all dependencies included in it? I am currently doing this in 2 steps and wondering if there's a "better" ruby-way of doing it - something along the lines of gem build ... that creates dependency-inclusive archive?
# Assuming `bundle install` was run on developer workstation and there's a `Gemfile.lock`
$ bundle install --deployment
$ tar zcf ../my-app.tar.gz ./
my-app.tar.gz can now be distributed and if I have an executable to run it with, I can do so with bundle exec bin/run from within the directory after it's extracted. This a good approach?
I've seen a gem called crate that might be able to work....
I am creating a small daemon, written in Ruby, which relies in part on a small binary utility compiled from C code. I want to package this as a gem and include this dependency along with it.
Essentially, this daemon will need to run commands such as ip addr add ... without requiring sudo, so I created a small C program to proxy those commands which must be compiled, chowned to root, and have the setuid bit set.
I would like to have the gem compile and install this dependency along with the daemon, but I am unsure how to do so. I understand extensions can be compiled via extconf.rb, but that is specifically meant for managing Ruby extensions, right? Would it be an ugly hack to have this compile and install a binary to /usr/local/bin or similar?
Does anyone know of an existing gem which does a similar thing which I can study as an example?
Here's a gem that packages the pdftk binary.
https://github.com/charliemaffitt/pdftk-heroku
I need to install a number of ruby gems (all with C extensions) on a production server which does not have any dev tools installed. I'd like to build gems on a dev server first and then repackage and install resulting native gems on production server.
However, there seems to be no standard methods to package gem with native extensions for redistribution. I am aware of rake-compiler, but none of the gems in concern works with it out of the box. Specifically, I am working with json-1.7.5, rb-inotify-0.8.8 and ffi-1.2.1 gems.
Any pointers on how to do this task or documentations on the subject are appreciated.
Using Jordan Sissel's fpm you can take various input archives (including gems) and compile and package them as (among others) DEBs or RPMs.
An example to compile the json gem into a deb package follows:
cd /tmp
fpm -s gem -t deb json
This will download the latest version of the json gem and create a rubygem-json-1.5.7-1.amd64.deb archive in /tmp which you can install on your server. Note that the compile box and the final server need to be rather identical. At least the distribution and bitness, the ruby version and its file layout, and the available loadable libraries should be the same. Basically all the constraints your upstream distribution deals with...
That said, in the long term I found it much easier to just install a compiler on the target servers and use rbenv or rvm on the server. For most small and mid-size installations, it's much easier to handle as you don't need to pre-compile and ship everything to your servers.
Hi You could do it with: gem-compiler
You need to tell RubyGems the filename of the gem you want to compile:
$ gem compile yajl-ruby-1.1.0.gem
The above command will unpack, compile any existing extensions found and repackage everything as a binary gem:
Unpacking gem: 'yajl-ruby-1.1.0' in temporary directory...
Building native extensions. This could take a while...
Successfully built RubyGem
Name: yajl-ruby
Version: 1.1.0
File: yajl-ruby-1.1.0-x86-mingw32.gem
It have well written documentations here:
https://github.com/luislavena/gem-compiler.
I am using it as well as we have own gem server. Just have to be careful with distribution because some gems compiled on wheezy won't work on jessie and so on.
You're going to have to build them on a system that's almost exactly the same for this to work. If you're linking against shared libraries that are in a different location or have slightly different versions it may not work at all. Sometimes you have some slack, where it will work with a range of versions, but this cannot be assured.
There's no way to package with native extensions for this very reason, there's just too many possible combinations of libraries.
You'll also need to make sure you're using the same architecture, including 32-bit or 64-bit as required.
Sometimes you'll get lucky and there's a package for your OS that can install these for you, but these won't work with rvm or rbenv.
Nokogiri allows for this by specifying the libraries in the install command:
gem install nokogiri -- --with-xml2-lib=/home/joe/builds/lib
--with-xml2-include=/home/joe/builds/include/libxml2
--with-xslt-lib=/home/joe/builds/lib
--with-xslt-include=/home/joe/builds/include
I did a little digging through Nokogiri's source to try to find out how they allow for those options to get passed down from the command to the actual build/installation.
I noticed the use of Rake::ExtensionTask as well as mini_portile, however their use seems to be limited to cross compiling on Windows systems in their code.
Is there some bit of code I can throw in my gem to allow users to specify the library they want to link against at install time? How did nokogiri allow for this?
This is using the dir_config method of the mkmf library.
The gem install command uses any arguments after -- as arguments to the build command, so they get passes to your extconf.rb.
Note you still need to use have_library or find_library in order to actually link to the library.