[英]foreman development vs production (rails)
what is the "foreman way" for behaving differently in production vs development?在生产与开发中表现不同的“工头方式”是什么? That is we want foreman start to start up a bunch of stuff in dev, however in heroku production we don't need it to start (for example) solr.
那就是我们希望工头开始在开发中启动一堆东西,但是在 heroku 生产中我们不需要它来启动(例如)solr。
I follow the convention; 我遵循惯例;
Procfile
defines all processes Procfile
定义所有进程 .foreman
set specific foreman variables .foreman
设置特定的工头变量 Development: 发展:
.env
sets environment variables for each developer .env
为每个开发人员设置环境变量 .env.example
sets defaults for development .env.example
设置开发的默认值 foreman start
starts all processes foreman start
启动所有流程 Production: 生产:
heroku config
sets environment variables heroku config
设置环境变量 heroku ps:scale
turns on or off whichever processes are needed for production heroku ps:scale
开启或关闭生产所需的任何流程 Here's an example from a project. 这是项目的一个例子。
Procfile: Procfile:
web: bundle exec unicorn_rails -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
search: bundle exec rake sunspot:solr:run
.env.example: .env.example:
# default S3 bucket
S3_KEY=keykeykeykeykeykey
S3_SECRET=secretsecretsecret
S3_BUCKET=myapp-development
.env .ENV
# developer's private S3 bucket
S3_KEY=mememememememememe
S3_SECRET=mysecretmysecret
S3_BUCKET=myapp-development
.foreman: 。领班:
# development port is 3000
port: 3000
Foreman takes arguments to use a different file (-d) and arguments to specify what to run. Foreman接受参数使用不同的文件(-d)和参数来指定运行的内容。 It also supports a
.foreman
file that allows those args to become default. 它还支持
.foreman
文件,允许这些args成为默认值。 See http://ddollar.github.com/foreman/ for more info 有关详细信息,请参见http://ddollar.github.com/foreman/
I've used environment-specific Procfile
s before, which is pretty simple and works fine. 之前我使用过特定
Procfile
环境的Procfile
,这很简单,工作正常。
Basically you have Procfile.development
, Procfile.production
, etc. In each you can customize the procs you want to start, then run them via foreman
like so: 基本上你有
Procfile.development
, Procfile.production
等。在每个你可以自定义你想要启动的过程,然后通过foreman
运行它们,如下所示:
foreman start -f Procfile.development
Another approach is to reference scripts in your Procfile
, and within each script start up the appropriate process based on the environment. 另一种方法是在
Procfile
引用脚本,并在每个脚本中根据环境启动相应的过程。 The creator of Foreman does this and has an example from his Anvil project your reference . Foreman的创造者做到了这一点 ,并从他的Anvil项目中得到了一个例子供您参考 。
Our solution was to use a separate job type in our Procfile for dev vs. production.我们的解决方案是在我们的 Procfile 中为开发与生产使用单独的作业类型。 It is not the most DRY method, but it works...
这不是最干的方法,但它有效......
sidekiq: bundle exec sidekiq
sidekiq-prod: bundle exec sidekiq -e production
Then we run foreman specifying the prod job on the production system:然后我们运行 foreman 在生产系统上指定 prod 作业:
foreman start -c sidekiq-prod=4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.