Skip to content

Commit ada9415

Browse files
committed
Restore and clarify config_version functionality
This branch is intended as a portability fix. Some functionailty had been inadvertently removed as unused, but testing revealed that it had a purpose. Because the purpose was unclear, this commit restores the functionality AND clarifies it in the script names and comments in config_version.sh.
1 parent 415a71d commit ada9415

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

scripts/code_manager_config_version.rb renamed to scripts/config_version-r10k.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/opt/puppetlabs/puppet/bin/ruby
12
require 'json'
23
require 'socket'
34

scripts/config_version-rugged.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/opt/puppetlabs/puppet/bin/ruby
2+
begin
3+
require 'rugged'
4+
require 'socket'
5+
rescue LoadError
6+
t = Time.new
7+
puts t.to_i
8+
else
9+
environmentpath = ARGV[0]
10+
environment = ARGV[1]
11+
12+
# Get the hostname of the Puppet master compiling the catalog.
13+
# Sometimes the hostname is the fqdn, so we'll take the first segment.
14+
compiling_master = Socket.gethostname.split('.').first
15+
16+
# Get the path to the environment being compiled.
17+
repo = Rugged::Repository.discover(File.join(environmentpath, environment))
18+
head = repo.head
19+
20+
# First 12 characters of the sha1 hash of the newest commit.
21+
commit_id = head.target_id[0...11]
22+
23+
# Show the compiling master, environment name, and commit ID.
24+
puts "#{compiling_master}-#{environment}-#{commit_id}"
25+
end

scripts/config_version.sh

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
11
#!/bin/sh
22

3+
# Usage
34
if [ $# -ne 2 -o ! -d "$1" -o ! -d "$1/$2" ]; then
45
echo "usage: $0 <environmentpath> <environment>" >&2
56
exit 1
67
fi
78

8-
ruby=ruby
9+
# For portability, identify a preferred ruby executable to use
10+
ruby() {
11+
[ -x /opt/puppetlabs/puppet/bin/ruby ] \
12+
&& /opt/puppetlabs/puppet/bin/ruby "$@" \
13+
|| /usr/bin/env ruby "$@"
14+
}
915

10-
if [ -x /opt/puppetlabs/puppet/bin/ruby ]; then
11-
ruby=/opt/puppetlabs/puppet/bin/ruby
12-
fi
16+
# Determine how best to calculate a config_version
17+
if [ -e $1/$2/.r10k-deploy.json ]; then
18+
# The environment was deployed using r10k. We will calculate the config
19+
# version using the r10k data.
20+
ruby $1/$2/scripts/config_version-r10k.rb $1 $2
21+
22+
elif [ -e /opt/puppetlabs/server/pe_version ]; then
23+
# This is a Puppet Enterprise system and we can rely on the rugged ruby gem
24+
# being available.
25+
ruby $1/$2/scripts/config_version-rugged.rb $1 $2
26+
27+
elif [ -x /usr/bin/git ]; then
28+
# The git command is available.
29+
/usr/bin/git --git-dir $1/$2/.git rev-parse HEAD
1330

14-
"${ruby}" "$1/$2/scripts/code_manager_config_version.rb" "$1" "$2"
31+
else
32+
# Nothing else available; just use the date.
33+
date +%s
34+
35+
fi

0 commit comments

Comments
 (0)