Git Push to Amazon S3 for Deploying Assets? - ruby-on-rails

Can you install git on Amazon and push assets (js, css, img) easily? Something like Heroku but with assets and S3 would be awesome.
Some people seem to use JungleDisk to sync a local git directory to s3, but that's too bulky. I tried installing jgit on a mac but to no avail, and that thing looks ancient. Is there anything else or does this type of thing just not work?
I've tried most of the gems out there for heroku asset deployment/optimization, but they all either require you to host them on heroku, or to run a rake task, which is not ideal.

You can use s3cmd --sync LOCAL s3://BUCKET/PREFIX to accomplish this. It is best if each asset has a version number in its name. Otherwise you can have weird issues such as the browser caching version 1 of the CSS and using version 2 of the JavaScript, causing undefined behavior.

How about setting up an EC2 image, mounting the s3 image on there and setting up a bare git repository to push to on said S3 image?

Tools recommend by other answers are out of date.
This one is up to date: https://github.com/schickling/git-s3

See Jammit s3, it's a great solution (zip + cloud):
https://github.com/railsjedi/jammit-s3

The problem with Jammit s3 is that you cannot manage versions of your files properly. It might take end users a while until they get the most update to date JS/CSS file.
You might find this useful, in case you use PHP for your application (otherwise this code can be adapted to your needs): https://github.com/SupersonicAds/git-hook-php-s3-files-revisions

Jammit S3 didn't have the control I was looking for, so I wrote my own CLI script:
https://github.com/bradt/git-deploy-s3

Related

Is there a way to asset pipeline assets to s3 when pushing to heroku?

Is there an easy way to you this with the asset pipeline and deploying to heroku / s3?
I would like my local rails app to use image/css/js locally as per normal.
And when you pre-compile, is there an easy way for the production app to serve it's assets from s3 (while dev assets are local). And also when you pre-compile / deploy to heroku, the newly compiled assets are sent up to s3 automatically?
This is so the developer (me :D ) does not have to keep manually updating s3 with the new deployed files?
Thanks.
I believe this is what you're looking for:
http://ckdake.com/content/2011/rails-31-assets-on-s3-with-https.html
Make sure you use up-to-date gems, as this guide is for rails 3.1 (in case you use 3.2+)
Heroku has good docs on this now, here:
https://devcenter.heroku.com/articles/cdn-asset-host-rails31
Which recommends this gem:
https://github.com/rumblelabs/asset_sync

Have anyone use gollum-site to generete markdown wikis and host it on heroku?

Hi i have tried using gollum-site gem, but it seems to only generate the site on localhost:8000 by default. How can i get the markdown wiki hosted on heroku. Anyone tried doing it before ?
There was a thread on this a while ago. It looks like it isn't possible because of Heroku's readonly filesystem and the fact that you don't have access to git.
So, the solution will be to clone the repo to temporary path, work there and push changes to the remote repo. There is a much overhead: you need to clone repo every time a user browse a wiki page. — Vanuan
There is GitHub repository: heroku-buildpack-gollum-site that seem to do just what you want. It uses a modified version
of heroku-buildpack-php to install an Apache pack to heroku.
The answers targeted to Gollum are not appropriate, as here any server can serve the static generated site. No need to host Gollum (or Gollum-site) itself.
The question is old now, but some people can still need the answer!

Downloading the source of my Heroku site from Heroku?

I built a Ruby on Rails application that is running on Heroku.
For reasons currently unknown to me, the page formatting of my web app has gotten a bit messed up on my local source code, and I'd like to download the not-messed-up copy from Heroku, and work with that instead.
Is there any way to do this? Thanks in advance.
By the way, I tried downloading the CSS files from the Heroku hosted site, and it still doesn't look right.
You will need to clone it:
git clone git#heroku.com:your-app.git

Using S3/CloudFront with Rails 3 Assets and Less CSS

This one is a mouthful! Basically I'm trying to send all of my Rails 3 assets up to the S3 Cloud and use CloudFront as the CDN to deliver it all. I already learned about configuring Rails to pull from an asset server in production mode. The problem I'm running into is finding a good way to automatically package and send everything to the cloud from a rake command or rails gem. The other problem I have is I don't know if using Less CSS with the More gem is going to screw this up. More generates a CSS file from another directory and places it in public/stylesheets. Any ideas or suggestions are much appreciated! Thanks :)
If you are pushing to Heroku and are using the Rails 3.1 assets you are all set.
In the CloudFront configuration on amazon create your distribution and set the origin to your applications URL.
Then in your production.rb file add:
config.action_controller.asset_host = "xxxxxxxxx.cloudfront.net"
The host is the host of your CloudFront distribution.
Then when you deploy make sure you are on the Cedar stack and that assets are being compiled. This will add a unique MD5 into the filenames. When a request is made to your CDN (handled automatically by the setting in your production.rb file), then the CDN will either serve up it's version of the file or pull it from the origin first. This means you don't have to push files up to the CDN, they are pulled in automatically.
If you have a file that doesn't have a unique name for some reason, then you will need to look at how to invalidate the cache in CloudFront, but other than that it's pretty easy.

Rails + Heroku + Jammit

I'm working to install Jammit on my Rails 3 app and then to deploy to Heroku.
I installed the Jammit Gem, and configured assets.yml just fine, it works on dev. But when I pushed to heroku, the files were 404'ing.
Jammit's Usage instructions say: "You can easily use Jammit within your Rakefile, and other scripts:
require 'jammit'
Jammit.package!
I'm not following where/how that works. Running Jammit in my sites command like on the Mac yields a command not found.
Any Jammit users able to help me understand how to move to production with Jammit?
Thanks
I'm using jammit on a Rails 3.0.7 app, on Heroku
gem "jammit", :git => "git://github.com/documentcloud/jammit.git"
I have this in a rake file, to package up the assets before I commit/deploy
desc 'jammit'
task :jam => :environment do
require 'jammit'
Jammit.package!
end
And this in .git/hooks/pre-commit so it is done automatically
echo "jamming it"
rake jam
git add public/assets/*
git add public/javascripts/*
By default, the expires time on Heroku was only 12hrs, to increase it (because I have a cache-busting scheme that I am confident in) I put this in config/initializers/heroku.rb
module Heroku
class StaticAssetsMiddleware
def cache_static_asset(reply)
return reply unless can_cache?(reply)
status, headers, response = reply
headers["Expires"] = CGI.rfc1123_date(11.months.from_now)
build_new_reply(status, headers, response)
end
end
end
To decrease the load on my Heroku Rails server, I am also using a free account at CloudFlare which provides a lightweight, reverse-proxy/cdn, with some decent analytics and security features.
When I get around to caching common content, this thing is really gonna scream!
You could, as I do, use jammit force to pack your assets, upload everything to s3 and define an asset host(s) in rails. This has the added advantage of keeping your slug smaller and more responsive as you can add your public directory to .slugignore .
Alternatively you'll need to work out how to make the heroku version work due to the read only file system.
You can also use a git pre-commit hook to ensure your assets are packaged prior to pushing to heroku (or any server). See https://gist.github.com/862102 for an example. You can copy that file to .git/hooks/pre-commit in your project directory.
this one is the solution
https://github.com/kylejginavan/heroku_jammit
Heroku has a read-only file system, so Jammit is unable to actually store compressed and minified CSS/JS files.
Here is a very good article on the challenge of asset packaging on heroku: http://jimmycuadra.com/posts/the-challenge-of-asset-packaging-on-heroku

Resources