Better overrides for database values
Before this change, it was impossible to override certain gitlab_rails['db_xxx'] settings from gitlab.rb when Postgres was enabled: we did a hash merge in recipes/gitlab-rails.rb and recipes/gitlab-ci.rb that would stomp on the custom settings in gitlab.rb. This change makes sure gitlab.rb overrides for gitlab_XXX['db_YYY'] always win.
This commit is contained in:
parent
c74d308846
commit
503fad5f9d
|
@ -177,6 +177,33 @@ module Gitlab
|
|||
end
|
||||
end
|
||||
|
||||
def parse_postgresql_settings
|
||||
# If the user wants to run the internal Postgres service using an alternative
|
||||
# DB username, host or port, then those settings should also be applied to
|
||||
# gitlab-rails and gitlab-ci.
|
||||
[
|
||||
# %w{gitlab_rails db_username} corresponds to
|
||||
# Gitlab['gitlab_rails']['db_username'], etc.
|
||||
[%w{gitlab_rails db_username}, %w{postgresql sql_user}],
|
||||
[%w{gitlab_rails db_host}, %w{postgresql listen_address}],
|
||||
[%w{gitlab_rails db_port}, %w{postgresql port}],
|
||||
[%w{gitlab_ci db_username}, %w{postgresql sql_ci_user}],
|
||||
[%w{gitlab_ci db_host}, %w{postgresql listen_address}],
|
||||
[%w{gitlab_ci db_port}, %w{postgresql port}],
|
||||
].each do |left, right|
|
||||
if ! Gitlab[left.first][left.last].nil?
|
||||
# If the user explicitly sets a value for e.g.
|
||||
# gitlab_rails['db_port'] in gitlab.rb then we should never override
|
||||
# that.
|
||||
next
|
||||
end
|
||||
|
||||
better_value_from_gitlab_rb = Gitlab[right.first][right.last]
|
||||
default_from_attributes = node['gitlab'][right.first.gsub('_', '-')][right.last]
|
||||
Gitlab[left.first][left.last] = better_value_from_gitlab_rb || default_from_attributes
|
||||
end
|
||||
end
|
||||
|
||||
def parse_nginx_listen_address
|
||||
return unless nginx['listen_address']
|
||||
|
||||
|
@ -263,6 +290,7 @@ module Gitlab
|
|||
parse_git_data_dir
|
||||
parse_udp_log_shipping
|
||||
parse_redis_settings
|
||||
parse_postgresql_settings
|
||||
parse_nginx_listen_address
|
||||
# Parse ci_external_url _before_ gitlab_ci settings so that the user
|
||||
# can turn on gitlab_ci by only specifying ci_external_url
|
||||
|
|
|
@ -81,23 +81,13 @@ template_symlink File.join(gitlab_ci_etc_dir, "secret") do
|
|||
restarts dependent_services
|
||||
end
|
||||
|
||||
database_attributes = node['gitlab']['gitlab-ci'].to_hash
|
||||
if node['gitlab']['postgresql']['enable']
|
||||
database_attributes.merge!(
|
||||
:db_adapter => "postgresql",
|
||||
:db_username => node['gitlab']['postgresql']['sql_ci_user'],
|
||||
:db_host => node['gitlab']['postgresql']['listen_address'],
|
||||
:db_port => node['gitlab']['postgresql']['port']
|
||||
)
|
||||
end
|
||||
|
||||
template_symlink File.join(gitlab_ci_etc_dir, "database.yml") do
|
||||
link_from File.join(gitlab_ci_source_dir, "config/database.yml")
|
||||
source "database.yml.erb"
|
||||
owner "root"
|
||||
group "root"
|
||||
mode "0644"
|
||||
variables database_attributes
|
||||
variables node['gitlab']['gitlab-ci'].to_hash
|
||||
helpers SingleQuoteHelper
|
||||
restarts dependent_services
|
||||
end
|
||||
|
|
|
@ -79,23 +79,13 @@ template_symlink File.join(gitlab_rails_etc_dir, "secret") do
|
|||
restarts dependent_services
|
||||
end
|
||||
|
||||
database_attributes = node['gitlab']['gitlab-rails'].to_hash
|
||||
if node['gitlab']['postgresql']['enable']
|
||||
database_attributes.merge!(
|
||||
:db_adapter => "postgresql",
|
||||
:db_username => node['gitlab']['postgresql']['sql_user'],
|
||||
:db_host => node['gitlab']['postgresql']['listen_address'],
|
||||
:db_port => node['gitlab']['postgresql']['port']
|
||||
)
|
||||
end
|
||||
|
||||
template_symlink File.join(gitlab_rails_etc_dir, "database.yml") do
|
||||
link_from File.join(gitlab_rails_source_dir, "config/database.yml")
|
||||
source "database.yml.erb"
|
||||
owner "root"
|
||||
group "root"
|
||||
mode "0644"
|
||||
variables database_attributes
|
||||
variables node['gitlab']['gitlab-rails'].to_hash
|
||||
helpers SingleQuoteHelper
|
||||
restarts dependent_services
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue