Skip to content

Commit f307fc6

Browse files
author
Kevin Paulisse
committed
Implement option for bootstrapping current directory
1 parent 978caba commit f307fc6

9 files changed

Lines changed: 70 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ def self.install_bootstrap_script(logger, opts)
136136
def self.run_bootstrap(logger, opts)
137137
logger.debug("Begin bootstrap with '#{opts[:bootstrap_script]}' in #{opts[:path]}")
138138
result = OctocatalogDiff::Bootstrap.bootstrap(opts)
139+
if opts[:debug_bootstrap] || result[:status_code] > 0
140+
output = result[:output].split(/[\r\n]+/)
141+
output.each { |x| logger.debug("Bootstrap: #{x}") }
142+
end
139143
raise BootstrapError, "bootstrap failed for #{opts[:path]}: #{result[:output]}" unless (result[:status_code]).zero?
140144
logger.debug("Success bootstrap in #{opts[:path]}")
141145
result[:output]

lib/octocatalog-diff/catalog/computed.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,17 @@ def bootstrap(logger)
9494
raise Errno::ENOENT, "Invalid dir #{@opts[:bootstrapped_dir]}" unless File.directory?(@opts[:bootstrapped_dir])
9595
tmphash[:basedir] = @opts[:bootstrapped_dir]
9696
elsif @opts[:branch] == '.'
97-
tmphash[:basedir] = @opts[:basedir]
97+
if @opts[:bootstrap_current]
98+
tmphash[:basedir] = Dir.mktmpdir
99+
at_exit { cleanup_checkout_dir(tmphash[:basedir], logger) }
100+
101+
FileUtils.cp_r File.join(@opts[:basedir], '.'), tmphash[:basedir]
102+
103+
o = @opts.reject { |k, _v| k == :branch }.merge(path: tmphash[:basedir])
104+
OctocatalogDiff::CatalogUtil::Bootstrap.bootstrap_directory(o, logger)
105+
else
106+
tmphash[:basedir] = @opts[:basedir]
107+
end
98108
else
99109
checkout_dir = Dir.mktmpdir
100110
at_exit { cleanup_checkout_dir(checkout_dir, logger) }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
ls -lR > /tmp/foo.$$
3+
echo "Hello, stdout"
4+
echo "Hello, stderr" 1>&2
5+
cp -r external-modules/test modules
6+
exit 0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
echo "Fail, stdout"
4+
echo "Fail, stderr" 1>&2
5+
exit 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class test {
2+
file { '/tmp/foo':
3+
content => template('test/foo.erb'),
4+
}
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test 123
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include test

spec/octocatalog-diff/fixtures/repos/bootstrap/modules/.gitkeep

Whitespace-only changes.

spec/octocatalog-diff/tests/catalog/computed_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,43 @@
77
require OctocatalogDiff::Spec.require_path('/catalog-util/builddir')
88

99
describe OctocatalogDiff::Catalog::Computed do
10+
context 'bootstrapping in the current directory' do
11+
before(:all) do
12+
@repo_dir = Dir.mktmpdir
13+
FileUtils.cp_r OctocatalogDiff::Spec.fixture_path('repos/bootstrap'), @repo_dir
14+
15+
@node = 'rspec-node.github.net'
16+
catalog_opts = {
17+
node: @node,
18+
puppet_binary: OctocatalogDiff::Spec::PUPPET_BINARY,
19+
basedir: File.join(@repo_dir, 'bootstrap'),
20+
fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'),
21+
branch: '.',
22+
bootstrap_current: true,
23+
debug_bootstrap: true,
24+
bootstrap_script: 'config/bootstrap.sh'
25+
}
26+
@catalog = OctocatalogDiff::Catalog::Computed.new(catalog_opts)
27+
logger, @logger_str = OctocatalogDiff::Spec.setup_logger
28+
@catalog.build(logger)
29+
end
30+
31+
after(:all) do
32+
OctocatalogDiff::Spec.clean_up_tmpdir(@repo_dir)
33+
end
34+
35+
describe '#bootstrap' do
36+
it 'should result in a successful compilation' do
37+
expect(@catalog.catalog).to be_a_kind_of(Hash), @catalog.inspect
38+
end
39+
40+
it 'should log debug messages' do
41+
expect(@logger_str.string).to match(/Bootstrap: Hello, stdout/)
42+
expect(@logger_str.string).to match(/Bootstrap: Hello, stderr/)
43+
end
44+
end
45+
end
46+
1047
context 'compiling a catalog' do
1148
context 'with a working catalog' do
1249
before(:all) do

0 commit comments

Comments
 (0)