Skip to content

Commit c5bef82

Browse files
authored
Merge branch 'master' into kpaulisse-hiera-5
2 parents f82d532 + 93df209 commit c5bef82

File tree

26 files changed

+423
-145
lines changed

26 files changed

+423
-145
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.1
1+
1.5.0

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The example above reflects the changes in the Puppet catalog from switching an u
5353
- [Requirements](/doc/requirements.md)
5454
- [Limitations](/doc/limitations.md)
5555
- [List of all command line options](/doc/optionsref.md)
56+
- [Environment variables](/doc/advanced-environment-variables.md)
5657

5758
### Project
5859

doc/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
</tr>
99
</thead><tbody>
1010
<tr valign=top>
11+
<td>1.5.0</td>
12+
<td>2017-10-18</td>
13+
<td>
14+
<li><a href="https://github.com/github/octocatalog-diff/pull/151">#151</a>: (Enhancement) Support text differences in files where `source` is an array</li>
15+
<li><a href="https://github.com/github/octocatalog-diff/pull/153">#153</a>: (Enhancement) Support for hiera 5</li>
16+
<li><a href="https://github.com/github/octocatalog-diff/pull/152">#152</a>: (Internal) Better temporary directory handling</li>
17+
</td>
18+
</tr>
19+
<tr valign=top>
1120
<td>1.4.1</td>
1221
<td>2017-10-02</td>
1322
<td>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Environment variables
2+
3+
The following environment variables have special meaning to octocatalog-diff:
4+
5+
### `OCTOCATALOG_DIFF_CONFIG_FILE`
6+
7+
This environment variable is used to locate the configuration file for the CLI. The use of configuration files is described generally in:
8+
9+
- [Configuration](/doc/configuration.md)
10+
11+
### `OCTOCATALOG_DIFF_CUSTOM_VERSION`
12+
13+
When set, the `octocatalog-diff` CLI will display this as the version number within debugging, instead of the version number in the package. This is most useful if you want to use or include a git SHA in the version number.
14+
15+
```
16+
$ export OCTOCATALOG_DIFF_CUSTOM_VERSION="@$(git rev-parse HEAD)"
17+
$ octocatalog-diff -d ...
18+
D, [2017-10-12T08:57:46.454738 #35205] DEBUG -- : Running octocatalog-diff @504d7f3c91267e5193beb103caae5d4d8cebfee3 with ruby 2.3.1
19+
...
20+
```
21+
22+
### `OCTOCATALOG_DIFF_DEVELOPER_PATH`
23+
24+
When set, instead of loading libraries from the system or bundler location, libraries will be loaded from the specified value of this environment variable. This is used internally for development as we point users to unreleased code for debugging or testing.
25+
26+
```
27+
$ export OCTOCATALOG_DIFF_DEVELOPER_PATH=$HOME/git-checkouts/octocatalog-diff
28+
$ octocatalog-diff ...
29+
```
30+
31+
### `OCTOCATALOG_DIFF_TEMPDIR`
32+
33+
When set:
34+
35+
- `octocatalog-diff` will create all of its temporary directories within the specified directory.
36+
- `octocatalog-diff` will not attempt to remove any temporary directories it creates.
37+
38+
This is useful in the following situations:
39+
40+
- You are calling `octocatalog-diff` from within another program which is highly parallelized, and `at_exit` handlers are difficult to implement. Instead of figuring that all out (if it can even be figured out), you create a temporary directory before the parallelized logic, and remove it afterwards.
41+
42+
- You wish to debug intermediate output. For example, you may be instructed to set this variable and send some of the output to the project maintainers if you request assistance.
43+
44+
This variable is used internally for the parallelized logic for catalog compilation, but the value set from the environment will override any internal usage.
45+
46+
### `OCTOCATALOG_DIFF_VERSION`
47+
48+
This variable is used when building the gem, to override the default version. This is used for internal testing of `octocatalog-diff` before public releases. This variable is not useful outside the build context.
49+
50+
### `PUPPETDB_HOST`
51+
52+
This variable specifies the fully qualified domain name or IP address of the PuppetDB server.
53+
54+
Note: If `PUPPETDB_URL` is specified, then `PUPPETDB_HOST` is not consulted.
55+
56+
### `PUPPETDB_PORT`
57+
58+
This variable specifies the port number of the PuppetDB server.
59+
60+
Note: If `PUPPETDB_URL` is specified, then `PUPPETDB_PORT` is not consulted.
61+
62+
### `PUPPETDB_URL`
63+
64+
This variable specifies the URL to the PuppetDB server.
65+
66+
Example: `https://puppetdb.example.net:8081`
67+
68+
### `PUPPET_FACT_DIR`
69+
70+
This variable specifies the directory path where puppet fact files are stored. (Fact files must be named `<fqdn>.yaml` where `<fqdn>` is specified when running `octocatalog-diff`.)

doc/dev/releasing.md

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,13 @@ The project maintainers are responsible for bumping the version number, regenera
66

77
*This procedure is performed by a GitHubber.*
88

9-
To test the new version of `octocatalog-diff` in the GitHub Puppet repository:
9+
To test the new version of `octocatalog-diff` in the GitHub Puppet repository, check out `github/puppet` and:
1010

11-
0. In a checkout of the GitHub Puppet repository, start a new branch based off master.
12-
0. In the `octocatalog-diff` checkout:
13-
- Ensure that the desired branch is checked out.
14-
- Choose a unique internal version number which has never been used in CI. A good guideline is that if you're planning to release a version `0.6.0` then for these tests, use `0.6.0a`, `0.6.0b`, ...
15-
- Build the gem using your internal version number:
16-
17-
```
18-
OCTOCATALOG_DIFF_VERSION=0.6.0a rake gem:force-build
19-
```
20-
- Run the task to install the gem into your Puppet checkout:
21-
22-
```
23-
OCTOCATALOG_DIFF_VERSION=0.6.0a rake gem:localinstall
24-
```
25-
26-
0. Back in the Puppet checkout, ensure that the changes are as expected (updates to Gemfile / Gemfile.lock, addition of new gem). Push the change and build appropriate CI job(s) to validate the changes.
11+
- Start a new branch based off master
12+
- Run `script/update-octocatalog-diff -r <ocd_branch_name>`
13+
- Confirm and commit the result
14+
- Make sure all CI jobs pass
15+
- Run the `puppet-catalog-diff` CI job and make sure it passes and shows expected results
2716

2817
## Merging one PR
2918

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
require_relative '../facts'
66
require_relative 'enc'
7+
require_relative '../util/util'
78

89
module OctocatalogDiff
910
module CatalogUtil
@@ -38,9 +39,7 @@ class BuildDir
3839
# @param options [Hash] Options for class; see above description
3940
def initialize(options = {}, logger = nil)
4041
@options = options.dup
41-
@tempdir = Dir.mktmpdir('ocd-builddir-')
42-
at_exit { FileUtils.rm_rf(@tempdir) if File.directory?(@tempdir) }
43-
42+
@tempdir = OctocatalogDiff::Util::Util.temp_dir('ocd-builddir-')
4443
@factdir = nil
4544
@enc = nil
4645
@fact_file = nil

lib/octocatalog-diff/catalog-util/fileresources.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@ def self.convert_file_resources(obj, environment = 'production')
2727
# module path that is specified within the environment.conf file (assuming the default 'modules'
2828
# directory doesn't exist or the module isn't found in there). If the file can't be found then
2929
# this returns nil which may trigger an error.
30-
# @param src [String] A file reference: puppet:///modules/xxx/yyy
30+
# @param src_in [String|Array] A file reference: puppet:///modules/xxx/yyy
3131
# @param modulepaths [Array] Cached module path
3232
# @return [String] File system path to referenced file
33-
def self.file_path(src, modulepaths)
34-
unless src =~ %r{^puppet:///modules/([^/]+)/(.+)}
35-
raise ArgumentError, "Bad parameter source #{src}"
36-
end
33+
def self.file_path(src_in, modulepaths)
34+
valid_sources = [src_in].flatten.select { |line| line =~ %r{\Apuppet:///modules/([^/]+)/(.+)} }
35+
return unless valid_sources.any?
3736

38-
path = File.join(Regexp.last_match(1), 'files', Regexp.last_match(2))
39-
modulepaths.each do |mp|
40-
file = File.join(mp, path)
41-
return file if File.exist?(file)
37+
valid_sources.each do |src|
38+
src =~ %r{\Apuppet:///modules/([^/]+)/(.+)}
39+
path = File.join(Regexp.last_match(1), 'files', Regexp.last_match(2))
40+
modulepaths.each do |mp|
41+
file = File.join(mp, path)
42+
return file if File.exist?(file)
43+
end
4244
end
4345

4446
nil
@@ -125,9 +127,14 @@ def self.resource_convertible?(resource)
125127
!resource['parameters'].nil? && \
126128
resource['parameters'].key?('source') && \
127129
!resource['parameters'].key?('content') && \
128-
resource['parameters']['source'] =~ %r{^puppet:///modules/([^/]+)/(.+)}
130+
valid_sources?(resource)
131+
129132
false
130133
end
134+
135+
def self.valid_sources?(resource)
136+
[resource['parameters']['source']].flatten.select { |line| line =~ %r{\Apuppet:///modules/([^/]+)/(.+)} }.any?
137+
end
131138
end
132139
end
133140
end

lib/octocatalog-diff/catalog/computed.rb

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
require_relative '../catalog-util/facts'
1212
require_relative '../util/puppetversion'
1313
require_relative '../util/scriptrunner'
14+
require_relative '../util/util'
1415

1516
module OctocatalogDiff
1617
class Catalog
@@ -69,23 +70,6 @@ def convert_file_resources(dry_run = false)
6970
OctocatalogDiff::CatalogUtil::FileResources.convert_file_resources(self, environment)
7071
end
7172

72-
private
73-
74-
# Private method: Clean up a checkout directory, if it exists
75-
def cleanup_checkout_dir(checkout_dir, logger)
76-
return unless File.directory?(checkout_dir)
77-
logger.debug("Cleaning up temporary directory #{checkout_dir}")
78-
# Sometimes this seems to break when handling the recursive removal when running under
79-
# a parallel environment. Trap and ignore the errors here if we don't care about them.
80-
begin
81-
FileUtils.remove_entry_secure checkout_dir
82-
# :nocov:
83-
rescue Errno::ENOTEMPTY, Errno::ENOENT => exc
84-
logger.debug "cleanup_checkout_dir(#{checkout_dir}) logged #{exc.class} - this can be ignored"
85-
# :nocov:
86-
end
87-
end
88-
8973
# Private method: Bootstrap a directory
9074
def bootstrap(logger)
9175
return if @builddir
@@ -99,9 +83,7 @@ def bootstrap(logger)
9983
tmphash[:basedir] = @options[:bootstrapped_dir]
10084
elsif @options[:branch] == '.'
10185
if @options[:bootstrap_current]
102-
tmphash[:basedir] = Dir.mktmpdir('ocd-bootstrap-basedir-')
103-
at_exit { cleanup_checkout_dir(tmphash[:basedir], logger) }
104-
86+
tmphash[:basedir] = OctocatalogDiff::Util::Util.temp_dir('ocd-bootstrap-basedir-')
10587
FileUtils.cp_r File.join(@options[:basedir], '.'), tmphash[:basedir]
10688

10789
o = @options.reject { |k, _v| k == :branch }.merge(path: tmphash[:basedir])
@@ -110,10 +92,8 @@ def bootstrap(logger)
11092
tmphash[:basedir] = @options[:basedir]
11193
end
11294
else
113-
checkout_dir = Dir.mktmpdir('ocd-bootstrap-checkout-')
114-
at_exit { cleanup_checkout_dir(checkout_dir, logger) }
115-
tmphash[:basedir] = checkout_dir
116-
OctocatalogDiff::CatalogUtil::Bootstrap.bootstrap_directory(@options.merge(path: checkout_dir), logger)
95+
tmphash[:basedir] = OctocatalogDiff::Util::Util.temp_dir('ocd-bootstrap-checkout-')
96+
OctocatalogDiff::CatalogUtil::Bootstrap.bootstrap_directory(@options.merge(path: tmphash[:basedir]), logger)
11797
end
11898

11999
# Create and populate the temporary directory

lib/octocatalog-diff/util/parallel.rb

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# this instead executes the tasks serially, but provides the same API as the parallel tasks.
77

88
require 'stringio'
9+
require_relative 'util'
910

1011
module OctocatalogDiff
1112
module Util
@@ -107,13 +108,14 @@ def self.run_tasks(task_array, logger = nil, parallelized = true, raise_exceptio
107108
# @return [Exception] First exception encountered by a child process; returns nil if no exceptions encountered.
108109
def self.run_tasks_parallel(result, task_array, logger)
109110
pidmap = {}
110-
ipc_tempdir = Dir.mktmpdir('ocd-ipc-')
111+
ipc_tempdir = OctocatalogDiff::Util::Util.temp_dir('ocd-ipc-')
111112

112113
# Child process forking
113114
task_array.each_with_index do |task, index|
114115
# simplecov doesn't see this because it's forked
115116
# :nocov:
116117
this_pid = fork do
118+
ENV['OCTOCATALOG_DIFF_TEMPDIR'] ||= ipc_tempdir
117119
task_result = execute_task(task, logger)
118120
File.open(File.join(ipc_tempdir, "#{Process.pid}.dat"), 'w') { |f| f.write Marshal.dump(task_result) }
119121
Kernel.exit! 0 # Kernel.exit! avoids at_exit from parents being triggered by children exiting
@@ -157,17 +159,6 @@ def self.run_tasks_parallel(result, task_array, logger)
157159
# If the process doesn't exist, that's fine.
158160
end
159161
end
160-
161-
retries = 0
162-
while File.directory?(ipc_tempdir) && retries < 10
163-
retries += 1
164-
begin
165-
FileUtils.remove_entry_secure ipc_tempdir
166-
rescue Errno::ENOTEMPTY, Errno::ENOENT # rubocop:disable Lint/HandleExceptions
167-
# Errno::ENOTEMPTY will trigger a retry because the directory exists
168-
# Errno::ENOENT will break the loop because the directory won't exist next time it's checked
169-
end
170-
end
171162
end
172163

173164
# Utility method! Not intended to be called from outside this class.

lib/octocatalog-diff/util/scriptrunner.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
require 'open3'
77
require 'shellwords'
88

9+
require_relative 'util'
10+
911
module OctocatalogDiff
1012
module Util
1113
# This is a utility class to execute a built-in script.
@@ -91,14 +93,7 @@ def log(priority, message, logger = @logger)
9193
# @return [String] Path to tempfile containing script
9294
def temp_script(script)
9395
raise Errno::ENOENT, "Script '#{script}' not found" unless File.file?(script)
94-
temp_dir = Dir.mktmpdir('ocd-scriptrunner-')
95-
at_exit do
96-
begin
97-
FileUtils.remove_entry_secure temp_dir
98-
rescue Errno::ENOENT # rubocop:disable Lint/HandleExceptions
99-
# OK if the directory doesn't exist since we're trying to remove it anyway
100-
end
101-
end
96+
temp_dir = OctocatalogDiff::Util::Util.temp_dir('ocd-scriptrunner')
10297
temp_file = File.join(temp_dir, File.basename(script))
10398
File.open(temp_file, 'w') { |f| f.write(File.read(script)) }
10499
FileUtils.chmod 0o755, temp_file

0 commit comments

Comments
 (0)