Permalink
Browse files

Adding erase_remote_folder and cache_remote_recipes preferences for c…

…ustomized behavior. Empty attributes / recipes / files now work correctly.
  • Loading branch information...
1 parent 8c4efc5 commit 561020c4a3f957d0226c3e1c0f134344d3c73816 @kenn committed Mar 8, 2012
Showing with 25 additions and 8 deletions.
  1. +1 −0 README.md
  2. +13 −7 lib/sunzi/cli.rb
  3. +1 −1 lib/sunzi/version.rb
  4. +10 −0 lib/templates/create/sunzi.yml
View
@@ -18,6 +18,7 @@ Its design goals are:
### What's new:
+* v0.7: Added `erase_remote_folder` and `cache_remote_recipes` preferences for customized behavior.
* v0.6: System function sunzi::silencer() added for succinct log messages.
* v0.5: Role-based configuration supported. Reworked directory structure. **Incompatible with previous versions**.
View
@@ -52,7 +52,7 @@ def do_deploy(target, role)
endpoint = "#{user}@#{host}"
# compile attributes and recipes
- compile(role)
+ do_compile(role)
# The host key might change when we instantiate a new VM, so
# we remove (-R) the old host key from known_hosts.
@@ -66,6 +66,8 @@ def do_deploy(target, role)
bash install.sh
EOS
+ remote_commands.strip! << ' && rm -rf ~/sunzi' if @config['preferences'] and @config['preferences']['erase_remote_folder']
+
local_commands = <<-EOS
cd compiled
tar cz . | ssh -o 'StrictHostKeyChecking no' #{endpoint} -p #{port} '#{remote_commands}'
@@ -92,18 +94,22 @@ def do_compile(role)
abort_with "#{role} doesn't exist!" if role and !File.exists?("roles/#{role}.sh")
# Load sunzi.yml
- hash = YAML.load(File.read('sunzi.yml'))
+ @config = YAML.load(File.read('sunzi.yml'))
# Break down attributes into individual files
- hash['attributes'].each {|key, value| create_file "compiled/attributes/#{key}", value }
+ (@config['attributes'] || []).each {|key, value| create_file "compiled/attributes/#{key}", value }
# Retrieve remote recipes via HTTP
- hash['recipes'].each {|key, value| get value, "compiled/recipes/#{key}.sh" }
+ cache_remote_recipes = @config['preferences'] && @config['preferences']['cache_remote_recipes']
+ (@config['recipes'] || []).each do |key, value|
+ next if cache_remote_recipes and File.exists?("compiled/recipes/#{key}.sh")
+ get value, "compiled/recipes/#{key}.sh"
+ end
# Copy local files
- Dir['recipes/*'].each {|file| copy_file File.expand_path(file), "compiled/recipes/#{File.basename(file)}" }
- Dir['roles/*'].each {|file| copy_file File.expand_path(file), "compiled/roles/#{File.basename(file)}" }
- hash['files'].each {|file| copy_file File.expand_path(file), "compiled/files/#{File.basename(file)}" }
+ Dir['recipes/*'].each {|file| copy_file File.expand_path(file), "compiled/recipes/#{File.basename(file)}" }
+ Dir['roles/*'].each {|file| copy_file File.expand_path(file), "compiled/roles/#{File.basename(file)}" }
+ (@config['files'] || []).each {|file| copy_file File.expand_path(file), "compiled/files/#{File.basename(file)}" }
# Build install.sh
if role
View
@@ -1,3 +1,3 @@
module Sunzi
- VERSION = "0.6.0"
+ VERSION = "0.7.0"
end
@@ -14,3 +14,13 @@ recipes:
# Files specified here will be copied to compiled/files.
files:
- ~/.ssh/id_rsa.pub
+
+# Fine tune how Sunzi should work.
+preferences:
+ # Erase the generated folder on the server after deploy.
+ # Turn on when you are done with testing and ready for production use.
+ erase_remote_folder: false
+
+ # Skip retrieving remote recipes when local copies already exist. This setting helps
+ # iterative deploy testing considerably faster, when you have a lot of remote recipes.
+ cache_remote_recipes: false

0 comments on commit 561020c

Please sign in to comment.