Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Deploy to S3 - Asset Pipeline, S3 and Heroku
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.