Automate deployment of files to Amazon S3? - ruby-on-rails

I have a Rails project that I will be deploying to the spectacularly awesome Heroku.
I would really like to be able to automate pushing my resources to Amazon S3 automatically, resources in this case being my images, stylesheets and javascript.
Obviously I can write some sort of capistrano task to do this myself, but does anyone know of something that does this already?
Note: I don't need to be able to upload user-files to S3 as I do that already via paperclip. I am talking about the actual project files required to run the site.

I found a good article which actually explain about the method to minify, compress and upload the static conetents (js/css) to Amazon S3 using Capistrano script.
Check the article at http://www.makeurownrules.com/ruby-on-rails/minify-compress-synch-amazons3-capistrano
Cheers,
Kapil

I bumped into your question looking for the same answer. I have good experience with Jammit as an asset packager and I just bumped into a gem which can deploy to S3 and seems to perfectly fit your needs.
https://github.com/railsjedi/jammit-s3
Best,
Jeroen

I tried Jammit S3, but it didn't have the control I was looking for, so I wrote my own CLI script and just got around to publishing it:
https://github.com/bradt/git-deploy-s3

There is also capistrano-s3 gem which is similar to jammit-s3 but a bit simpler and framework agnostic.
It simply publish all files in your public folder to amazon s3 using capistrano so you may add custom hooks. Have a look at the doc here :
https://github.com/hooktstudios/capistrano-s3
I does not deal with CloudFront invalidations, but I plan on adding this feature.

Related

Rails offline development with CDN

I love to develop without the internet. But the problem is we cannot get image/css/javascript assets files by CDN.
I think the best way is
On development env, try to get such asset files from CDN first, and
If possible, use it and cache it
If impossible, use cache
Alternative is
Keep all such asset files in the repo too
Use them on development env, use CDN on production env
But implementing these takes a bit time and I believe many developers face this problem.
So I want to know your way to solve this problem. If any good gem, it's fantastic.
My env is Rails4 without assets pipeline nor turbolinks.

Heroku and Rich Editor - Clearing uploaded images

I'm using Rich Editor for my Ruby on Rails app. And I'm have a problem when I'm deploying my code to Heroku. When I'm deploy new code to Heroku, all old assets removes. Also, all uploaded images by Rich Editor too removes. Maybe, I'm forgot to set some settings?
Thanks!
There are multiple reasons for this kind of issue. Typically it is either has to do with the way Heroku precompiles the assets or that the CSS is not pointing to the proper file if the asset is stored on S3.
One such being this:
http://natashatherobot.com/rails-4-heroku-assets-not-found-css-image/
Another being this:
Can't get CSS working on Heroku using Rails 4 with bootstrap-sass gem
Edit
Okay. It looks like you need to change the way you are managing your assets.
One solution is to use S3. A good explanation on how to do that: https://devcenter.heroku.com/articles/s3
I haven't used this gem but it looks promising:
https://github.com/rumblelabs/asset_sync
Another solution is to keep your local asset file in synch with production. You could do this by pulling down a copy of your asset directory from heroku each time you do development.

What should i use for rails file attachment and jruby?

Normally I'd use carrierwave, but they do not officially support jruby, and I've been running in to bugs, possibly related. (https://github.com/jnicklas/carrierwave/issues/620, Image corruption on upload to s3, production only. (carrierwave, engineyard))
Have others had success here?
I'm considering trying out paperclip, but it looks like that may not be perfect either-- https://github.com/thoughtbot/paperclip/issues/100
Try dragonfly it's a really great library to manage you file attachment.
check out this guide, it's cake
http://webtempest.com/how-to-allow-image-uploads-in-rails-on-heroku/
It uses paperclip and amazon web s3 gems

CKEditor won't link files (backed by rails, mongoid, paperclip, s3)

I'm having issues with CKEditor. I can upload and insert pictures without issues, but when I try to do the same with files, the link to my file is set to something like javascript:void(0)/*130*/, with the number changing. This is happening on FF/Safari/Chrome.
My app runs on rails 3.1.3, using MongoDB/Mongoid as database/ODM, with paperclip for handling attachments and using S3 for hosting assets. When I explore my bucket I can see that the files are uploaded correctly, so the problem (probably) come from somewhere else. I'm using this gem, and both the rc2 & the master branch doesn't fix that.
Thanks for your time.
Well it's been a while. I solved it by forking the gem (cf ksol/ckeditor), but the diff is too obfuscated to remember what was wrong. Hopefully the original gem is working now.

uploading a file with rail - what is the best approach

I have a requirement of uploading a file to my disk through my webpage. Seems like I have two options
My requirement is specific that I will upload ONLY text files.
Using default rails methods to upload a file.
Ex: http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm
Using a plugin like 'PaperClip'
Following are my concerns:
I want to keep the file upload as simple as possible
Keep as away as dependencies like Imagemagic etc
I'm using rails 2.8.3
concurrent file uploads can be happen by multiple users
please can someone tell me what are the pros and cons of having
writing a simple file upload (option 1)
using a plugin/gem to upload a files
Writing your own file uploader is an option, but using a pre-built gem provides you with all of the code you need, straight after install.
Gems will usually have all of the functionality packaged into them that handles all of the cross-platform issues and security headaches your likely to run into by writing something from scratch. A well maintained gem will also have a good community behind it, keeping things up to date.
The popular Gems out there are really easy to use, and unless you are resizing images etc, you shouldn't need ImageMagick installed. Have a look at these:
http://railscasts.com/episodes/134-paperclip
https://github.com/technoweenie/attachment_fu/wiki
Paperclip is far easier to build a simple upload form with, but I'm not sure if it works on Rails 2. Attachment_fu is an old favorite from the Rails 2 days and will definitely be able to handle your problem, it just requires a little more configuration.

Resources