Skip to content

Commit

Permalink
rpearce; Add new experimental diff command
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Pearce committed Jan 16, 2017
1 parent c4c075d commit 1ab1f07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bin/stacks
Expand Up @@ -40,6 +40,8 @@ Options:
clean [-e] -s shuts down and removes a stack, but retains configuration (puppet, nagios, mongo)
clean_all [-e] -s shuts down and removes a stack, puppet, nagios and mongo
compile create a yaml file describing the entire infrastructure
diff show compile diff between last commit and latest commit.
diff -sb show compile diff between latest stackbuilder and local stackbuilder.
enc [-e] -s print the enc of the specified stack. Stack must be a single fqdn. Used for debugging
spec [-e] -s print the spec of the specified stack. Stack must be a single fqdn. Used for debugging
ls [-est] show the entire environment. Show just one stack if -s is specified. If -t is specified,
Expand Down Expand Up @@ -69,6 +71,8 @@ Files:
Examples:
stacks compile > /tmp/enc_test
stacks diff > /tmp/diff
stacks diff -sb > /tmp/sb_diff
stacks -e test ls -s refapp
stacks -e test enc -s test-refapp-002.mgmt.st.net.local
Expand Down
17 changes: 16 additions & 1 deletion lib/stackbuilder/support/cmd.rb
Expand Up @@ -10,7 +10,7 @@
class CMD
attr_reader :cmds # this list is just a safety check
def initialize
@cmds = %w(audit compile ls lsenv enc spec clean clean_all provision reprovision terminus test)
@cmds = %w(audit compile diff ls lsenv enc spec clean clean_all provision reprovision terminus test)
end
include CMDAudit
include CMDLs
Expand All @@ -32,6 +32,21 @@ def compile(_argv)
puts ZAMLS.to_zamls(deep_dup_to_avoid_yaml_aliases(output))
end

def diff(argv)
diff_type = arg.shift if argv.size > 0
diff_tool = ENV['DIFF'] || '/usr/bin/sdiff -s'
sbc_path = ENV['STACKBUILDER_CONFIG_PATH'] || '.'

if diff_type == '-sb'
system("sudo apt-get install stackbuilder && stacks compile > /tmp/before")
system("rake package install && stacks compile > /tmp/after")
else
system("cd #{sbc_path} && git checkout HEAD~1 && stacks compile > /tmp/before")
system("cd #{sbc_path} && git checkout master && stacks compile > /tmp/after")
end
system("#{diff_tool} /tmp/before /tmp/after")
end

def terminus(_argv)
output = {}
$factory.inventory.environments.sort.each do |_envname, env|
Expand Down

0 comments on commit 1ab1f07

Please sign in to comment.