Commit ab3d30c7 authored by Toon Claes's avatar Toon Claes

Dump settings from Rakefile

Add 2 new targets:
- gdk.example.yml: Dumps the default configuration to file
- dump_config: Dumps the current configuration to stdout
parent 507bbeb7
......@@ -8,10 +8,29 @@ def config
@config ||= GDK::Config.new
end
desc 'Dump the configured settings'
task 'dump_config' do
GDK::Config.new.dump!(STDOUT)
end
desc 'Generate an example config file with all the defaults'
file 'gdk.example.yml' do |t|
File.open(t.name, File::CREAT|File::TRUNC|File::WRONLY) do |file|
config = Class.new(GDK::Config)
config.define_method(:gdk_root) { '/home/git/gdk' }
config.define_method(:username) { 'git' }
config.define_method(:read!) { |_| nil }
config.new(yaml: {}).dump!(file)
end
end
desc 'Generate Procfile for Foreman'
file 'Procfile' => ['Procfile.erb', GDK::Config::FILE] do |t|
GDK::ErbRenderer.new(t.source, t.name).safe_render!
end
desc 'Generate nginx configuration'
file 'nginx/conf/nginx.conf' => ['nginx/conf/nginx.conf.erb', GDK::Config::FILE] do |t|
GDK::ErbRenderer.new(t.source, t.name).safe_render!
end
---
gdk_root: "/home/git/gdk"
username: git
repositories:
gitlab: https://gitlab.com/gitlab-org/gitlab-ce.git
gitlab_shell: https://gitlab.com/gitlab-org/gitlab-shell.git
gitlab_workhorse: https://gitlab.com/gitlab-org/gitlab-workhorse.git
gitaly: https://gitlab.com/gitlab-org/gitaly.git
gitaly_proto: https://gitlab.com/gitlab-org/gitaly-proto.git
gitlab_pages: https://gitlab.com/gitlab-org/gitlab-pages.git
gitlab_docs: https://gitlab.com/gitlab-com/gitlab-docs.git
gitaly:
assembly_dir: "/home/git/gdk/gitaly/assembly"
gitlab_pages:
port: 3034
enabled: true
port: 3000
registry:
port: 5000
enabled: false
host: 127.0.0.1
external_port: 5000
https: false
relative_url_root:
webpack:
port: 3806
object_store:
port: 9000
enabled: false
geo:
enabled: false
auto_devops:
gitlab:
port: 20000
enabled: false
registry:
port: 25000
tracer:
build_tags: tracer_static tracer_static_jaeger
jaeger:
version: 1.10.1
enabled: true
elasticsearch:
version: 6.5.1
checksum: 5903e1913a7c96aad96a8227517c40490825f672
git:
bin: "/usr/bin/git"
nginx:
workhorse_port: 3333
enabled: false
bin: '/usr/sbin/nginx'
postgresql:
bin_dir: "/usr/lib/postgresql/9.6/bin"
dir: "/home/git/gdk/postgresql"
replication_user: gitlab_replication
data_dir: "/home/git/gdk/postgresql/data"
replica_dir: "/home/git/gdk/postgresql-replica"
geo_dir: "/home/git/gdk/postgresql-geo"
hostname: localhost
sshd:
bin: '/usr/sbin/sshd'
......@@ -6,7 +6,7 @@ module GDK
class ConfigSettings
SettingUndefined = Class.new(StandardError)
attr_accessor :parent, :yaml
attr_reader :parent, :yaml, :key
def self.method_missing(name, *args, &blk)
if !args.empty?
......@@ -21,24 +21,35 @@ module GDK
sub = Class.new(ConfigSettings)
blk.call(sub)
sub.new(parent: self, yaml: yaml.fetch(name.to_s, {}))
sub.new(parent: self, yaml: yaml.fetch(name.to_s, {}), key: [key, name].compact.join('.'))
end
else
raise SettingUndefined, "Could not find the setting '#{name}'"
end
end
# Provide a shorter form for `config.setting.enabled` as `config.setting?`
def method_missing(method_name, *args, &blk)
enabled = enabled_value(method_name)
def initialize(parent: nil, yaml: nil, key: nil)
@parent = parent
@key = key
@yaml = yaml || load_yaml!
end
return super if enabled.nil?
def dump!(file = nil)
base_methods = ConfigSettings.new.methods
enabled
end
yaml = (methods - base_methods).inject({}) do |hash, method|
value = public_send(method)
if value.is_a?(ConfigSettings)
hash[method.to_s] = value.dump!
else
hash[method.to_s] = value
end
hash
end
def respond_to_missing?(method_name, include_private = false)
!enabled_value(method_name).nil? || super
file.puts(yaml.to_yaml) if file
yaml
end
def cmd!(cmd)
......@@ -58,16 +69,28 @@ module GDK
value
end
def initialize(parent: nil, yaml: nil)
@parent = parent
@yaml = yaml || load_yaml!
end
def root
parent&.root || self
end
alias_method :config, :root
def inspect
"#<GDK::ConfigSettings key:#{key}>"
end
# Provide a shorter form for `config.setting.enabled` as `config.setting?`
def method_missing(method_name, *args, &blk)
enabled = enabled_value(method_name)
return super if enabled.nil?
enabled
end
def respond_to_missing?(method_name, include_private = false)
!enabled_value(method_name).nil? || super
end
private
def enabled_value(method_name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment