Created
April 23, 2012 13:36
-
-
Save alikhajeh1/2470967 to your computer and use it in GitHub Desktop.
Rake task to upload static website to AWS S3 using the s3cmd command-line tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
OUT_DIR = 'public' | |
desc 'Prepare and upload the static site to S3' | |
task :upload, [:name] do |t, args| | |
raise Exception.new('You must provide the name of site to upload to, e.g., be rake upload[www]') unless args[:name] | |
puts "Removing existing output directory" | |
FileUtils.rm_rf OUT_DIR if File.exists?(OUT_DIR) | |
Dir.mkdir OUT_DIR | |
puts "Compiling assets..." | |
`bundle exec rake assets:precompile RAILS_ENV=production` | |
puts "\n\n>>>>>>>>" | |
puts 'PLEASE kill any running rails servers, and start one in production mode like this:' | |
puts 'RAILS_ENV=production bundle exec rails s' | |
puts 'Press enter once the server has started:' | |
STDIN.gets | |
puts "Getting copy of static pages..." | |
Dir.chdir(OUT_DIR) do | |
['index', 'error', 'privacy'].each do |page| | |
`wget -m -nH http://localhost:3000/#{page}.html` | |
end | |
`cp ../favicon.ico .` | |
`cp ../robots.txt .` | |
`cp ../site_map.xml .` | |
puts "\n\nUploading site to S3, this will take a few minutes..." | |
`s3cmd put -r * s3://#{args[:name]}.MYSITE.COM/` | |
end | |
# Remove OUT_DIR otherwise users running in development mode won't see updated pages | |
FileUtils.rm_rf OUT_DIR if File.exists?(OUT_DIR) | |
puts "\n\nYou can now kill the rails server." | |
puts "-- DONE --" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment