如何使用 Heroku 和 Amazon AWS 资产设置 RefineryCMS
-
21-12-2019 - |
题
过去三天的大部分时间我都在努力在 Heroku 上安装 RefineryCMS。
关于 SO 和各种博客以及来自 Refinery 和 Heroku(和 Rails)的文档有很多问题,但没有一个演练能够 100% 提供帮助......每一页似乎都缺少一些重要的信息。
我尝试记录所有必要的步骤,并经历了三到四次,每次都改进程序(找出哪些是必要的,哪些是不必要的)。
参考文献包括明显的地方。
解决方案
使用 Heroku 选项运行精炼厂初始化脚本
refinerycms myapp --heroku
从 http://refinerycms.com/guides/heroku
输出应该为您提供一个新的 heroku 应用程序及其在输出中列出的名称:
“创建 Heroku 应用程序..从“”运行Heroku Create -Stack Cedar。创建...完成,堆栈是雪松http://[你的 heroku app] .herokuapp.com/ | git@heroku.com:[您的Heroku App] .git git远程Heroku添加了”
在亚马逊 AWS 上创建存储桶...
应该是不言自明的。
在 Heroku 环境中设置 Amazon 连接信息
我们需要两组凭据。
- AWS_* 和 FOG_* 适用于 Heroku (我相信 Rails 是预编译的)。
- S3_* 的东西是让 Refinery 能够上传图像等。
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'
gem 'unf'
(修复一些警告)
gem 'rails_12factor'
从 为什么 Heroku 上需要有rails_12factor gem?
gem 'asset_sync'
从 https://github.com/rumblelabs/asset_sync. 。这个宝石似乎是将资产推到云端的唯一方法......尽管也许没有它你也可以凑合;也许其他人可以证实。
ruby '2.0.0'
[ place this at the end of the Gemfile. (Needed to clear Heroku warnings) ]
在 config/environments/production.rb 中添加 asset_sync 资产主机路径
config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
从 https://github.com/rumblelabs/asset_sync
在 config/initializers/refinery/core.rb 中设置站点名称
config.site_name = <your site name>
在 config/environments/production.rb 中设置 s3_backend
Refinery::Core.config.s3_backend = true
从 https://github.com/refinery/refinerycms/issues/1879
配置数据库详细信息
删除 config/database.yml 中的 sqlite3 并设置 postgresql:这是可选的,但由 Heroku 和其他人推荐
对于适配器:
sqlite3 => postgresql
对于数据库名称:
db/foo.sqlite3 => <sitename>_foo
设置 user-env-precompile 设置
heroku labs:enable user-env-compile -a myapp
从 https://devcenter.heroku.com/articles/labs-user-env-compile
运行捆绑器
bundle install
笔记:首先,我必须按照提示运行:
1.RVM使用2.0.0以匹配我们在Gemfile 2中使用的版本。捆绑更新全球化3
创建(本地)生产数据库
RAILS_ENV=production rake db:create
设置资产预编译工作之前所需的环境变量
(这是针对 *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>"
预编译资产(???)
笔记:这可能不是必需的...(我每次都执行此步骤,但无法确定是否需要。接下来的步骤建议我不需要手动预编译:我们需要将“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
在 config/application.rb 中设置预编译为 false
config.assets.initialize_on_precompile = false
从 http://refinerycms.com/guides/heroku…
第一次 git Push 到 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
在 config/application.rb 中将预编译选项设置回 true
config.assets.initialize_on_precompile = true
从 http://refinerycms.com/guides/heroku…
将 config/application.rb 添加到 git 并提交(!!)
...如果不这样做,下一次推送将会失败
推送到heroku(证明这次成功了)
git push heroku master
在 Heroku 数据库上迁移和播种
heroku run rake db:migrate
heroku run rake db:seed
从 http://refinerycms.com/guides/heroku
准备好出发!
希望从这里您可以访问您的 RefineryCMS 页面,所有 Refinery CSS 和图像都能正确显示(无论是在管理屏幕上还是在“查看网站”时但仍处于登录状态)。
如果您使用 Refinery 菜单添加图像,您随后应该能够看到该图像添加到您的 AWS 存储桶中。我还没有缩略图。