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
# File 'lib/orchestration/install_generator.rb', line 30

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

#database_ymlObject



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

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

#docker_composeObject



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

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

#dockerfileObject



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

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

#entrypoint_shObject



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

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



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

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

#gitignoreObject



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

def 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



83
84
85
86
87
# File 'lib/orchestration/install_generator.rb', line 83

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

#pumaObject



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

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



89
90
91
92
93
# File 'lib/orchestration/install_generator.rb', line 89

def rabbitmq_yml
  return unless defined?(Bunny)

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

#unicornObject



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

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)
  regex = /gem\s+['"]unicorn['"]/
  ensure_line_in_file(gemfile_path, "gem 'unicorn'", regex: regex)
end