Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure installation to avoid duplicate files #870

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 25 additions & 38 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,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 @@ -74,37 +75,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 @@ -219,11 +217,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 @@ -241,17 +237,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 @@ -262,11 +251,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