Created
August 6, 2010 01:36
-
-
Save robdimarco/510683 to your computer and use it in GitHub Desktop.
Scripts to set up an EngineYard AppCloud that will use Amazon S3 as its assets host. These scripts will sync your public directory (including any cache files such as cached javascript) up to a bucket on S3 which can then be used as an asset host.
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
# EngineYard AppCloud before_symlink to copy public files to S3 | |
# lives in $RAILS_ROOT/deploy/before_symlink.rb | |
# | |
# Only need to run once | |
on_app_master do | |
aws_bucket = "<BUCKET_NAME>" | |
aws_access_key = "<YOUR ACCESS ID>" | |
aws_secret_key = "<YOUR SECRET KEY>" | |
# Generate all cache files | |
run "RAILS_ENV=#{environment} #{release_path}/script/generate_asset_cache_files.rb" | |
# Run the S3SYNC (http://www.s3sync.net/) | |
# gem install s3snc | |
# This exports over ssl all files in the public directory and makes the readable by the public | |
run "export AWS_ACCESS_KEY_ID=#{aws_access_key};export AWS_SECRET_ACCESS_KEY=#{aws_secret_key}; s3sync -s -p -v --progress --make-dirs -r #{release_path}/public #{aws_bucket}:" | |
end |
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
#!/usr/bin/env ruby | |
# Script resides at | |
# $RAILS_ROOT/script/generate_asset_cache_files.rb | |
# | |
# Big assist on this to Kyle Burton | |
# | |
require 'net/http' | |
require 'uri' | |
env = ENV['RAILS_ENV'] || "development" # Environment to run | |
# List of all URLs needed to generate all cached content that should be synced out to the asset host | |
urls = ["/"] | |
port = 3009 | |
# | |
# We need the retries as the Webrick server may not be ready right away | |
# | |
max_retries = 20 | |
cmd = "#{File.join(File.dirname(__FILE__))}/server -e #{env} -p #{port} -d" | |
puts "Starting Webrick with #{cmd}" | |
unless system(cmd) | |
raise "Problem booting webrick!" | |
end | |
try_count = 0 | |
urls.each do |url| | |
make_request = true | |
while make_request and try_count < max_retries do | |
begin | |
full_url = "http://localhost:#{port}#{url}" | |
puts "Getting url #{full_url}" | |
Net::HTTP.get_print URI.parse(full_url) | |
puts "Got url #{full_url}" | |
make_request=false | |
rescue Exception => e | |
puts "Errored...#{e.inspect}" | |
try_count += 1 | |
sleep 2 | |
end | |
end | |
end | |
res = `ps aux | grep [r]uby | grep [s]cript/server` | |
pid = res.split[1] | |
puts "Killing Webrick" | |
Process.kill "KILL", pid.to_i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment