File tree Expand file tree Collapse file tree 3 files changed +52
-5
lines changed Expand file tree Collapse file tree 3 files changed +52
-5
lines changed Original file line number Diff line number Diff line change 1+ #!/opt/puppetlabs/puppet/bin/ruby
12require 'json'
23require 'socket'
34
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 11#! /bin/sh
22
3+ # Usage
34if [ $# -ne 2 -o ! -d " $1 " -o ! -d " $1 /$2 " ]; then
45 echo " usage: $0 <environmentpath> <environment>" >&2
56 exit 1
67fi
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
You can’t perform that action at this time.
0 commit comments