Permalink
Browse files

Use a git repository for file tracking.

  • Loading branch information...
jeremyboles committed Dec 7, 2012
1 parent 0c93ec6 commit 299612aeea458d7ea60a72ccc50852f211a6976e
Showing with 112 additions and 244 deletions.
  1. +3 −1 Gemfile
  2. +1 −3 ale.gemspec
  3. +1 −0 bin/ale
  4. +0 −2 lib/ale.rb
  5. +0 −156 lib/ale/bucket.rb
  6. +19 −12 lib/ale/cli.rb
  7. +1 −10 lib/ale/config.rb
  8. +1 −1 lib/ale/content_type.rb
  9. +0 −15 lib/ale/dns.rb
  10. +12 −2 lib/ale/site.rb
  11. +74 −34 lib/ale/uploader.rb
  12. +0 −8 lib/templates/website_configuration.xml
View
@@ -1,2 +1,4 @@
source 'http://rubygems.org'
-gemspec
+gemspec
+
+gem 'aws-sdk', github: 'jeremyboles/aws-sdk-for-ruby'
View
@@ -18,10 +18,8 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.require_paths = ['lib']
- s.add_dependency('crack', '~> 0.3.1')
- s.add_dependency('dnsimple-ruby', '~> 1.3.2')
+ s.add_dependency('aws-sdk', '~> 1.7.1')
s.add_dependency('grit', '~> 2.5.0')
s.add_dependency('mime-types', '~> 1.16')
- s.add_dependency('net-http-persistent', '~> 2.1')
s.add_dependency('thor', '~> 0.14.6')
end
View
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
$:.push File.expand_path("../../lib", __FILE__)
+$:.push File.expand_path("/Users/jeremyboles/Code/Ruby/aws-sdk-for-ruby/lib", __FILE__)
require 'ale'
Ale::CLI.start
View
@@ -1,9 +1,7 @@
module Ale
- autoload :Bucket, 'ale/bucket'
autoload :CLI, 'ale/cli'
autoload :Config, 'ale/config'
autoload :ContentType, 'ale/content_type'
- autoload :DNS, 'ale/dns'
autoload :Site, 'ale/site'
autoload :Uploader, 'ale/uploader'
View
@@ -1,156 +0,0 @@
-require 'base64'
-require 'crack'
-require 'net/http/persistent'
-require 'time'
-
-module Ale
- class Bucket
- attr_reader :name
-
- # Create an return a new bucket.
- #
- def self.create(name)
- self.new(name).tap {|bucket| bucket.create }
- end
-
- def initialize(name)
- @name = name
- end
-
- # Creates the bucket on S3. It does not throw an error if the bucket
- # already exsists.
- #
- def create
- request = Net::HTTP::Put.new(uri.request_uri)
- request.add_field('x-amz-acl', 'private')
- send(uri, request)
- end
-
- # Allows the bucket to be used to host websites.
- #
- def enable_website
- uri = uri(query: 'website')
- request = Net::HTTP::Put.new(uri.request_uri)
- request.body = File.read(File.expand_path('../../templates/website_configuration.xml', __FILE__))
- send(uri, request)
- end
-
- # Returns true of the bucket exsists on S3.
- #
- def exists?
- request = Net::HTTP::Head.new(uri.request_uri)
- send(uri, request) do |response|
- return response.class == Net::HTTPOK
- end
- end
-
- # Return the name of the host for accessing the bucket.
- #
- def host_name
- "#{name}.s3-website-us-east-1.amazonaws.com"
- end
-
- # Returns an array of all of the objects in the bucket.
- #
- def objects
- uri = uri(prefix: 'prefix=/')
- request = Net::HTTP::Get.new(uri.request_uri)
- send(uri, request) do |response|
- list = Crack::XML.parse(response.body)
- # Make sure we're returning an Array.
- return [] if list['ListBucketResult'].nil?
- return [list['ListBucketResult']['Contents']].flatten.compact
- end
- end
-
- # Removes an object form the bucket.
- #
- def remove(key)
- uri = uri(key)
- request = Net::HTTP::Delete.new(uri.request_uri)
- send(uri, request)
- end
-
- # Uploads a file to the specified key on S3.
- #
- def upload(file, key, content_type, permissions = 'private')
- uri = uri(key)
- file = File.open(file, 'rb')
- request = Net::HTTP::Put.new(uri.request_uri)
- request.add_field('Cache-Control', 'max-age=31536000')
- request.add_field('Content-Length', file.size)
- request.add_field('Content-Type', content_type)
- request.add_field('x-amz-acl', permissions)
-
- today = Date.today
- expires = Date.new(today.year + 1, today.month, today.day)
- request.add_field('Expires', expires.strftime('%a, %d %b %Y 00:00:00 GMT'))
-
- if should_compress_content?(content_type)
- stream = StringIO.new
- gz = Zlib::GzipWriter.new(stream)
- gz.write(file.read)
- gz.close
-
- request.add_field('Content-Encoding', 'gzip')
- request.body = stream.string
- else
- request.body_stream = file
- end
- send(uri, request)
- end
-
- private
-
- def should_compress_content?(content_type)
- content_type.include?('application/javascript') ||
- content_type.include?('text/css') ||
- content_type.include?('text/html')
- end
-
- # Creates an authorization string for the request.
- # http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html
- #
- def authorization(uri, request)
- string_to_sign = "#{request.class::METHOD}\n"
- string_to_sign << "\n"
- string_to_sign << "#{request['Content-Type']}\n"
- string_to_sign << "#{request['Date']}\n"
-
- amz_headers = request.to_hash.collect {|h,v| "#{h}:#{v.join(',')}" if h =~ /x-amz-/ }.compact.sort
- string_to_sign << amz_headers.join("\n") << "\n" unless amz_headers.empty?
-
- string_to_sign << uri.request_uri
-
- digest = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), Ale::Config.amazon_secret_access_key, string_to_sign)
- signature = Base64.encode64(digest).chomp
-
- "AWS #{Ale::Config.amazon_access_key_id}:#{signature}"
- end
-
- # Helps construct URIs for interacting the S3's REST API.
- #
- def uri(options_or_path = {}, options = {})
- if options_or_path.is_a?(Hash)
- options, path = options_or_path, '/'
- else
- path = options_or_path
- end
- path = URI.escape(path.sub(/^\//, ''))
- URI::HTTP.build(options.merge(host: 's3.amazonaws.com', path: "/#{name}/#{path}"))
- end
-
- def connection
- @_connection ||= Net::HTTP::Persistent.new("ale/#{name}")
- end
-
- # Send a request object to the URI passed in.
- #
- def send(uri, request, &block)
- request.add_field('Content-Type', 'application/x-www-form-urlencoded') unless request.key?('content-type')
- request.add_field('Date', Time.now.utc.rfc822)
- request.add_field('Authorization', authorization(uri, request))
- connection.request(uri, request, &block)
- end
- end
-end
View
@@ -4,22 +4,26 @@ module Ale
class CLI < Thor
include Thor::Actions
- default_task :upload
+ default_task :deploy
- desc 'build', 'Prepares the site for upload, if you using a static site generator'
- method_option 'generator', :type => :string, :banner =>
- 'Specify which static site generator to use. Use this if it is not automatically detecting.'
+ desc 'build', 'If the site uses a static site generator, builds the site'
def build
opts = options.dup
-
- say("Building site in #{Ale.root}")
+
+ Ale.alefile = opts[:alefile]
+ Ale::Config.load(Ale.alefile)
+
+ say("Building site in #{site.directory}")
+ site.build
rescue AlefileNotFound
say('Count not locale Alefile', :red)
end
- desc 'clean', 'Removes the files created during the build'
- def clean
- say('Cleaning up')
+ desc 'deploy', 'Builds the site and then uploads the new files'
+ def deploy
+ say('Preparing for deploy...')
+ invoke :build
+ invoke :upload
end
desc 'init', 'Generates a simple Alefile, placed in the current directory'
@@ -40,7 +44,10 @@ def setup
Ale::Config.load(Ale.alefile)
say("Setting up website for bucket: #{Ale::Config.bucket}")
- uploader.setup!
+ uploader.setup_bucket
+
+ say("Setting up git repository for file tracking")
+ uploader.setup_git_repo
rescue AlefileNotFound
say('Count not locale Alefile', :red)
rescue BucketNotSpecified
@@ -56,8 +63,8 @@ def upload
Ale.alefile = opts[:alefile]
Ale::Config.load(Ale.alefile)
- say("Uploading site in #{uploader.site.directory}")
- uploader.upload!
+ say("Uploading site in #{site.directory}")
+ uploader.upload
rescue AlefileNotFound
say('Count not locale Alefile', :red)
rescue BucketNotFound
View
@@ -1,11 +1,10 @@
-require 'aws-sdk'
+require 'aws'
module Ale
module Config
class << self
attr_accessor :bucket
attr_writer :amazon_access_key_id, :amazon_secret_access_key
- attr_writer :dnsimple_password, :dnsimple_username
attr_writer :ignored_files, :public_files, :private_files
attr_writer :upload_strategy
@@ -29,14 +28,6 @@ def amazon_secret_access_key
@amazon_secret_access_key || ENV['AMAZON_SECRET_ACCESS_KEY']
end
- def dnsimple_password
- @dnsimple_password || ENV['DNSIMPLE_PASSWORD']
- end
-
- def dnsimple_username
- @dnsimple_username || ENV['DNSIMPLE_USERNAME']
- end
-
def ignored_files
@ignored_files ||= []
@ignored_files
View
@@ -17,7 +17,7 @@ def self.for(path)
@@content_types[extension] || MIME::Types.of(path)
end
- add :mp4, 'video/mp4'
+ add :mp4, 'video/mp4'
add :webm, 'video/webm'
end
end
View
@@ -1,15 +0,0 @@
-require 'dnsimple'
-
-module Ale
- class DNS
- def self.setup(domain, host)
- DNSimple::Client.username = Ale::Config.dnsimple_username
- DNSimple::Client.password = Ale::Config.dnsimple_password
-
- DNSimple::Domain.create(domain).tap do |d|
- DNSimple::Record.create(d, '', 'ALIAS', host)
- DNSimple::Record.create(d, 'www', 'URL', domain)
- end
- end
- end
-end
View
@@ -24,12 +24,22 @@ def initialize(directory)
@private_files = ['Alefile']
@public_files = ['*', '*/*']
end
+
+ def build; end
end
- class Middleman < Base
+ class Jekyll < Base
end
- class Jekyll < Base
+ class Middleman < Base
+ def initialize(directory)
+ super(directory)
+ @directory = "#{@directory}/build"
+ end
+
+ def build
+ `middleman build`
+ end
end
end
end
Oops, something went wrong.

0 comments on commit 299612a

Please sign in to comment.