简体   繁体   English

使用自定义 gem 在 Dreamhost/Passenger 上部署 Sinatra 应用程序

[英]Deploying Sinatra app on Dreamhost/Passenger with custom gems

I've got a Sinatra app that I'm trying to run on Dreamhost that makes use of pony to send email.我有一个 Sinatra 应用程序,我试图在 Dreamhost 上运行它,它利用小马发送电子邮件。 In order to get the application up and running at the very beginning (before adding pony), I had to gem unpack rack and gem unpack sinatra into the vendor/ directory, so this was my config.ru:为了让应用程序在一开始就启动并运行(在添加 pony 之前),我必须将gem unpack rackgem unpack sinatra放到 vendor/ 目录中,所以这是我的 config.ru:

require 'vendor/rack/lib/rack'
require 'vendor/sinatra/lib/sinatra'

set :run, false
set :environment, :production
set :views, "views"

require 'public/myapp.rb'
run Sinatra::Application

I have already done gem install pony and gem unpack pony (into vendor/).我已经完成了gem install ponygem unpack pony (到 vendor/)。 Afterwards, I tried adding require 'vendor/sinatra/lib/pony' to config.ru only to have Passenger complain about pony's dependencies (mime-types, tmail) not being found either!之后,我尝试将require 'vendor/sinatra/lib/pony'添加到 config.ru,结果只是让乘客抱怨 pony 的依赖项(mime-types、tmail)也找不到!

There has to be a better way to use other gems and tone down those long, ugly, redundant requires .必须更好的方法来使用其他宝石并淡化那些冗长、丑陋、多余的requires Any thoughts?有什么想法吗?

I'd recommend creating your own gem path "somewhere" then adding it in your config.ru like:我建议在“某处”创建自己的 gem 路径,然后将其添加到config.ru中,例如:

ENV['GEM_PATH'] = xxx
Gem.clear_paths

then install your gems into that然后将您的宝石安装到其中

Install Ruby gems on dreamhost在 Dreamhost 上安装 Ruby gem

https://c.kat.pe/installing-ruby-gems-on-dreamhost https://c.kat.pe/installing-ruby-gems-on-dreamhost

Change config.ru (works for Sinatra 1.0)更改 config.ru(适用于 Sinatra 1.0)

require 'rubygems'需要“红宝石”

require 'vendor/sinatra/lib/sinatra.rb'需要'供应商/sinatra/lib/sinatra.rb'

ENV['GEM_HOME'] = '/home/username/.gems'
ENV['GEM_PATH'] = '$GEM_HOME:/usr/lib/ruby/gems/1.8'
require 'rubygems'
Gem.clear_paths

disable :run, :reload

set :environment, :production

require 'yourapp'
run Sinatra::Application

Hope it helps someone.希望它可以帮助某人。

I am using pony and a lot of other gems for my Sinatra.我正在为我的 Sinatra 使用小马和许多其他宝石。 It should work well for you too.它也应该适合你。 It's just those two lines (GEM_HOME and GEM_PATH) you have to add on your config.您必须在配置中添加这两行(GEM_HOME 和 GEM_PATH)。

It took me ages to find that you can simply use "gem install sinatra" and gem will figure out (because the system directories are read-only) that you will need to use a local gem install directory.我花了很长时间才发现您可以简单地使用“gem install sinatra”,gem 会发现(因为系统目录是只读的)您需要使用本地 gem 安装目录。 As of now, there seems to be no need to set any special environment at all.到目前为止,似乎根本不需要设置任何特殊环境。 It figures out to use $HOME/.gem as the local gem path and everything just works.它发现使用 $HOME/.gem 作为本地 gem 路径,一切正常。 No need for require 'vendor/stuff' at all.根本不需要 require 'vendor/stuff'。 I did find I had to add $HOME/.gem/ruby/1.8/bin to my path in order to execute binaries installed by gems.我确实发现我必须将 $HOME/.gem/ruby/1.8/bin 添加到我的路径中才能执行 gems 安装的二进制文件。

Here's my config.ru (for Dreamhost)这是我的 config.ru(用于 Dreamhost)

## Passenger should set RACK_ENV for Sinatra
require 'test'
set :environment, :development
run Sinatra::Application

Later edit: This is all well and fine, but there remains the issue that Passenger can't find my gems when the job initially starts up .稍后编辑:这一切都很好,但是仍然存在问题,即当工作最初启动时,Passenger 找不到我的宝石

My config.ru is just simple as:我的 config.ru 很简单:

require 'rubygems'
require 'vendor/sinatra/lib/sinatra.rb'
require 'app.rb'

and app.rb head:和 app.rb 头:

require 'yaml'
require 'haml'
require 'ostruct'
require 'date'
require 'pp'

module FlytoFB
    log = File.new("sinatra.log", "a")
    STDOUT.reopen(log)
    STDERR.reopen(log)

    configure do

            enable :logging, :dump_errors
            set :app_file, __FILE__
            set :reload, true
            set :root, File.dirname(__FILE__)
            set :environment, :production
            set :env, :production
            set :run, false

            set :raise_errors, true
      set :public, 'public'

            error do
                    e = request.env['sinatra.error']
                    puts e.to_s
                    puts e.backtrace.join("\n")
                    "Application Error!"
            end

            not_found do
              "Page not found!"
      end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM