Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/home/ec2-user/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
require 'rubygems'
require 'aws/s3'
require 'fileutils'
AWS::S3::Base.establish_connection!(
:access_key_id => 'access_key',
:secret_access_key => 'secret_key'
)
open('/home/ec2-user/tarred_code_download.tar.gz', 'w') do |file|
AWS::S3::S3Object.stream('tarred_code.tar.gz', 'bucket-name') do |chunk|
file.write chunk
end
end
# Log the download
File.open('/home/ec2-user/checkout.log', 'a') { |f| f.puts("Code updated #{Time.now}") }
# Remove the current code
`rm -rf /home/ec2-user/public_html/yourapp/current`
# Make a temporary directory for the unzipped code
FileUtils.mkdir('/tmp/source')
FileUtils.mkdir('/tmp/source/tarred_code')
# Extract code
`tar -C /tmp/source/tarred_code -xvzf /home/ec2-user/tarred_code_download.tar.gz`
# Move the new code to the apache dir
src_files = Dir.glob('/tmp/source/*')
new_dir = Time.now.strftime("%Y%m%d%H%M%S").to_s
`mv #{src_files.first} /home/ec2-user/public_html/yourapp/releases/#{new_dir}`
# Clean up old files
FileUtils.rm_r('/tmp/source')
FileUtils.rm('/home/ec2-user/tarred_code_download.tar.gz')
# make symlinks
`ln -s /home/ec2-user/public_html/yourapp/releases/#{new_dir} /home/ec2-user/public_html/yourapp/current`
`ln -s /home/ec2-user/public_html/yourapp/shared/log /home/ec2-user/public_html/yourapp/current/log`
`ln -s /home/ec2-user/public_html/yourapp/shared/database.yml /home/ec2-user/public_html/yourapp/current/config/database.yml`
`ln -s /home/ec2-user/public_html/yourapp/shared/site_settings.yml /home/ec2-user/public_html/yourapp/current/config/site_settings.yml`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment