Taking images out of SVN - ruby-on-rails

I have a bunch of images in SVN I would like to move out and put on S3. How have you dealt with keeping images out of your ruby on rails apps and out of SVN?

You don't have to put your images into your repository. You could still have them on your server, but it doesn't really matter where they're linked from. If you don't use any plugins to manage your assets then you can just remove them from your repository, upload all of them to S3 and update all links pointing to them.
If you do use some kind of plugin like paperclip or attachment_fu then you'll have to tell it where to find your files.

Related

Best AWS Storage Option for Exporting Directories as .zip Files?

I'm brand new to AWS products, ruby on rails, web development, and coding of any type. For my first project after a quick (and dirty) bootcamp, I'm trying to build a ruby-on-rails website that stores images and allows the user to download them as a zip file. I used the RubyZip gem to accomplish this in my EC2 dev environment, but I have deployed to Elastic Beanstalk with S3 file storage, and the RubyZip gem seems unable to handle this structure without traditional directory targets for zipping.
My question is what's the best setup to achieve this functionality in EB? Disregarding the ruby constraint, zipping an S3 directory seems tricky. Should I move to EFS or another storage system? I plan to erase the folders regularly, and limit them to ~100 photos, so long term and large size storage are not a concern. Thanks very much!
Edit: I am attached to Ruby (only language I know), but not RubyZip, AWS, or much of anything else if they are not the best approach for this task.
I think you're on the right path as far as using S3 as a solution. The problem that your facing is that when you're interacting with S3 it's not like a folder on your local system, instead you're hitting the S3 API to interact with the files. (upload, edit, delete ect). This will be a problem you'll encounter with every AWS based storage solution.
I think the solution, in your case, is to fetch all of the photos and download them to a temporary folder on your local system. Then, you could zip them using Ruby, locally. After it's zipped, upload it back to S3.
Edit: By locally I mean onto the server where the Ruby application is running (not client-side)

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.

Where should my images go in Rails? What does precompile do exactly?

I'm using Rails 3 with assets pipeline enabled.
And I know images such as icons or logos should go in app/assets/images.
But where should I put images that may be a lot and big? For example images uploaded by the users, such as photos
I don't want them to be duplicated by precompile (not sure if it does that, I don't know how it works). And I want them to be ready to use as soon as they get uploaded.
Any ideas?
The image_tag wasn't working as expected. In the documentation it says 'By default, files are loaded from public/images', but that wasn't working.
The solution was to add /images to the path (with leading backslash, or it won't work)
<%= image_tag '/images/some_dir/some_image.jpeg' %>
Amazon S3 is a great, inexpensive way to store images that your users upload. I recommend using the Paperclip gem which integrates with s3. There's a section in the paperclip documentation with instructions on how to use s3. No clue what precompiling images means or how it applies to uploaded image files, but they will be available as soon the upload is complete. Using this also has some additional benefits such as acting as a backup system.

Paperclip: migrating from file system storage to Amazon S3

I have a RoR website, where users can upload photos. I use paperclip gem to upload the photos and store them on the server as files. I am planning to move to Amazon S3 for storing the photos. I need to move all my existing photos from server to Amazon S3. Can someone tell me the best way for moving the photos. Thanks !
You'll want to log into your AWS Console and create a bucket structure to facilitate your images. Neither S3 nor Paperclip have any tools in the way of bulk migrations from file system -> s3, you'll need to use the tool s3cmd for that. In particular, you're interested in the s3cmd sync command, something along the lines of:
s3cmd sync ./public/system/images/ s3://imagesbucket
If you have any image urls hard-coded into your database (a la markdown/template code) this might be a little tricky. One option would be to manually update your urls to point to the new bucket. Alternatively, you can rack-rewrite.
You can easily do this by creating a bucket on Amazon S3 that has the same folder structure as your public directory on your Rails app.
So say for instance, you create a new bucket on Amazon S3 called MyBucket and it has a folder in it called images. You'd just move all of your images within your Rails app's images folder over to that new bucket's images folder.
Then you can set up your app to use an asset host like this answer describes: is it good to use S3 for Rails "public/images" and there an easy way to do it?
If you are using image_tag or other tag helpers (javascripts, stylesheets, etc), then it will use that asset_host for production environments and properly generate the URL to your S3 bucket.
I found this script which takes care of moving the images to Amazon S3 bucket using rake task.
https://gist.github.com/924617

Automate deployment of files to Amazon S3?

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.

Resources