Rails way to store heroku app assets on amazon cloud

Looking at the fact that my rails application on heroku uses amazon, everything can (assets, database, download).

assets listen to me the most ... Heroku help files are said to create a bucket to dump files and link as: http://s3.amazonaws.com/bucketname/filename . This gives me two development options (what can I come up with):

  • Can I have .gitignore not look at assets for local development and make sure I upload these files to my AWS bucket after clearing all the links or writing an assistant?
  • Always save everything in your bucket and be forced to call my bucket during local development.

I am wondering if I can configure this so that I can locally store application assets in the application / assets folder and does it automatically drag assets to Amazon when clicking / deploying to a hero?

This is my first geelu rails app with Amazon, so feel free to offend my intellect about how this stuff should be set up and the right workflow.

Thanks.

+4
source share
2 answers

Try asset_sync gem . This allows you to do exactly what you want: use the resource pipeline locally, and then serve assets from S3 (optionally through Cloudfront) after clicking on Heroku.

Note that the Heroku compilation step usually does not provide access to configuration variables, and you need these configuration variables for asset_sync to click on S3. The solution for this (and actually the full asset_sync resource) is published in Using CDN Asset Host with Rails 3.1 .

The disadvantage of this approach is that it violates some of the 12 application factors - in particular, it relates to "assembly, release, running." This has some negative consequences: for example, heroku releases:rollback will roll back your application, but will not recompile and reload your assets.

+2
source

In Rails 3, you can use the Rails Resource Pipeline for various configurations for assets. Basically in your config/environments/production.rb file you do something like:

  ActionController::Base.asset_host = "/path/to/s3/bucket" 

Locally, you will continue to serve assets directly from the Rails server. As for deployment, you can write a rake task using the aws-s3 gem, or I think you should automate it with capistrano . Another option is to use the CDN and configure it to search for assets on your production server, so you do not need to deploy them separately.

0
source

Source: https://habr.com/ru/post/1442572/


All Articles