Permalink
Browse files

integrated Jack Chu’s cloud deployer (https://github.com/kamui/nanoc-…

  • Loading branch information...
1 parent 26d2ad1 commit e4c7f16ea0fbb8a59eac8d33591b83b1915540ec @ddfreyne committed Jul 14, 2011
Showing with 88 additions and 0 deletions.
  1. +5 −0 NEWS.md
  2. +1 −0 README.md
  3. +3 −0 lib/nanoc/extra/deployers.rb
  4. +79 −0 lib/nanoc/extra/deployers/fog.rb
View
@@ -1,5 +1,10 @@
# nanoc news
+## 3.3
+
+* Turned Rake tasks into proper nanoc commands
+* Added support for deployment using Fog [Jack Chu]
+
## 3.2 (???)
Base:
View
@@ -76,6 +76,7 @@ may be interested in the development dependencies:
* Dmitry Bilunov
* Devon Luke Buchanan
* Brian Candler
+* Jack Chu
* Michal Cichra
* Zaiste de Grengolada
* Vincent Driessen
@@ -4,7 +4,10 @@ module Nanoc::Extra
module Deployers
+ autoload 'Fog', 'nanoc/extra/deployers/fog'
autoload 'Rsync', 'nanoc/extra/deployers/rsync'
+
+ Nanoc::Extra::Deployer.register '::Nanoc::Extra::Deployers::Fog', :fog
Nanoc::Extra::Deployer.register '::Nanoc::Extra::Deployers::Rsync', :rsync
end
@@ -0,0 +1,79 @@
+# encoding: utf-8
+
+require 'fog'
+
+module Nanoc::Extra::Deployers
+
+ # TODO document
+ class Fog < ::Nanoc::Extra::Deployer
+
+ # @see Nanoc::Extra::Deployer#run
+ #
+ # @todo Allow dry runs
+ def run
+ # Get params
+ src = File.expand_path(self.source_path)
+ bucket = self.config[:bucket]
+ path = self.config[:path]
+
+ # Validate params
+ error 'No bucket found in deployment configuration' if bucket.nil?
+ error 'The path requires no trailing slash' if path && path[-1,1] == '/'
+
+ # Get connection
+ puts "Connecting"
+ connection = ::Fog::Storage.new(self.config)
+
+ # Get bucket
+ puts "Getting bucket"
+ begin
+ directory = connection.directories.get(bucket)
+ rescue ::Excon::Errors::NotFound
+ should_create_bucket = true
+ end
+ should_create_bucket = true if directory.nil?
+
+ # Create bucket if necessary
+ if should_create_bucket
+ directory = connection.directories.create(:key => bucket)
+ end
+
+ # Get list of remote files
+ files = directory.files
+ truncated = files.respond_to?(:is_truncated) && files.is_truncated
+ while truncated
+ set = directory.files.all(:marker => files.last.key)
+ truncated = set.is_truncated
+ files = files + set
+ end
+
+ # Delete all the files in the bucket
+ puts "Removing remote files"
+ files.all.each do |file|
+ file.destroy
+ end
+
+ # Upload all the files in the output folder to the clouds
+ puts "Uploading local files"
+ Dir.chdir(src)
+ files = Dir['**/*'].select { |f| File.file?(f) }
+ files.each do |file_path|
+ directory.files.create(
+ :key => "#{path}#{file_path}",
+ :body => File.open(file_path),
+ :public => true)
+ end
+
+ puts "Done!"
+ end
+
+ private
+
+ # Prints the given message on stderr and exits.
+ def error(msg)
+ raise RuntimeError.new(msg)
+ end
+
+ end
+
+end

0 comments on commit e4c7f16

Please sign in to comment.