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

发布于 2024-08-13 03:32:26 字数 672 浏览 4 评论 0原文

我有一个 Sinatra 应用程序,正在尝试在 Dreamhost 上运行,该应用程序利用 pony 发送电子邮件。为了让应用程序从一开始就启动并运行(在添加 pony 之前),我必须将 gem unpackrack 和 gem unpack sinatra 放入供应商/目录中,所以这是我的 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

我已经完成了 gem install ponygem unpack pony (到供应商/)。之后,我尝试将 require 'vendor/sinatra/lib/pony' 添加到 config.ru,结果却让 Passenger 抱怨 pony 的依赖项(mime 类型、tmail)没有被执行找到了!

必须有一种更好的方法来使用其他宝石并淡化那些冗长、丑陋、冗余的需求。有什么想法吗?

I've got a Sinatra app that I'm trying to run on Dreamhost that makes use of pony to send email. 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:

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/). 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!

There has to be a better way to use other gems and tone down those long, ugly, redundant requires. Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请别遗忘我 2024-08-20 03:32:26

我建议在“某处”创建您自己的 gem 路径,然后将其添加到您的 config.ru 中
就像:

ENV['GEM_PATH'] = xxx
Gem.clear_paths

然后将你的宝石安装到其中

I'd recommend creating your own gem path "somewhere" then adding it in your config.ru
like:

ENV['GEM_PATH'] = xxx
Gem.clear_paths

then install your gems into that

眼眸印温柔 2024-08-20 03:32:26

在 dreamhost 上安装 Ruby gems

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

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

require 'rubygems'

require 'vendor/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

希望它对某人有帮助。

我在我的 Sinatra 中使用了 pony 和许多其他宝石。它应该也适合你。您只需在配置中添加这两行(GEM_HOME 和 GEM_PATH)即可。

Install Ruby gems on dreamhost

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

Change config.ru (works for Sinatra 1.0)

require 'rubygems'

require 'vendor/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. 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.

尘曦 2024-08-20 03:32:26

我花了很长时间才发现您可以简单地使用“gem install sinatra”,并且 gem 会发现(因为系统目录是只读的)您将需要使用本地 gem 安装目录。目前来看,似乎根本不需要设置什么特殊的环境。它发现使用 $HOME/.gem 作为本地 gem 路径,一切正常。根本不需要“供应商/东西”。我确实发现我必须将 $HOME/.gem/ruby/1.8/bin 添加到我的路径中才能执行 gems 安装的二进制文件。

这是我的 config.ru(用于 Dreamhost)

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

稍后编辑:这一切都很好,但仍然存在 作业首次启动时,乘客找不到我的宝石

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. 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. No need for require 'vendor/stuff' at all. I did find I had to add $HOME/.gem/ruby/1.8/bin to my path in order to execute binaries installed by gems.

Here's my config.ru (for 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.

折戟 2024-08-20 03:32:26

我的 config.ru 很简单:

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

和 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

My config.ru is just simple as:

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

and app.rb head:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文