Skip to content

Commit

Permalink
Adding erase_remote_folder and cache_remote_recipes preferences for c…
Browse files Browse the repository at this point in the history
…ustomized behavior. Empty attributes / recipes / files now work correctly.
  • Loading branch information
kenn committed Mar 8, 2012
1 parent 8c4efc5 commit 561020c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -18,6 +18,7 @@ Its design goals are:


### What's new: ### 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.6: System function sunzi::silencer() added for succinct log messages.
* v0.5: Role-based configuration supported. Reworked directory structure. **Incompatible with previous versions**. * v0.5: Role-based configuration supported. Reworked directory structure. **Incompatible with previous versions**.


Expand Down
20 changes: 13 additions & 7 deletions lib/sunzi/cli.rb
Expand Up @@ -52,7 +52,7 @@ def do_deploy(target, role)
endpoint = "#{user}@#{host}" endpoint = "#{user}@#{host}"


# compile attributes and recipes # compile attributes and recipes
compile(role) do_compile(role)


# The host key might change when we instantiate a new VM, so # The host key might change when we instantiate a new VM, so
# we remove (-R) the old host key from known_hosts. # we remove (-R) the old host key from known_hosts.
Expand All @@ -66,6 +66,8 @@ def do_deploy(target, role)
bash install.sh bash install.sh
EOS EOS


remote_commands.strip! << ' && rm -rf ~/sunzi' if @config['preferences'] and @config['preferences']['erase_remote_folder']

local_commands = <<-EOS local_commands = <<-EOS
cd compiled cd compiled
tar cz . | ssh -o 'StrictHostKeyChecking no' #{endpoint} -p #{port} '#{remote_commands}' tar cz . | ssh -o 'StrictHostKeyChecking no' #{endpoint} -p #{port} '#{remote_commands}'
Expand All @@ -92,18 +94,22 @@ def do_compile(role)
abort_with "#{role} doesn't exist!" if role and !File.exists?("roles/#{role}.sh") abort_with "#{role} doesn't exist!" if role and !File.exists?("roles/#{role}.sh")


# Load sunzi.yml # Load sunzi.yml
hash = YAML.load(File.read('sunzi.yml')) @config = YAML.load(File.read('sunzi.yml'))


# Break down attributes into individual files # 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 # 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 # Copy local files
Dir['recipes/*'].each {|file| copy_file File.expand_path(file), "compiled/recipes/#{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)}" } 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)}" } (@config['files'] || []).each {|file| copy_file File.expand_path(file), "compiled/files/#{File.basename(file)}" }


# Build install.sh # Build install.sh
if role if role
Expand Down
2 changes: 1 addition & 1 deletion lib/sunzi/version.rb
@@ -1,3 +1,3 @@
module Sunzi module Sunzi
VERSION = "0.6.0" VERSION = "0.7.0"
end end
10 changes: 10 additions & 0 deletions lib/templates/create/sunzi.yml
Expand Up @@ -14,3 +14,13 @@ recipes:
# Files specified here will be copied to compiled/files. # Files specified here will be copied to compiled/files.
files: files:
- ~/.ssh/id_rsa.pub - ~/.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.