Permalink
Browse files

Modify for use by OSL

  • Loading branch information...
1 parent 009c146 commit ae1e08f303dc996b33ab56e782134af69f8419d5 Mike Cooper committed Mar 29, 2012
Showing with 49 additions and 63 deletions.
  1. +42 −53 puppetsubsync
  2. +7 −10 puppetsubsync-githook
View
@@ -62,7 +62,7 @@ class PuppetSync
end
def run
- unless parsed_options?
+ unless parsed_options?
abort "ERROR: invalid arguments given."
end
unless arguments_valid?
@@ -71,21 +71,20 @@ class PuppetSync
puts ".------------------------------------------------ Puppet-Sync ---"
puts "| Host : #{Socket.gethostbyname(Socket.gethostname).first}"
- puts "| Submodule : #{@options.submodule}"
puts "| Branch : #{@options.branch}"
- puts "| Deploy To : #{deploy_directory(@options.submodule, @options.branch)}"
- puts "| environment : #{env_directory(@options.submodule, @options.branch)}"
- puts "| to test : puppet agent --noop --test --environment=#{env_directory(@options.submodule, @options.branch)}"
+ puts "| Deploy To : #{@options.deploy}/#{@options.branch}"
+ puts "| environment : #{@options.branch}"
+ puts "| to test : puppet agent --noop --test --environment=#{env_directory(@options.branch)}"
puts "| repository : #{@options.repository}"
puts "| delete branch" if @options.delete
- self.update(@options.submodule,@options.branch, :delete => @options.delete)
+ self.update(@options.branch, :delete => @options.delete)
puts "`----------------------------------------------------------------\n"
end
- def update(submodule, branch, opts={})
- deploy = deploy_directory(submodule, branch)
+ def update(branch, opts={})
+ deploy = deploy_directory(branch)
if File.exists?(deploy) and not File.exists?("#{deploy}/#{STAMP}")
raise "error: environment directory is not managed by puppet-sub-sync."
@@ -107,7 +106,7 @@ class PuppetSync
Dir.chdir(deploy) do
git(:fetch, 'origin')
git(:reset, '--hard')
- git(:checkout, "origin/production")
+ git(:checkout, "origin/master")
git(:submodule, 'sync')
git(:submodule, 'foreach --recursive "git checkout -f head"')
git(:submodule, 'foreach --recursive "git clean -d -x -f"')
@@ -117,7 +116,7 @@ class PuppetSync
FileUtils.touch(STAMP)
end
end
- git_submodule(:checkout, submodule, deploy, branch) if not @options.delete
+ git_submodule(:checkout, deploy, branch) if not @options.delete
rescue => exception
puts exception.message
puts exception.backtrace if @options.verbose
@@ -134,39 +133,42 @@ class PuppetSync
end
end
- def git_submodule(subcommand, submodule, deploy, branch)
+ def git_submodule(subcommand, deploy, branch)
case subcommand.to_sym
when :checkout
-
- submodules = []
- current_module = []
- puts "Using gitmodules file: #{deploy}/.gitmodules" if @options.verbose
- File.open("#{deploy}/.gitmodules").each do |line|
- current_module += [line]
- if current_module.length == 3
- submodules += [current_module]
- current_module = []
+ submodules = [deploy]
+ submodules.each do |repo|
+ Dir.chdir(repo)
+ # Check for out target branch (if it exists)
+ git(:branch, "-a").each do |b|
+ # Check for the branch, either local or remote.
+ if b =~ /(remotes\/origin\/)?#{branch}/
+ # Clean up, get new code, and make everything shiny.
+ git(:fetch, 'origin')
+ get(:reset, '--hard')
+ git(:checkout, b)
+ git(:submodule, 'sync')
+ git(:submodule, 'foreach --recursive "git checkout -f head"')
+ git(:submodule, 'foreach --recursive "git clean -d -x -f"')
+ git(:submodule, 'update --init --recursive')
+ git(:clean, '-d -x -f')
+ # Don't look at anymore branches on this repo
+ break
+ end
+ end
+
+ # Get any submodules
+ puts "Parsing gitmodules file: #{repo}/.gitmodules" if @options.verbose
+ current_module = []
+ File.open("#{repo}/.gitmodules").each do |line|
+ current_module << line
+ if current_module.length == 3
+ # Grab module path from config file.
+ current_module[1] ~= /\s*path\s*=\s*(.*)$/
+ submodules += "#{repo}/#{$1}"
+ current_module == []
+ end
end
- end
- key_submodule = []
- submodules.each do |sub|
- key_submodule = sub if not sub.grep(/#{submodule}/).empty?
- puts "Parsing submodule: #{sub}" if @options.verbose
- end
- puts "Submodule root: #{key_submodule[1]}" if @options.verbose
- submodule_path = key_submodule[1].split(" ").last
- puts "cd into: submodule path: #{submodule_path}" if @options.verbose
- Dir.chdir("#{deploy}/#{submodule_path}") do
- git(:fetch, 'origin')
- git(:reset, '--hard')
- git(:checkout, "origin/#{branch}")
- git(:submodule, 'sync')
- git(:submodule, 'foreach --recursive "git checkout -f head"')
- git(:submodule, 'foreach --recursive "git clean -d -x -f"')
- git(:submodule, 'update --init --recursive')
- git(:clean, '-d -x -f')
- puts "touch: #{STAMP}" if @options.verbose
- FileUtils.touch(STAMP)
end
else
abort "error"
@@ -192,14 +194,6 @@ class PuppetSync
return result[:all].join
end
- def deploy_directory(submodule, branch)
- return "#{@options.deploy}/#{submodule.gsub("-","_")}_#{branch}"
- end
-
- def env_directory(submodule, branch)
- return "#{submodule.gsub("-","_")}_#{branch}"
- end
-
def parsed_options?
opts = OptionParser.new
@@ -221,11 +215,6 @@ class PuppetSync
@options.repository = repo
end
- opts.on('-s', '--submodule SUBMODULE', 'Mandatory, specify the git submodule to track.') do |submodule|
- @options.submodule = submodule
- end
-
-
opts.separator "Common options:"
opts.on('-V', '--version', 'Display the script version.') { output_version ; exit 0; }
opts.on('-v', '--verbose', 'Be more verbose.') { @options.verbose = true }
View
@@ -1,35 +1,32 @@
-##!/bin/sh
-#
+#!/bin/sh
+
CWD=`pwd`
-SUBMODULE=`basename $CWD | sed 's/\.git$//'`
GITUSER='git'
-GITSERVER='git.yourdomain.com'
+GITSERVER='git.organization.com'
PUPPETSUPERPROJECT='puppet.git'
SSHKEY=''
PUPPETUSER='puppet'
-PUPPETSERVER='geppetto.yourdomain.com'
-
+PUPPETSERVER='puppet.organization.com'
REPO="$GITUSER@$GITSERVER:$PUPPETUSERPROJECT"
DEPLOY="/etc/puppet/environments"
-SSH_ARGS="-i $SSHKYE"
+SSH_ARGS="-i $SSHKEY"
PUPPETMASTER="$PUPPETUSER@PUPPETSERVER"
SYNC_COMMAND="/usr/local/bin/puppetsubsync"
while read oldrev newrev refname
do
BRANCH=`echo $refname | sed -n 's/^refs\/heads\///p'`
- if echo $BRANCH | egrep '^s_' > /dev/null; then
+ if echo $BRANCH | egrep '^t_' > /dev/null; then
- echo "Detecting leading s_ on branchname, submodule cloning..."
+ echo "Detecting leading t_ on branchname, submodule cloning..."
[ "$newrev" -eq 0 ] 2> /dev/null && DELETE='--delete' || DELETE=''
ssh $SSH_ARGS "$PUPPETMASTER" "$SYNC_COMMAND" \
--branch "$BRANCH" \
--repository "$REPO" \
--deploy "$DEPLOY" \
- --submodule "$SUBMODULE" \
$DELETE
fi
done

0 comments on commit ae1e08f

Please sign in to comment.