Skip to content

Commit

Permalink
Restructure installation to avoid duplicate files
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Dec 7, 2022
1 parent 5dcd8c9 commit ba346c3
Showing 1 changed file with 25 additions and 38 deletions.
63 changes: 25 additions & 38 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ directory BUILDDIR
directory PKGDIR
directory "#{BUILDDIR}/parser_cache"
file "#{BUILDDIR}/parser_cache" => BUILDDIR
directory "#{BUILDDIR}/scenarios.d" => BUILDDIR

SCENARIOS.each do |scenario|
config = "config/#{scenario}.yaml"
file "#{BUILDDIR}/#{scenario}.yaml" => [config, BUILDDIR] do |t|
file "#{BUILDDIR}/scenarios.d/#{scenario}.yaml" => [config, "#{BUILDDIR}/scenarios.d"] do |t|
cp t.prerequisites.first, t.name

scenario_config_replacements = {
Expand All @@ -123,37 +124,34 @@ SCENARIOS.each do |scenario|
end
end

file "#{BUILDDIR}/parser_cache/#{scenario}.yaml" => [config, "#{BUILDDIR}/modules", "#{BUILDDIR}/parser_cache"] do |t|
sh "#{exporter}/kafo-export-params -c #{t.prerequisites.first} -f parsercache --no-parser-cache -o #{t.name}"
end

file "#{BUILDDIR}/#{scenario}-options.asciidoc" => [config, "#{BUILDDIR}/parser_cache/#{scenario}.yaml"] do |t|
sh "#{exporter}/kafo-export-params -c #{t.prerequisites.first} -f asciidoc -o #{t.name}"
file "#{BUILDDIR}/scenarios.d/#{scenario}-answers.yaml" => ["config/#{scenario}-answers.yaml", "#{BUILDDIR}/scenarios.d"] do |t|
cp t.prerequisites.first, t.name
end

# Store migration scripts under DATADIR, symlinked back into SYSCONFDIR and keep .applied file in SYSCONFDIR
directory "#{BUILDDIR}/#{scenario}.migrations"
file "#{BUILDDIR}/#{scenario}.migrations" => BUILDDIR do |t|
# These symlinks are broken until installation, so don't reference them in rake file tasks
ln_s "#{DATADIR}/foreman-installer/config/#{scenario}.migrations", "#{t.name}/#{scenario}.migrations"
ln_s "#{SYSCONFDIR}/foreman-installer/scenarios.d/#{scenario}-migrations-applied", "#{t.name}/.applied"
end

file "#{BUILDDIR}/config/#{scenario}.migrations" => ["config/#{scenario}.migrations", "#{BUILDDIR}/config"] do |t|
cp_r t.prerequisites.first, t.name
end

file "#{BUILDDIR}/config/#{scenario}.yaml" => ["config/#{scenario}.yaml", "#{BUILDDIR}/config"] do |t|
cp t.prerequisites.first, t.name
file "#{BUILDDIR}/config/#{scenario}.migrations/.applied" => "#{BUILDDIR}/config/#{scenario}.migrations" do |t|
ln_s "#{SYSCONFDIR}/foreman-installer/scenarios.d/#{scenario}-migrations-applied", t.name
end

file "#{BUILDDIR}/config/#{scenario}-answers.yaml" => ["config/#{scenario}-answers.yaml", "#{BUILDDIR}/config"] do |t|
cp t.prerequisites.first, t.name
file "#{BUILDDIR}/scenarios.d/#{scenario}.migrations" => "#{BUILDDIR}/scenarios.d" do |t|
ln_s "#{DATADIR}/foreman-installer/config/#{scenario}.migrations", t.name
end

# Generate an empty applied migrations file to ensure the symlink is preserved
file "#{BUILDDIR}/#{scenario}-migrations-applied" => BUILDDIR do |t|
File.open(t.name, 'w') { |f| f.write([].to_yaml) }
file "#{BUILDDIR}/scenarios.d/#{scenario}-migrations-applied" => "#{BUILDDIR}/scenarios.d" do |t|
File.write(t.name, [].to_yaml)
end

file "#{BUILDDIR}/parser_cache/#{scenario}.yaml" => [config, "#{BUILDDIR}/modules", "#{BUILDDIR}/parser_cache"] do |t|
sh "#{exporter}/kafo-export-params -c #{t.prerequisites.first} -f parsercache --no-parser-cache -o #{t.name}"
end

file "#{BUILDDIR}/#{scenario}-options.asciidoc" => [config, "#{BUILDDIR}/parser_cache/#{scenario}.yaml"] do |t|
sh "#{exporter}/kafo-export-params -c #{t.prerequisites.first} -f asciidoc -o #{t.name}"
end
end

Expand Down Expand Up @@ -268,11 +266,9 @@ namespace :build do

task :scenarios => [SCENARIOS.map do |scenario|
[
"#{BUILDDIR}/#{scenario}.yaml",
"#{BUILDDIR}/#{scenario}.migrations",
"#{BUILDDIR}/#{scenario}-migrations-applied",
"#{BUILDDIR}/config/#{scenario}.yaml",
"#{BUILDDIR}/config/#{scenario}-answers.yaml",
"#{BUILDDIR}/scenarios.d/#{scenario}.yaml",
"#{BUILDDIR}/scenarios.d/#{scenario}-answers.yaml",
"#{BUILDDIR}/scenarios.d/#{scenario}-migrations-applied",
"#{BUILDDIR}/config/#{scenario}.migrations",
"#{BUILDDIR}/parser_cache/#{scenario}.yaml",
]
Expand All @@ -290,17 +286,10 @@ task :build => ['build:base', 'build:scenarios', 'build:certs_scenarios']

task :install => :build do
mkdir_p "#{DATADIR}/foreman-installer"
cp_r Dir.glob('{checks,hooks,VERSION,README.md,LICENSE}'), "#{DATADIR}/foreman-installer"
cp_r Dir.glob('{checks,hooks,VERSION}'), "#{DATADIR}/foreman-installer"
cp_r "#{BUILDDIR}/config", "#{DATADIR}/foreman-installer"

mkdir_p "#{SYSCONFDIR}/foreman-installer/scenarios.d"
SCENARIOS.each do |scenario|
cp "#{BUILDDIR}/#{scenario}.yaml", "#{SYSCONFDIR}/foreman-installer/scenarios.d/"
cp "config/#{scenario}-answers.yaml", "#{SYSCONFDIR}/foreman-installer/scenarios.d/#{scenario}-answers.yaml"
cp "#{BUILDDIR}/#{scenario}-migrations-applied", "#{SYSCONFDIR}/foreman-installer/scenarios.d/#{scenario}-migrations-applied"
copy_entry "#{BUILDDIR}/#{scenario}.migrations/#{scenario}.migrations", "#{SYSCONFDIR}/foreman-installer/scenarios.d/#{scenario}.migrations"
copy_entry "#{BUILDDIR}/#{scenario}.migrations/.applied", "#{DATADIR}/foreman-installer/config/#{scenario}.migrations/.applied"
end
cp_r "#{BUILDDIR}/modules", "#{DATADIR}/foreman-installer", :preserve => true
cp_r "#{BUILDDIR}/parser_cache", "#{DATADIR}/foreman-installer"

if CERTS_SCENARIOS.any?
mkdir_p "#{DATADIR}/foreman-installer/katello-certs/scenarios.d"
Expand All @@ -311,11 +300,9 @@ task :install => :build do
cp "katello_certs/config/#{scenario}-answers.yaml", "#{DATADIR}/foreman-installer/katello-certs/scenarios.d/#{scenario}-answers.yaml"
end

cp_r "#{BUILDDIR}/modules", "#{DATADIR}/foreman-installer", :preserve => true
cp_r "#{BUILDDIR}/parser_cache", "#{DATADIR}/foreman-installer"

mkdir_p "#{SYSCONFDIR}/foreman-installer"
cp "config/custom-hiera.yaml", "#{SYSCONFDIR}/foreman-installer"
cp_r "#{BUILDDIR}/scenarios.d", "#{SYSCONFDIR}/foreman-installer"

mkdir_p SBINDIR
install "#{BUILDDIR}/foreman-installer", "#{SBINDIR}/foreman-installer", :mode => 0o755, :verbose => true
Expand Down

0 comments on commit ba346c3

Please sign in to comment.