Class: GDK::TaskHelpers::ConfigTasks

Inherits:
Object
  • Object
show all
Defined in:
lib/gdk/task_helpers/config_tasks.rb

Overview

Class to handle config tasks templates and make targets

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigTasks

Returns a new instance of ConfigTasks.



130
131
132
133
# File 'lib/gdk/task_helpers/config_tasks.rb', line 130

def initialize
  @template_tasks = []
  @make_tasks = []
end

Class Method Details

.buildObject



23
24
25
26
27
28
29
30
# File 'lib/gdk/task_helpers/config_tasks.rb', line 23

def self.build
  @tasks ||= new.tap do |tasks|
    define_template_tasks(tasks)
    define_make_tasks(tasks)
    # This should be the last task.
    define_makefile_config_task(tasks)
  end
end

.define_make_tasks(tasks) ⇒ Object

rubocop:enable Metrics/AbcSize



120
121
122
123
124
# File 'lib/gdk/task_helpers/config_tasks.rb', line 120

def self.define_make_tasks(tasks)
  tasks.add_make_task(name: 'gitlab-db-migrate', make_dependencies: ['ensure-databases-running'])
  tasks.add_make_task(name: 'preflight-checks', timed: true)
  tasks.add_make_task(name: 'preflight-update-checks', timed: true)
end

.define_makefile_config_task(tasks) ⇒ Object



126
127
128
# File 'lib/gdk/task_helpers/config_tasks.rb', line 126

def self.define_makefile_config_task(tasks)
  tasks.add_template(name: 'support/makefiles/Makefile.config.mk', template: 'support/templates/makefiles/Makefile.config.mk.erb', rake_dependencies: Dir['lib/**/*'], erb_extra_args: { tasks: tasks.all_with_makefile_target })
end

.define_template_tasks(tasks) ⇒ Object

rubocop:disable Metrics/AbcSize – A set of definitions which could be split up per component later



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/gdk/task_helpers/config_tasks.rb', line 33

def self.define_template_tasks(tasks)
  tasks.add_template(name: 'gdk.example.yml', rake_dependencies: ['clobber:gdk.example.yml'], generate_makefile_target: false)
  tasks.add_template(name: 'Procfile')
  tasks.add_template(name: 'gitlab/config/cable.yml')
  tasks.add_template(name: 'gitlab/config/database.yml')
  tasks.add_template(name: 'gitlab/config/gitlab.yml')
  tasks.add_template(name: 'gitlab/config/puma.rb')
  tasks.add_template(name: 'gitlab/config/redis.cache.yml', template: 'support/templates/gitlab/config/redis.sessions.yml.erb', erb_extra_args: { cluster: :cache })
  tasks.add_template(name: 'gitlab/config/redis.repository_cache.yml', template: 'support/templates/gitlab/config/redis.sessions.yml.erb', erb_extra_args: { cluster: :repository_cache })
  tasks.add_template(name: 'gitlab/config/redis.queues.yml', template: 'support/templates/gitlab/config/redis.sessions.yml.erb', erb_extra_args: { cluster: :queues })
  tasks.add_template(name: 'gitlab/config/redis.sessions.yml', erb_extra_args: { cluster: :sessions })
  tasks.add_template(name: 'gitlab/config/redis.shared_state.yml', template: 'support/templates/gitlab/config/redis.sessions.yml.erb', erb_extra_args: { cluster: :shared_state })
  tasks.add_template(name: 'gitlab/config/redis.trace_chunks.yml', template: 'support/templates/gitlab/config/redis.sessions.yml.erb', erb_extra_args: { cluster: :trace_chunks })
  tasks.add_template(name: 'gitlab/config/resque.yml', template: 'support/templates/gitlab/config/redis.sessions.yml.erb', erb_extra_args: { cluster: :shared_state })
  tasks.add_template(name: 'gitlab/config/session_store.yml', template: 'support/templates/gitlab/config/session_store.yml.erb')

  tasks.add_template(name: 'gitaly/gitaly.config.toml', erb_extra_args: { node: GDK.config.gitaly }, post_render: lambda do |_task|
    GDK.config.gitaly.__storages.each do |storage|
      FileUtils.mkdir_p(storage.path)
    end

    FileUtils.mkdir_p(GDK.config.gitaly.log_dir)
    FileUtils.mkdir_p(GDK.config.gitaly.runtime_dir)
    FileUtils.mkdir_p(GDK.config.gdk_root.join('gitaly-custom-hooks'))
  end)

  tasks.add_template(name: 'gitaly/praefect.config.toml', post_render: lambda do |_task|
    GDK.config.praefect.__nodes.each_with_index do |node, _|
      Rake::Task[node['config_file']].invoke
    end
  end)

  GDK.config.praefect.__nodes.each do |node|
    tasks.add_template(name: node['config_file'], template: 'support/templates/gitaly/gitaly.config.toml.erb', erb_extra_args: { node: node }, generate_makefile_target: false, post_render: lambda do |_task|
      node.__storages.each do |storage|
        FileUtils.mkdir_p(storage.path)
      end

      FileUtils.mkdir_p(node['log_dir'])
      FileUtils.mkdir_p(node['runtime_dir'])
    end)
  end

  if GDK.config.redis_cluster.enabled?
    tasks.add_template(name: 'gitlab/config/redis.rate_limiting.yml', template: 'support/templates/gitlab/config/redis.cluster.yml.erb')
  else
    tasks.add_template(name: 'gitlab/config/redis.rate_limiting.yml', template: 'support/templates/gitlab/config/redis.sessions.yml.erb', erb_extra_args: { cluster: :rate_limiting })
  end

  tasks.add_template(name: 'gitlab-topology-service/config.toml')
  tasks.add_template(name: 'gitlab-http-router/wrangler.toml', hide_diff: true)
  tasks.add_template(name: 'gitlab/config/vite.gdk.json')
  tasks.add_template(name: 'gitlab/workhorse/config.toml')
  tasks.add_template(name: 'gitlab-k8s-agent-config.yml')
  tasks.add_template(name: 'gitlab-pages/gitlab-pages.conf', make_dependencies: ['gitlab-pages/.git/pull'])
  tasks.add_template(name: 'gitlab-pages-secret', hide_diff: true)
  tasks.add_template(name: 'gitlab-runner-config.toml', no_op_condition: 'runner_enabled')
  tasks.add_template(name: 'gitlab-shell/config.yml', make_dependencies: ['gitlab-shell/.git'])
  tasks.add_template(name: 'gitlab-spamcheck/config/config.toml')
  tasks.add_template(name: 'grafana/grafana.ini')
  tasks.add_template(name: 'nginx/conf/nginx.conf')
  tasks.add_template(name: 'openbao/config.hcl')
  tasks.add_template(name: 'openssh/sshd_config')
  tasks.add_template(name: 'prometheus/prometheus.yml', post_render: ->(task) { chmod('+r', task.name, verbose: false) })
  tasks.add_template(name: 'redis/redis.conf')
  tasks.add_template(name: 'registry/config.yml', make_dependencies: ['registry_host.crt'])
  tasks.add_template(name: 'snowplow/snowplow_micro.conf', post_render: ->(task) { chmod('+r', task.name, verbose: false) })
  tasks.add_template(name: 'snowplow/iglu.json', post_render: ->(task) { chmod('+r', task.name, verbose: false) })
  tasks.add_template(name: 'clickhouse/config.xml', template: 'support/templates/clickhouse/config.xml')
  tasks.add_template(name: 'clickhouse/users.xml', template: 'support/templates/clickhouse/users.xml')
  tasks.add_template(name: 'clickhouse/config.d/data-paths.xml')
  tasks.add_template(name: 'clickhouse/config.d/gdk.xml')
  tasks.add_template(name: 'clickhouse/config.d/logger.xml')
  tasks.add_template(name: 'clickhouse/config.d/openssl.xml')
  tasks.add_template(name: 'clickhouse/config.d/user-directories.xml')
  tasks.add_template(name: 'clickhouse/users.d/gdk.xml')
  tasks.add_template(name: 'elasticsearch/config/elasticsearch.yml', template: 'support/templates/elasticsearch/config/elasticsearch.yml', no_op_condition: 'elasticsearch_enabled')
  tasks.add_template(name: 'elasticsearch/config/jvm.options.d/custom.options', template: 'support/templates/elasticsearch/config/jvm.options.d/custom.options', no_op_condition: 'elasticsearch_enabled')
  tasks.add_template(name: 'pgbouncers/pgbouncer-replica-1.ini', template: 'support/templates/pgbouncer/pgbouncer-replica.ini.erb', erb_extra_args: { host: GDK.config.postgresql.replica.host, port: GDK.config.postgresql.replica.port1 })
  tasks.add_template(name: 'pgbouncers/pgbouncer-replica-2.ini', template: 'support/templates/pgbouncer/pgbouncer-replica.ini.erb', erb_extra_args: { host: GDK.config.postgresql.replica.host, port: GDK.config.postgresql.replica.port2 })
  tasks.add_template(name: 'pgbouncers/pgbouncer-replica-2-1.ini', template: 'support/templates/pgbouncer/pgbouncer-replica.ini.erb', erb_extra_args: { host: GDK.config.postgresql.replica_2.host, port: GDK.config.postgresql.replica_2.port1 })
  tasks.add_template(name: 'pgbouncers/pgbouncer-replica-2-2.ini', template: 'support/templates/pgbouncer/pgbouncer-replica.ini.erb', erb_extra_args: { host: GDK.config.postgresql.replica_2.host, port: GDK.config.postgresql.replica_2.port2 })
  tasks.add_template(name: 'pgbouncers/userlist.txt', template: 'support/templates/pgbouncer/pgbouncer-userlist.txt.erb')
  tasks.add_template(name: 'consul/config.json', template: 'support/templates/consul/config.json.erb', erb_extra_args: { min_port: 6432, max_port: 6435 })
end

Instance Method Details

#add_make_task(**args) ⇒ Object



139
140
141
# File 'lib/gdk/task_helpers/config_tasks.rb', line 139

def add_make_task(**args)
  @make_tasks << Task.new(**args)
end

#add_template(**args) ⇒ Object



135
136
137
# File 'lib/gdk/task_helpers/config_tasks.rb', line 135

def add_template(**args)
  @template_tasks << Task.new(**args)
end

#all_tasksObject



155
156
157
# File 'lib/gdk/task_helpers/config_tasks.rb', line 155

def all_tasks
  template_tasks + make_tasks
end

#all_with_makefile_targetObject



159
160
161
# File 'lib/gdk/task_helpers/config_tasks.rb', line 159

def all_with_makefile_target
  all_tasks.select(&:generate_makefile_target)
end

#diffable_template_tasksObject



147
148
149
# File 'lib/gdk/task_helpers/config_tasks.rb', line 147

def diffable_template_tasks
  template_tasks.reject(&:hide_diff)
end

#make_tasksObject



151
152
153
# File 'lib/gdk/task_helpers/config_tasks.rb', line 151

def make_tasks
  @make_tasks.clone
end

#template_tasksObject



143
144
145
# File 'lib/gdk/task_helpers/config_tasks.rb', line 143

def template_tasks
  @template_tasks.clone
end