public
Created

Deploy to S3 - Asset Pipeline, S3 and Heroku

  • Download Gist
Deploy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
namespace :deploy do
desc "Deploy to Heroku"
task :heroku do
Rake::Task["deploy:precompile_assets_and_upload_to_s3"].invoke
Rake::Task["deploy:push_heroku"].invoke
end
 
desc "Precompile assets and upload to s3"
task :precompile_assets_and_upload_to_s3 do
storage = Fog::Storage.new :provider => 'AWS', :aws_access_key_id => "123", :aws_secret_access_key => "123"
bucket = storage.directories.get('bucket_name')
assets_folder = bucket.files.get('assets/')
 
if assets_folder
assets_folder.destroy
puts "[Deleted] assets/"
end
 
bucket.files.create :key => 'assets/', :public => true
system "RAILS_ENV=production rake assets:precompile"
Dir.glob(File.join(Rails.root, 'public', 'assets', '*')).each do |file|
new_file = bucket.files.new :key => "assets/#{File.basename(file)}", :body => File.open(file), :public => true
if new_file.save
puts "[Uploaded] #{File.basename(file)}"
else
puts "[Failed Upload] #{File.basename(file)}"
end
end
end
 
desc "Push master branch to heroku remote"
task :push_heroku do
puts "[Deploying] Heroku"
`git push heroku master`
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.