Class: Orchestration::Environment
- Inherits:
-
Object
- Object
- Orchestration::Environment
- Defined in:
- lib/orchestration/environment.rb
Instance Method Summary collapse
- #app_name ⇒ Object
- #app_port ⇒ Object
- #database_configuration_path ⇒ Object
- #database_url ⇒ Object
- #database_volume ⇒ Object
- #default_app_name ⇒ Object
- #docker_api_version ⇒ Object
- #docker_compose_config(env = nil) ⇒ Object
- #docker_compose_config?(env = nil) ⇒ Boolean
- #docker_compose_path(env = nil) ⇒ Object
- #environment ⇒ Object
-
#initialize(options = {}) ⇒ Environment
constructor
A new instance of Environment.
- #mongo_url ⇒ Object
- #mongo_volume ⇒ Object
- #mongoid_configuration_path ⇒ Object
- #orchestration_configuration_path ⇒ Object
- #orchestration_dir_name ⇒ Object
- #orchestration_root ⇒ Object
- #rabbitmq_configuration_path ⇒ Object
- #rabbitmq_url ⇒ Object
- #root ⇒ Object
- #settings ⇒ Object
- #web_server ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Environment
Returns a new instance of Environment.
5 6 7 |
# File 'lib/orchestration/environment.rb', line 5 def initialize( = {}) @environment = .fetch(:environment, nil) end |
Instance Method Details
#app_name ⇒ Object
81 82 83 |
# File 'lib/orchestration/environment.rb', line 81 def app_name settings.get('docker.repository') end |
#app_port ⇒ Object
77 78 79 |
# File 'lib/orchestration/environment.rb', line 77 def app_port ENV.fetch('CONTAINER_PORT', ENV.fetch('WEB_PORT', '3000')).to_i end |
#database_configuration_path ⇒ Object
32 33 34 |
# File 'lib/orchestration/environment.rb', line 32 def database_configuration_path root.join('config', 'database.yml') end |
#database_url ⇒ Object
20 21 22 |
# File 'lib/orchestration/environment.rb', line 20 def database_url ENV['DATABASE_URL'] end |
#database_volume ⇒ Object
103 104 105 |
# File 'lib/orchestration/environment.rb', line 103 def database_volume 'database' end |
#default_app_name ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/orchestration/environment.rb', line 64 def default_app_name default = root.basename.to_s 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.class.parent == Object Rails.application.class.parent.name.underscore end |
#docker_api_version ⇒ Object
44 45 46 |
# File 'lib/orchestration/environment.rb', line 44 def docker_api_version '3.7' end |
#docker_compose_config(env = nil) ⇒ Object
54 55 56 57 |
# File 'lib/orchestration/environment.rb', line 54 def docker_compose_config(env = nil) env ||= environment YAML.safe_load(File.read(docker_compose_path(env))) end |
#docker_compose_config?(env = nil) ⇒ Boolean
59 60 61 62 |
# File 'lib/orchestration/environment.rb', line 59 def docker_compose_config?(env = nil) env ||= environment docker_compose_path(env).file? end |
#docker_compose_path(env = nil) ⇒ Object
48 49 50 51 52 |
# File 'lib/orchestration/environment.rb', line 48 def docker_compose_path(env = nil) return orchestration_root.join('docker-compose.yml') if env.nil? orchestration_root.join("docker-compose.#{env}.yml") end |
#environment ⇒ Object
9 10 11 12 13 |
# File 'lib/orchestration/environment.rb', line 9 def environment return @environment unless @environment.nil? ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end |
#mongo_url ⇒ Object
24 25 26 |
# File 'lib/orchestration/environment.rb', line 24 def mongo_url ENV['MONGO_URL'] end |
#mongo_volume ⇒ Object
107 108 109 |
# File 'lib/orchestration/environment.rb', line 107 def mongo_volume 'mongo' end |
#mongoid_configuration_path ⇒ Object
28 29 30 |
# File 'lib/orchestration/environment.rb', line 28 def mongoid_configuration_path root.join('config', 'mongoid.yml') end |
#orchestration_configuration_path ⇒ Object
40 41 42 |
# File 'lib/orchestration/environment.rb', line 40 def orchestration_configuration_path root.join('.orchestration.yml') end |
#orchestration_dir_name ⇒ Object
99 100 101 |
# File 'lib/orchestration/environment.rb', line 99 def orchestration_dir_name 'orchestration' end |
#orchestration_root ⇒ Object
95 96 97 |
# File 'lib/orchestration/environment.rb', line 95 def orchestration_root root.join(orchestration_dir_name) end |
#rabbitmq_configuration_path ⇒ Object
36 37 38 |
# File 'lib/orchestration/environment.rb', line 36 def rabbitmq_configuration_path root.join('config', 'rabbitmq.yml') end |
#rabbitmq_url ⇒ Object
73 74 75 |
# File 'lib/orchestration/environment.rb', line 73 def rabbitmq_url ENV.fetch('RABBITMQ_URL', nil) end |
#root ⇒ Object
89 90 91 92 93 |
# File 'lib/orchestration/environment.rb', line 89 def root defined?(Rails) && Rails.root ? Rails.root : Pathname.new(Dir.pwd) rescue NoMethodError Pathname.new(Dir.pwd) end |
#settings ⇒ Object
85 86 87 |
# File 'lib/orchestration/environment.rb', line 85 def settings Settings.new(orchestration_configuration_path) end |
#web_server ⇒ Object
15 16 17 18 |
# File 'lib/orchestration/environment.rb', line 15 def web_server # Used at installation time only ENV.fetch('server', 'puma') end |