Skip to content

Commit

Permalink
Fixes #35420 - Drop boot_settings.rb for early settings
Browse files Browse the repository at this point in the history
With Rails 7 require_relative no longer works in a Gemfile (maybe it's
Zeitwerk?). Currently we only support Rails 6.1 anyway and if we can't
use the mechanism for Rails 7 this mechanism should be removed.

An environment variable has been considered but in testing the
environment variable was not passed on and issues with the lockfile
showed up.

When we upgrade Rails to 7.0 a new mechnism needs to be found.
  • Loading branch information
ekohl committed Aug 25, 2022
1 parent c85b0ce commit afd0518
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 37 deletions.
10 changes: 1 addition & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
# foreman plugins import this file therefore __FILE__ cannot be used
FOREMAN_GEMFILE = __FILE__ unless defined? FOREMAN_GEMFILE

require_relative 'config/boot_settings'

source 'https://rubygems.org'

gem 'rails', case SETTINGS[:rails]
when '6.1'
'~> 6.1.6.1'
else
raise "Unsupported Ruby on Rails version configured in settings.yaml: #{SETTINGS[:rails]}"
end

gem 'rails', '~> 6.1.6.1'
gem 'rest-client', '>= 2.0.0', '< 3', :require => 'rest_client'
gem 'audited', '>= 4.9.0', '< 5'
gem 'will_paginate', '~> 3.3'
Expand Down
1 change: 0 additions & 1 deletion app/services/foreman/env_settings_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def settings_map
'FOREMAN_WEBPACK_DEV_SERVER_HTTPS' => [:boolean, :webpack_dev_server_https],
'FOREMAN_ASSETS_DEBUG' => [:boolean, :assets_debug],
'FOREMAN_HSTS_ENABLED' => [:boolean, :hsts_enabled],
'FOREMAN_RAILS' => [:string, :rails],
'FOREMAN_DOMAIN' => [:string, :domain],
'FOREMAN_FQDN' => [:string, :fqdn],
'FOREMAN_CORS_DOMAINS' => [:list, :cors_domains],
Expand Down
14 changes: 0 additions & 14 deletions config/boot_settings.rb

This file was deleted.

11 changes: 4 additions & 7 deletions config/settings.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
require_relative 'boot_settings'
require_relative '../app/services/foreman/version'
require_relative '../app/services/foreman/env_settings_loader'

root = File.expand_path(File.dirname(__FILE__) + "/..")
settings_file = Rails.env.test? ? 'config/settings.yaml.test' : 'config/settings.yaml'
settings_file = File.join(__dir__, Rails.env.test? ? 'settings.yaml.test' : 'settings.yaml')

SETTINGS.merge! YAML.load(ERB.new(File.read("#{root}/#{settings_file}")).result) if File.exist?(settings_file)
SETTINGS = {}
SETTINGS.merge! YAML.load(ERB.new(File.read(settings_file)).result) if File.exist?(settings_file)
SETTINGS[:version] = Foreman::Version.new

# Load settings from env variables
Expand All @@ -21,15 +20,13 @@
SETTINGS[setting] = SETTINGS.fetch(setting, true)
end

SETTINGS[:rails] = '%.1f' % SETTINGS[:rails] if SETTINGS[:rails].is_a?(Float) # unquoted YAML value

unless SETTINGS[:domain] && SETTINGS[:fqdn]
require 'facter'
SETTINGS[:domain] ||= Facter.value(:domain) || Facter.value(:hostname)
SETTINGS[:fqdn] ||= Facter.value(:fqdn)
end

# Load plugin config, if any
Dir["#{root}/config/settings.plugins.d/*.yaml"].each do |f|
Dir["#{__dir__}/settings.plugins.d/*.yaml"].each do |f|
SETTINGS.merge! YAML.load(ERB.new(File.read(f)).result)
end
4 changes: 0 additions & 4 deletions config/settings.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
# so only change this if you know what you're doing.
:hsts_enabled: true

# Ruby on Rails version (available: 6.1)
# Defaults to 6.1
#:rails: 6.1

# Local administrative settings for application domain, fqdn, foreman URL,
# administrator email address etc. If you don't have a Puppet provisioning
# system you may want to change to setup your project on your local machine.
Expand Down
2 changes: 0 additions & 2 deletions test/unit/foreman/env_settings_loader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class EnvSettingsLoaderTest < ActiveSupport::TestCase
'FOREMAN_WEBPACK_DEV_SERVER_HTTPS' => 'false',
'FOREMAN_ASSETS_DEBUG' => 'false',
'FOREMAN_HSTS_ENABLED' => 'false',
'FOREMAN_RAILS' => '5.2',
'FOREMAN_DOMAIN' => 'example.com',
'FOREMAN_FQDN' => 'foreman.example.com',
'FOREMAN_CORS_DOMAINS' => 'https://foreman.example.com https://www.foreman.example.com',
Expand Down Expand Up @@ -48,7 +47,6 @@ class EnvSettingsLoaderTest < ActiveSupport::TestCase
webpack_dev_server_https: false,
assets_debug: false,
hsts_enabled: false,
rails: '5.2',
domain: 'example.com',
fqdn: 'foreman.example.com',
cors_domains: ['https://foreman.example.com', 'https://www.foreman.example.com'],
Expand Down

0 comments on commit afd0518

Please sign in to comment.