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



36
37
38
39
40
# File 'lib/orchestration/install_generator.rb', line 36

def application_makefile
  path = @env.root.join('Makefile')
  simple_copy('application.mk', path) unless File.exist?(path)
  inject_if_missing(path, 'include orchestration/Makefile')
end

#database_ymlObject



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

def database_yml
  return unless defined?(ActiveRecord)

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

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

#deploy_mkObject



125
126
127
# File 'lib/orchestration/install_generator.rb', line 125

def deploy_mk
  simple_copy('deploy.mk')
end

#docker_composeObject



67
68
69
70
71
72
73
74
# File 'lib/orchestration/install_generator.rb', line 67

def docker_compose
  @docker_compose.docker_compose_yml
  @docker_compose.docker_compose_test_yml
  @docker_compose.docker_compose_development_yml
  @docker_compose.docker_compose_local_yml
  @docker_compose.docker_compose_production_yml
  @docker_compose.docker_compose_override_yml
end

#dockerfileObject



42
43
44
45
46
47
48
# File 'lib/orchestration/install_generator.rb', line 42

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

#entrypoint_shObject



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

def 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



121
122
123
# File 'lib/orchestration/install_generator.rb', line 121

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

#gitignoreObject



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

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

  ensure_lines_in_file(path, entries)
end

#healthcheckObject



113
114
115
# File 'lib/orchestration/install_generator.rb', line 113

def healthcheck
  simple_copy('healthcheck.rb')
end

#mongoid_ymlObject



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

def 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
  path = @env.orchestration_configuration_path
  @terminal.ask_setting('docker.organization')
  @terminal.ask_setting('docker.repository', @env.default_app_name)
  relpath = relative_path(path)
  return @terminal.write(:create, relpath) unless @settings.exist? || force?
  return @terminal.write(:update, relpath) if @settings.dirty?

  @terminal.write(:skip, relpath)
end

#orchestration_makefileObject



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

def orchestration_makefile
  content = template('orchestration.mk', makefile_environment)
  path = @env.orchestration_root.join('Makefile')
  path.exist? ? update_file(path, content) : create_file(path, content)
end

#pumaObject



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

def puma
  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



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

def rabbitmq_yml
  return unless defined?(Bunny)

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

#unicornObject



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

def unicorn
  return nil unless @env.web_server == 'unicorn'

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

#yaml_bashObject



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

def yaml_bash
  simple_copy('yaml.bash')
end