如何运送Sinatra应用程序作为宝石并部署? [英] How to ship a Sinatra application as a gem and deploy it?

查看:200
本文介绍了如何运送Sinatra应用程序作为宝石并部署?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个sinatra应用程序,并打包成作为宝石。其文件布局大致如下:

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

我可以安装并运行它很好。调用 ruby​​ lib / tubemp.rb 也触发应用程序,因为Sinatra使它自行启动。 tubemp.rb

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

二进制也很简单。 bin / tubemp

#!/usr/bin/env ruby
require "tubemp.rb"
Tubemp.run!

但现在我想将其部署为Rack-app。或者将其部署在机架应用程序中。至少应该在生产机器上的乘客下运行。

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.

使用通用应用程序,只需添加 config.ru 在应用程序的目录中。该文件大致包含并调用运行Tubemp 。将nginx或apache的乘客指向这个机架文件和应用程序所在的目录,启动它。
这个工作,直到我把它作为一个宝石;因为现在我不再有一个应用程序的目录,而另外一个 gem install tubemp 决定放置文件。

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.

我需要创建一个包含tubemp-gem及其依赖项的包装器应用程序吗?如果是,如何从 rackup 文件中调用gem?或者我完全错了吗?

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?

推荐答案

忽略路径问题现在,以下是我解决了它

应用程序捆绑为gem, tubemp

The application bundled as gem, tubemp.

一个 Gemfile 来安装并包含有宝石的应用程序:

A Gemfile to install and include the gemified application:

gem 'tubemp'

A config.ru 它运行的是gemified应用程序,称为 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

这两个文件是创建新的机架应用程序所需要的,其中包括
宝石Sinatra应用程序,因此可以通过例如引导nginx,
乘客或简单地 rackup

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.

这篇关于如何运送Sinatra应用程序作为宝石并部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆