I have a sinatra application and packaged that as a gem. Its file-layout looks roughly like this:
├── bin
│ └── tubemp
├── lib
│ └── tubemp.rb
├── Gemfile
└── tubemp.gemspec
I can install and run it just fine. Calling ruby lib/tubemp.rb
fires the app too, because Sinatra made it self-starting. tubemp.rb
:
class Tubemp < Sinatra::Application
get '/' do
erb :index, :locals => { :title => "YouTube embeds without third party trackers." }
end
end
The binary is really simple too. bin/tubemp
:
#!/usr/bin/env ruby
require "tubemp.rb"
Tubemp.run!
But now I want to deploy this as Rack-app. Or deploy it inside a Rack-app. At least it should run under Passenger on a production machine.
With a generic application it is as simple as adding a config.ru
in the directory where the application lives. This file then, roughly, includes and calls run Tubemp
. Pointing nginx or apache's passenger at the dir where this rackup file and the app lives, starts it.
This worked, up to the point where I made it a gem; because now I no longer have "a directory where the app lives", other then where gem install tubemp
decides to place the files.
Do I need to create a wrapper
application wich bundles the tubemp-gem and its dependencies? If so, how do I call the gem from a rackup
file? Or am I going at this entirely wrong?
Ignoring path-issues for now, here is how I solved it:
The application bundled as gem, tubemp
.
A Gemfile
to install and include the gemified application:
gem 'tubemp'
A config.ru
which runs the gemified application, called Tubemp
:
require 'rubygems'
require 'bundler/setup' # To allow inclusion via the Bundle/Gemfile
require 'sinatra' # Sinatra is required so we can call its "set"
require 'tubemp' # And include the application
# Set the environment to :production on production
set :environment, ENV['RACK_ENV'].to_sym
# And fire the application.
run Tubemp
These two files is all that is needed to make a new rack-application, which includes the
gemified Sinatra-app and as such are bootable trough e.g. nginx,
passenger or simply rackup
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With