Skip to content

Instantly share code, notes, and snippets.

@wonjun27
Forked from zooniverse/aws_bundle.rb
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wonjun27/fe7531c2c3349fc19af7 to your computer and use it in GitHub Desktop.
Save wonjun27/fe7531c2c3349fc19af7 to your computer and use it in GitHub Desktop.
Capistrano::Configuration.instance(:must_exist).load do
# example execution 'cap bundle_app -s version=HEAD'
desc "Bundle code and push to S3"
task :bundle_app do
puts "Starting Git archive of #{version}"
`git archive -o oldweather.tar #{version}`
`gzip oldweather.tar`
s3_upload
clean_up
end
desc "Upload file to S3"
task :s3_upload do
# need to have the aws/s3 gem
AWS::S3::Base.establish_connection!(
:access_key_id => 'YOURACCESSID',
:secret_access_key => 'YOURSECRETKEY'
)
# upload the new one
print "Uploading new one..."
AWS::S3::S3Object.store('oldweather_new.tar.gz', open('oldweather.tar.gz'), 'your-bucket')
print "done\n"
# rename the old file
puts "Renaming old code bundle"
AWS::S3::S3Object.rename "oldweather.tar.gz", "oldweather-#{Time.now.strftime('%H%M-%d%m%y')}.tar.gz", "your-bucket"
# rename the new file
AWS::S3::S3Object.rename "oldweather_new.tar.gz", "oldweather.tar.gz", "your-bucket"
end
desc "Clean up old files"
task :clean_up do
puts "Cleaning up"
`rm oldweather.tar.gz`
puts "All done!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment