Class: Orchestration::InstallGenerator

Inherits:
Thor::Group
  • Object
show all
Includes:
FileHelpers
Defined in:
lib/orchestration/install_generator.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ InstallGenerator

Returns a new instance of InstallGenerator.



11
12
13
14
15
16
17
# File 'lib/orchestration/install_generator.rb', line 11

def initialize(*_args)
  super
  @env = Environment.new
  @settings = Settings.new(@env.orchestration_configuration_path)
  @terminal = Terminal.new(@settings)
  @docker_compose = DockerCompose::InstallGenerator.new(@env, @terminal)
end

Instance Method Details

#application_makefileObject



30
31
32
33
34
35
# File 'lib/orchestration/install_generator.rb', line 30

def application_makefile
  return unless build?('Makefile')

  path = @env.root.join('Makefile')
  simple_copy('application.mk', path) unless File.exist?(path)
end

#database_ymlObject



84
85
86
87
88
89
90
91
92
# File 'lib/orchestration/install_generator.rb', line 84

def database_yml
  return unless build?('database.yml')
  return unless defined?(::ActiveRecord)

  adapter = DockerCompose::ComposeConfiguration.database_adapter_name
  return if adapter == 'sqlite3'

  service_config('database.yml', Services::Database::Configuration)
end

#docker_composeObject



56
57
58
59
60
61
62
# File 'lib/orchestration/install_generator.rb', line 56

def docker_compose
  return unless build?('docker-compose.yml')

  @docker_compose.docker_compose_test_yml
  @docker_compose.docker_compose_development_yml
  @docker_compose.docker_compose_deployment_yml
end

#dockerfileObject



37
38
39
40
41
42
43
44
45
# File 'lib/orchestration/install_generator.rb', line 37

def dockerfile
  return unless build?('Dockerfile')

  create_file(
    orchestration_dir.join('Dockerfile'),
    dockerfile_content,
    overwrite: false
  )
end

#entrypoint_shObject



47
48
49
50
51
52
53
54
# File 'lib/orchestration/install_generator.rb', line 47

def entrypoint_sh
  return unless build?('entrypoint.sh')

  content = template('entrypoint.sh')
  path = orchestration_dir.join('entrypoint.sh')
  create_file(path, content, overwrite: false)
  FileUtils.chmod('a+x', path)
end

#envObject



115
116
117
118
119
# File 'lib/orchestration/install_generator.rb', line 115

def env
  return unless build?('.env')

  simple_copy('env', @env.root.join('.env'), overwrite: false)
end

#gitignoreObject



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/orchestration/install_generator.rb', line 121

def gitignore
  return unless build?('.gitignore')

  path = @env.root.join('.gitignore')
  globs = %w[.build/ .deploy/ Gemfile Gemfile.lock docker-compose.local.yml]
  lines = %w[orchestration/.sidecar .env deploy.tar] + globs.map do |line|
    "#{@env.orchestration_dir_name}/#{line}"
  end

  ensure_lines_in_file(path, lines)
end

#mongoid_ymlObject



94
95
96
97
98
99
# File 'lib/orchestration/install_generator.rb', line 94

def mongoid_yml
  return unless build?('mongoid.yml')
  return unless defined?(::Mongoid)

  service_config('mongoid.yml', Services::Mongo::Configuration)
end

#orchestration_configurationObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/orchestration/install_generator.rb', line 19

def orchestration_configuration
  return unless build?('.orchestration.yml')

  configure_orchestration_settings
  relpath = relative_path(@env.orchestration_configuration_path)
  return @terminal.write(:create, relpath) unless @settings.exist? || force?
  return @terminal.write(:update, relpath) if @settings.dirty?

  @terminal.write(:skip, relpath)
end

#pumaObject



64
65
66
67
68
69
70
71
# File 'lib/orchestration/install_generator.rb', line 64

def puma
  return unless build?('puma.rb')
  return nil unless @env.web_server == 'puma'

  content = template('puma.rb')
  path = @env.root.join('config', 'puma.rb')
  create_file(path, content, backup: true)
end

#rabbitmq_ymlObject



101
102
103
104
105
106
# File 'lib/orchestration/install_generator.rb', line 101

def rabbitmq_yml
  return unless build?('rabbitmq.yml')
  return unless defined?(::Bunny)

  service_config('rabbitmq.yml', Services::RabbitMQ::Configuration)
end

#redis_ymlObject



108
109
110
111
112
113
# File 'lib/orchestration/install_generator.rb', line 108

def redis_yml
  return unless build?('redis.yml')
  return unless defined?(::Redis)

  service_config('redis.yml', Services::Redis::Configuration)
end

#unicornObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/orchestration/install_generator.rb', line 73

def unicorn
  return unless build?('unicorn.rb')
  return nil unless @env.web_server == 'unicorn'

  content = template('unicorn.rb')
  path = @env.root.join('config', 'unicorn.rb')
  create_file(path, content, backup: true)
  regex = /gem\s+['"]unicorn['"]/
  ensure_line_in_file(gemfile_path, "gem 'unicorn'", regex:)
end