accomodate separate-git-dir, consolidate scripts
This commit is contained in:
parent
c9931ceef7
commit
6307feb7dd
@ -1,2 +1,2 @@
|
|||||||
modulepath = modules:site:$basemodulepath
|
modulepath = modules:site:$basemodulepath
|
||||||
config_version = 'scripts/config_version.sh $environmentpath $environment'
|
config_version = 'scripts/config_version.rb $environmentpath $environment'
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require 'json'
|
|
||||||
|
|
||||||
environmentpath = ARGV[0]
|
|
||||||
environment = ARGV[1]
|
|
||||||
|
|
||||||
r10k_deploy_file_path = File.join(environmentpath, environment, '.r10k-deploy.json')
|
|
||||||
|
|
||||||
#output the sha1 from the control-repo
|
|
||||||
puts JSON.parse(File.read(r10k_deploy_file_path))['signature']
|
|
@ -1,24 +1,49 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/opt/puppetlabs/puppet/bin/ruby
|
||||||
begin
|
|
||||||
require 'rugged'
|
require 'json'
|
||||||
rescue LoadError => e
|
|
||||||
t = Time.new
|
param_environment_path = ARGV[0]
|
||||||
puts t.to_i
|
param_environment = ARGV[1]
|
||||||
|
|
||||||
|
if (param_environment_path && param_environment)
|
||||||
|
# Use the parameters, if passed.
|
||||||
|
environment_path = File.join(param_environment_path, param_environment)
|
||||||
else
|
else
|
||||||
|
# Or use the parent directory.
|
||||||
environmentpath = ARGV[0]
|
environment_path = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
||||||
environment = ARGV[1]
|
|
||||||
|
|
||||||
repo = Rugged::Repository.discover(File.join(environmentpath, environment))
|
|
||||||
head = repo.head
|
|
||||||
|
|
||||||
#sha1 hash of the newest commit
|
|
||||||
head_sha = head.target_id
|
|
||||||
|
|
||||||
#the commit message associated the newest commit
|
|
||||||
commit = repo.lookup(head_sha)
|
|
||||||
|
|
||||||
#add something to find the remote url
|
|
||||||
|
|
||||||
puts head_sha
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
environment_r10k_deploy_file = File.join(environment_path, '.r10k-deploy.json')
|
||||||
|
environment_dot_git = File.join(environment_path, '.git')
|
||||||
|
pe_version_file = '/opt/puppetlabs/server/pe_version'
|
||||||
|
environment_version = nil
|
||||||
|
|
||||||
|
if (File.file?(environment_r10k_deploy_file))
|
||||||
|
# Use the r10k deploy file, if using Code Manager.
|
||||||
|
environment_version = JSON.parse(File.read(environment_r10k_deploy_file))['signature']
|
||||||
|
|
||||||
|
elsif (File.file?(pe_version_file))
|
||||||
|
# Or use rugged, if using Puppet Enterprise.
|
||||||
|
begin
|
||||||
|
require 'rugged'
|
||||||
|
rescue LoadError => e
|
||||||
|
# It's okay.
|
||||||
|
else
|
||||||
|
environment_version = Rugged::Repository.discover(environment_path).head.target_id
|
||||||
|
end
|
||||||
|
|
||||||
|
elsif (File.exist?(environment_dot_git))
|
||||||
|
# Or use git, just use git.
|
||||||
|
if (File.file?(environment_dot_git))
|
||||||
|
# It's a file, created via --separate-git-dir.
|
||||||
|
git_dir = File.read(environment_dot_git).split(': ')[1]
|
||||||
|
else
|
||||||
|
git_dir = environment_dot_git
|
||||||
|
end
|
||||||
|
git_rev_parse_head = %x( /usr/bin/git --git-dir #{git_dir} rev-parse HEAD 2>/dev/null )
|
||||||
|
environment_version = git_rev_parse_head if ($?.exitstatus == 0)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return the version, if found, or the current timestamp.
|
||||||
|
puts (environment_version || Time.now.to_i)
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ -e $1/$2/.r10k-deploy.json ]
|
|
||||||
then
|
|
||||||
/opt/puppetlabs/puppet/bin/ruby $1/$2/scripts/code_manager_config_version.rb $1 $2
|
|
||||||
elif [ -e /opt/puppetlabs/server/pe_version ]
|
|
||||||
then
|
|
||||||
/opt/puppetlabs/puppet/bin/ruby $1/$2/scripts/config_version.rb $1 $2
|
|
||||||
else
|
|
||||||
/usr/bin/git --version > /dev/null 2>&1 &&
|
|
||||||
/usr/bin/git --git-dir $1/$2/.git rev-parse HEAD ||
|
|
||||||
date +%s
|
|
||||||
fi
|
|
Loading…
Reference in New Issue
Block a user