在Windows上开发,在Heroku上生产环境运行Unicorn

17

我有一个新的Rails项目,决定尝试使用Heroku进行部署,那里的部署似乎非常容易。

我是在Windows上开发的,所以无法选择运行unicorn,但是webrick适合开发。

但是,当涉及到部署时,我想使用unicorn,而Heroku完美支持这一点。

问题是:我必须在Gemfile中列出unicorn,以便Heroku选取它,但当我这样做并在我的Windows开发机器上运行bundle命令(或rails s)时,它会尝试安装unicorn服务器。

我尝试将unicorn放入production组中, group :production do gem 'unicorn' end 但bundle仍然抱怨,我无法运行开发服务器。

2个回答

42
你可以在Gemfile中针对特定平台进行设置:
platforms :ruby do # linux
  gem 'unicorn'
end

platforms :mswin do
  # gems specific to windows
end

查看gemfile的手册获取更多信息。


16

备选方案(原帖作者非常接近)为

group :production do
  gem 'unicorn'
end

然后使用

bundle install --without production

在你的Windows机器上。

Heroku附注(未经测试)

与被接受的答案不同,这不应导致Heroku忽略你的Gemfile.lock

这是因为Heroku在决定是否为Windows生成时检查你的Gemfile中是否有mswinmingw


Windows 7:在安装kgio时,gem 'unicorn',group: :production会给我一个错误,而gem 'unicorn',platforms: :ruby则不会。 - Matthias

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接