Skip to content

Commit

Permalink
WIP on deployer for S3
Browse files Browse the repository at this point in the history
  • Loading branch information
moredip committed May 25, 2013
1 parent 15d65e4 commit ccbe91d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'http://rubygems.org'
gem "jekyll", "0.11.0"
gem "liquid", "~>2.2.2"

gem "aws-s3", "~> 0.6.3"
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ GEM
specs:
albino (1.3.3)
posix-spawn (>= 0.3.6)
aws-s3 (0.6.3)
builder
mime-types
xml-simple
builder (3.2.0)
classifier (1.3.3)
fast-stemmer (>= 1.0.0)
directory_watcher (1.4.1)
Expand All @@ -18,12 +23,15 @@ GEM
liquid (2.2.2)
maruku (0.6.0)
syntax (>= 1.0.0)
mime-types (1.23)
posix-spawn (0.3.6)
syntax (1.0.0)
xml-simple (1.1.2)

PLATFORMS
ruby

DEPENDENCIES
aws-s3 (~> 0.6.3)
jekyll (= 0.11.0)
liquid (~> 2.2.2)
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'aws/s3'
require_relative 'tasks/deploy_tasks.rb'

13 changes: 13 additions & 0 deletions tasks/deploy_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require_relative 'deployer'

PRODUCTION_AWS_BUCKET = "preview.testingwithfrank.com"

desc "deploy to production"
task :deploy do
aws_access_key_id = ENV.fetch('AWS_ACCESS_KEY_ID')
aws_secret_access_key = ENV.fetch('AWS_SECRET_ACCESS_KEY')

deployer = S3Deployer.new( aws_access_key_id, aws_secret_access_key )
deployer.upload_dir( File.expand_path("../../public",__FILE__), PRODUCTION_AWS_BUCKET )
end

31 changes: 31 additions & 0 deletions tasks/deployer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'aws/s3'
require 'yaml'

# All of this courtesy Giles Alexander (@gga)
class S3Deployer
include Rake::DSL

def initialize( access_key_id, secret_access_key )
@access_key_id, @secret_access_key = access_key_id, secret_access_key
end

def upload_dir(dir, bucket)
AWS::S3::Base.establish_connection!(:access_key_id => @access_key_id,
:secret_access_key => @secret_access_key)
cd dir do
upload_sub_dir('.', bucket)
end
end

def upload_sub_dir(dir, bucket)
Dir["#{dir}/*"].each do |file|
if File.directory? file
upload_sub_dir(file, bucket)
else
file_name = file.gsub("./", '')
puts "Uploading: '#{file_name}'"
AWS::S3::S3Object.store(file_name, open(file), bucket)
end
end
end
end

0 comments on commit ccbe91d

Please sign in to comment.