Skip to content

Instantly share code, notes, and snippets.

@andoriyu
Created April 12, 2011 00:26
Show Gist options
  • Select an option

  • Save andoriyu/914672 to your computer and use it in GitHub Desktop.

Select an option

Save andoriyu/914672 to your computer and use it in GitHub Desktop.
Upload static site generated by jekyll to Amazon S3.
#!/usr/bin/env ruby
require 'fog'
PROVIDER='AWS'
AWS_BUCKET_NAME='NAME'
ROOT='/path/to/_site'
Dir.chdir(ROOT)
storage = Fog::Storage.new(:provider => PROVIDER)
bucket = storage.directories.get(AWS_BUCKET_NAME)
# First upload all files from _site derectory
Dir.glob('*.*').each do |file|
bucket.files.create(:key => file, :body => File.open(file), :public => true)
end
# Then, upload subfolders and files
Dir.glob("**/").each do |dir|
bucket.files.create(:key => dir)
Dir.glob(dir + '*.*').each do |file|
bucket.files.create(:key => file, :body => File.open(file), :public => true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment