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
88 89 90 |
# File 'lib/orchestration/environment.rb', line 88 def app_name settings.get('docker.repository') end |
#app_port ⇒ Object
84 85 86 |
# File 'lib/orchestration/environment.rb', line 84 def app_port ENV.fetch('PUBLISH_PORT', ENV.fetch('WEB_PORT', '3000')).to_i end |
#database_configuration_path ⇒ Object
39 40 41 |
# File 'lib/orchestration/environment.rb', line 39 def database_configuration_path root.join('config', 'database.yml') end |
#database_url ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/orchestration/environment.rb', line 20 def database_url case environment when 'development' ENV['DEVELOPMENT_DATABASE_URL'] || ENV['DATABASE_URL'] when 'test' ENV['TEST_DATABASE_URL'] || ENV['DATABASE_URL'] else ENV['DATABASE_URL'] end end |
#database_volume ⇒ Object
110 111 112 |
# File 'lib/orchestration/environment.rb', line 110 def database_volume 'database' end |
#default_app_name ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/orchestration/environment.rb', line 71 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_version ⇒ Object
51 52 53 |
# File 'lib/orchestration/environment.rb', line 51 def docker_api_version '3.7' end |
#docker_compose_config(env = nil) ⇒ Object
61 62 63 64 |
# File 'lib/orchestration/environment.rb', line 61 def docker_compose_config(env = nil) env ||= environment YAML.safe_load(File.read(docker_compose_path(env))) end |
#docker_compose_config?(env = nil) ⇒ Boolean
66 67 68 69 |
# File 'lib/orchestration/environment.rb', line 66 def docker_compose_config?(env = nil) env ||= environment docker_compose_path(env).file? end |
#docker_compose_path(env = nil) ⇒ Object
55 56 57 58 59 |
# File 'lib/orchestration/environment.rb', line 55 def docker_compose_path(env = nil) env ||= 'development' 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
31 32 33 |
# File 'lib/orchestration/environment.rb', line 31 def mongo_url ENV['MONGO_URL'] end |
#mongo_volume ⇒ Object
114 115 116 |
# File 'lib/orchestration/environment.rb', line 114 def mongo_volume 'mongo' end |
#mongoid_configuration_path ⇒ Object
35 36 37 |
# File 'lib/orchestration/environment.rb', line 35 def mongoid_configuration_path root.join('config', 'mongoid.yml') end |
#orchestration_configuration_path ⇒ Object
47 48 49 |
# File 'lib/orchestration/environment.rb', line 47 def orchestration_configuration_path root.join('.orchestration.yml') end |
#orchestration_dir_name ⇒ Object
106 107 108 |
# File 'lib/orchestration/environment.rb', line 106 def orchestration_dir_name 'orchestration' end |
#orchestration_root ⇒ Object
102 103 104 |
# File 'lib/orchestration/environment.rb', line 102 def orchestration_root root.join(orchestration_dir_name) end |
#rabbitmq_configuration_path ⇒ Object
43 44 45 |
# File 'lib/orchestration/environment.rb', line 43 def rabbitmq_configuration_path root.join('config', 'rabbitmq.yml') end |
#rabbitmq_url ⇒ Object
80 81 82 |
# File 'lib/orchestration/environment.rb', line 80 def rabbitmq_url ENV.fetch('RABBITMQ_URL', nil) end |
#root ⇒ Object
96 97 98 99 100 |
# File 'lib/orchestration/environment.rb', line 96 def root defined?(Rails) && Rails.root ? Rails.root : Pathname.new(Dir.pwd) rescue NoMethodError Pathname.new(Dir.pwd) end |
#settings ⇒ Object
92 93 94 |
# File 'lib/orchestration/environment.rb', line 92 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 |