如何使用Heroku和Amazon AWS资产设置RefineryCMS

CJB*_*rew 1 ruby-on-rails heroku amazon-web-services refinerycms

在过去三天的大部分时间里,我都在努力在Heroku上安装RefineryCMS.

在SO和各种博客上有很多问题,以及来自Refinery和Heroku(和Rails)的文档,但没有一个演练已经帮助100%...每个页面似乎都缺少一些重要的信息.

我已经尝试记录经过三到四次的所有必要步骤,每次都要完善程序(弄清楚什么是必要的).

参考文献包括它们显而易见的地方.

CJB*_*rew 9

使用Heroku选项运行精炼厂初始化脚本

refinerycms myapp --heroku
Run Code Online (Sandbox Code Playgroud)

来自http://refinerycms.com/guides/heroku

输出应该为您提供一个新的heroku应用程序及其输出中列出的名称:

"创建Heroku app ..运行heroku create --stack cedar from"."创建...完成,堆栈是雪松 http:// [你的 heroku app] .herokuapp.com/| git@heroku.com:[you heroku app] .git Git remote heroku添加"

在Amazon AWS上创建存储桶...

应该是不言自明的.

在Heroku环境中设置Amazon的连接信息

我们需要两套凭证.

  • AWS_*和FOG_*适用于Heroku (我相信rails预编译).
  • S3_*的东西是炼油厂能够上传图像等.

heroku config:add AWS_ACCESS_KEY_ID="<your key>" AWS_SECRET_ACCESS_KEY="<your secret>" FOG_DIRECTORY="<your bucket name>" FOG_PROVIDER="AWS" FOG_REGION="<your aws region>"

heroku config:add S3_BUCKET="<your bucket name>" S3_KEY="<your key>" S3_REGION="<your aws region>" S3_SECRET="<your secret>"

将所需的gem添加到Gemfile中

gem 'globalize3', '0.3.0'
Run Code Online (Sandbox Code Playgroud)

refinerycms添加页面时不起作用

gem 'unf' 
Run Code Online (Sandbox Code Playgroud)

(修正了一些警告)

gem 'rails_12factor'
Run Code Online (Sandbox Code Playgroud)

为什么在Heroku上需要rails_12factor gem?

gem 'asset_sync'
Run Code Online (Sandbox Code Playgroud)

来自https://github.com/rumblelabs/asset_sync.这个宝石似乎是将资产推向云端的唯一方法......虽然也许你可以在没有它的情况下做到; 也许其他人可以证实.

ruby '2.0.0' 
      [ place this at the end of the Gemfile. (Needed to clear Heroku warnings) ]
Run Code Online (Sandbox Code Playgroud)

在config/environments/production.rb中添加asset_sync资产主机路径

config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
Run Code Online (Sandbox Code Playgroud)

来自https://github.com/rumblelabs/asset_sync

在config/initializers/refinery/core.rb中设置站点名称

config.site_name = <your site name>
Run Code Online (Sandbox Code Playgroud)

在config/environments/production.rb中设置s3_backend

Refinery::Core.config.s3_backend = true
Run Code Online (Sandbox Code Playgroud)

来自https://github.com/refinery/refinerycms/issues/1879

配置数据库细节

删除config/database.yml中的sqlite3并设置postgresql:这是可选的,但是由Heroku和其他人推荐

对于适配器:

sqlite3 => postgresql
Run Code Online (Sandbox Code Playgroud)

对于数据库名称:

db/foo.sqlite3 => <sitename>_foo
Run Code Online (Sandbox Code Playgroud)

设置user-env-precompile设置

heroku labs:enable user-env-compile -a myapp
Run Code Online (Sandbox Code Playgroud)

来自https://devcenter.heroku.com/articles/labs-user-env-compile

运行Bundler

bundle install
Run Code Online (Sandbox Code Playgroud)

注意:首先,我必须按照提示运行:
1.rvm使用2.0.0以匹配我们在Gemfile 2中使用的版本.bund update globalize3

refinerycms添加页面时不起作用

创建(本地)生产数据库

RAILS_ENV=production rake db:create
Run Code Online (Sandbox Code Playgroud)

在资产预编译可以工作之前设置所需的环境变量

(这适用于*nix,在您的平台上执行您需要的任何操作)

export FOG_DIRECTORY="<your bucket name>"
export FOG_PROVIDER="AWS"
export AWS_SECRET_ACCESS_KEY="<your secret>"
export AWS_ACCESS_KEY_ID="<your key>"
Run Code Online (Sandbox Code Playgroud)

预编译资产(???)

注意:这可能不是必需的......(我每次都执行此步骤,但无法确定是否需要.接下来的步骤告诉我没有必要手动预编译:我们需要将"initialize_on_precompile"更改为false,运行git push到heroku(即没有资源),然后将"initialize_on_precompile"设置为true以备将来推送.不确定为什么我们需要这样做,并且它可能只是Rails 3的问题.*(请参阅:https ://devcenter.heroku.com/articles/rails-asset-pipeline)

RAILS_ENV=production bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)

在config/application.rb中设置precompile false

config.assets.initialize_on_precompile = false
Run Code Online (Sandbox Code Playgroud)

来自http://refinerycms.com/guides/heroku ...

你第一次git push to heroku时需要这个设置,因为否则git push heroku master的预编译步骤总是失败:

连接到DATABASE_URL指定的数据库rake中止了!无法连接到服务器:连接被拒绝服务器是否在主机"127.0.0.1"上运行并接受端口5432上的TCP/IP连接?

注意:参考文献对此不明确(虽然设置为false,然后在其他地方提到true).

签入文件以进行git并提交更改

注意:添加Gemfile.lock以及所有其他更改.

推送到heroku

git push heroku master
Run Code Online (Sandbox Code Playgroud)

在config/application.rb中将预编译选项设置回true

config.assets.initialize_on_precompile = true
Run Code Online (Sandbox Code Playgroud)

来自http://refinerycms.com/guides/heroku ...

将config/application.rb添加到git和commit(!!)

......如果你不这样做,下一次推动就会失败

推送到heroku(证明这次成功)

git push heroku master
Run Code Online (Sandbox Code Playgroud)

在Heroku数据库上迁移和种子

heroku run rake db:migrate
heroku run rake db:seed
Run Code Online (Sandbox Code Playgroud)

来自http://refinerycms.com/guides/heroku

准备好出发!

希望从这里您可以访问您的RefineryCMS页面,所有Refinery CSS和图像都正确显示(在管理员屏幕上和"查看网站"时仍然登录.

如果您使用Refinery菜单添加图像,则随后应该可以看到该图像已添加到您的AWS桶中.我还没有缩略图工作.