Class: Orchestration::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestration/environment.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Environment

Returns a new instance of Environment.



6
7
8
# File 'lib/orchestration/environment.rb', line 6

def initialize(options = {})
  @environment = options.fetch(:environment, nil)
end

Instance Method Details

#app_nameObject



93
94
95
# File 'lib/orchestration/environment.rb', line 93

def app_name
  settings.get('docker.repository')
end

#app_portObject



89
90
91
# File 'lib/orchestration/environment.rb', line 89

def app_port
  ENV.fetch('PUBLISH_PORT', ENV.fetch('WEB_PORT', '3000')).to_i
end

#database_configuration_pathObject



40
41
42
# File 'lib/orchestration/environment.rb', line 40

def database_configuration_path
  root.join('config', 'database.yml')
end

#database_urlObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/orchestration/environment.rb', line 21

def database_url
  case environment
  when 'development'
    ENV.fetch('DEVELOPMENT_DATABASE_URL', nil) || ENV.fetch('DATABASE_URL', nil)
  when 'test'
    ENV.fetch('TEST_DATABASE_URL', nil) || ENV.fetch('DATABASE_URL', nil)
  else
    ENV.fetch('DATABASE_URL', nil)
  end
end

#database_volumeObject



115
116
117
# File 'lib/orchestration/environment.rb', line 115

def database_volume
  'database'
end

#default_app_nameObject



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

def default_app_name
  default = docker_filter(root.basename.to_s, underscore: true)
  return default unless defined?(Rails)
  # Edge case if Rails is used as a dependency but we are not a Rails app:
  return default if rails_application == Object

  docker_filter(rails_application.name.underscore, underscore: true)
end

#docker_api_versionObject



56
57
58
# File 'lib/orchestration/environment.rb', line 56

def docker_api_version
  '3.7'
end

#docker_compose_config(env = nil) ⇒ Object



66
67
68
69
# File 'lib/orchestration/environment.rb', line 66

def docker_compose_config(env = nil)
  env ||= environment
  YAML.safe_load(File.read(docker_compose_path(env)))
end

#docker_compose_config?(env = nil) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/orchestration/environment.rb', line 71

def docker_compose_config?(env = nil)
  env ||= environment
  docker_compose_path(env).file?
end

#docker_compose_path(env = nil) ⇒ Object



60
61
62
63
64
# File 'lib/orchestration/environment.rb', line 60

def docker_compose_path(env = nil)
  env ||= 'development'

  orchestration_root.join("docker-compose.#{env}.yml")
end

#environmentObject



10
11
12
13
14
# File 'lib/orchestration/environment.rb', line 10

def environment
  return @environment unless @environment.nil?

  ENV.fetch('RAILS_ENV', nil) || ENV.fetch('RACK_ENV', nil) || 'development'
end

#mongo_urlObject



32
33
34
# File 'lib/orchestration/environment.rb', line 32

def mongo_url
  ENV.fetch('MONGO_URL', nil)
end

#mongo_volumeObject



119
120
121
# File 'lib/orchestration/environment.rb', line 119

def mongo_volume
  'mongo'
end

#mongoid_configuration_pathObject



36
37
38
# File 'lib/orchestration/environment.rb', line 36

def mongoid_configuration_path
  root.join('config', 'mongoid.yml')
end

#orchestration_configuration_pathObject



52
53
54
# File 'lib/orchestration/environment.rb', line 52

def orchestration_configuration_path
  root.join('.orchestration.yml')
end

#orchestration_dir_nameObject



111
112
113
# File 'lib/orchestration/environment.rb', line 111

def orchestration_dir_name
  'orchestration'
end

#orchestration_rootObject



107
108
109
# File 'lib/orchestration/environment.rb', line 107

def orchestration_root
  root.join(orchestration_dir_name)
end

#rabbitmq_configuration_pathObject



44
45
46
# File 'lib/orchestration/environment.rb', line 44

def rabbitmq_configuration_path
  root.join('config', 'rabbitmq.yml')
end

#rabbitmq_urlObject



85
86
87
# File 'lib/orchestration/environment.rb', line 85

def rabbitmq_url
  ENV.fetch('RABBITMQ_URL', nil)
end

#redis_configuration_pathObject



48
49
50
# File 'lib/orchestration/environment.rb', line 48

def redis_configuration_path
  root.join('config', 'redis.yml')
end

#rootObject



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

def root
  defined?(Rails) && Rails.root ? Rails.root : Pathname.new(Dir.pwd)
rescue NoMethodError
  Pathname.new(Dir.pwd)
end

#settingsObject



97
98
99
# File 'lib/orchestration/environment.rb', line 97

def settings
  Settings.new(orchestration_configuration_path)
end

#web_serverObject



16
17
18
19
# File 'lib/orchestration/environment.rb', line 16

def web_server
  # Used at installation time only
  ENV.fetch('server', 'puma')
end