orchestration 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d46427ecb6cb0665a6be31e5e49cd6a01a8c2f5148442f3c1bcc3852c87c83e9
4
- data.tar.gz: d622198cebd4619d573f391f9eae23d68bea32606619f4d8965032c1eb096a98
3
+ metadata.gz: 3423dc31e2b526868cb869c930d6f73039437939aa7b2ceb859e0e8106536344
4
+ data.tar.gz: 4669fd75876e047f52d256dd2f2e3840ecd42f157b04c6f4f81e315ae96ca6ff
5
5
  SHA512:
6
- metadata.gz: 89364f65e27bb9f05213a4a6c64351b1fc9e1b2e12eb890d4b90f2b1338cdab7e04b1dc1a43cf155d6fafe1f838c3c8a903dcccc1bf80b557e38a371aee902eb
7
- data.tar.gz: 69aca6c30ba0fcbd2a8d1172a8e4904a88e8fe3d0875281f6cd8a2245e601d36c45fcbbd4f784b39935e6195a5d13c87cb5f1a0f8247823e3a2de2e209caf71e
6
+ metadata.gz: 2a4f0579b2698d30103975b175b8a4cdc1df51c5ce883560f2b11f24b8fd3307fd1e6a35868689f6152d182e07ddbc65b6f081fe4b33ae1114e7957b64338c02
7
+ data.tar.gz: 380413ccb1b108614ad09247a2435178a042c352775712b287c79e707938aa409290ab42f9b0b5d7cc32184fe73de200a8a551ae5c24ba37b3c08655e4caeaf0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orchestration (0.7.0)
4
+ orchestration (0.7.2)
5
5
  database_url (~> 0.1.2)
6
6
  erubis (~> 2.7)
7
7
  i18n
@@ -173,6 +173,7 @@ GEM
173
173
  rainbow (3.1.1)
174
174
  rake (13.0.6)
175
175
  rbtree (0.4.5)
176
+ redis (4.6.0)
176
177
  regexp_parser (2.4.0)
177
178
  rexml (3.2.5)
178
179
  rspec (3.11.0)
@@ -248,6 +249,7 @@ DEPENDENCIES
248
249
  pg (~> 1.3)
249
250
  rails
250
251
  rake (~> 13.0)
252
+ redis (~> 4.6)
251
253
  rspec (~> 3.11)
252
254
  rspec-its (~> 1.3)
253
255
  rubocop (~> 1.28)
data/README.md CHANGED
@@ -31,7 +31,7 @@ Add _Orchestration_ to your `Gemfile`:
31
31
  _Ruby 3.x_:
32
32
 
33
33
  ```ruby
34
- gem 'orchestration', '~> 0.7.1'
34
+ gem 'orchestration', '~> 0.7.2'
35
35
  ```
36
36
 
37
37
  _Ruby 2.x_:
@@ -67,6 +67,7 @@ _Orchestration_ generates the following files where appropriate. Backups are cre
67
67
  * `config/database.yml`
68
68
  * `config/mongoid.yml`
69
69
  * `config/rabbitmq.yml` (see [RabbitMQ Configuration](#rabbitmq-configuration) for more details)
70
+ * `config/redis.yml` (see [Redis Configuration](#redis-configuration) for more details)
70
71
  * `config/unicorn.rb`
71
72
  * `config/puma.rb`
72
73
 
@@ -396,13 +397,6 @@ make stop RAILS_ENV=test
396
397
  <a name="rabbitmq-configuration"></a>
397
398
  ## RabbitMQ Configuration
398
399
 
399
- The [Bunny](https://github.com/ruby-amqp/bunny) _RabbitMQ_ gem does not recognise `config/rabbitmq.yml` or `RABBITMQ_URL`. If your application uses _RabbitMQ_ then you must manually update your code to reference this file, e.g.:
400
-
401
- ```ruby
402
- connection = Bunny.new(config_for(:rabbit_mq)['url'])
403
- connection.start
404
- ```
405
-
406
400
  _Orchestration_ generates the following `config/rabbitmq.yml`:
407
401
 
408
402
  ```
@@ -419,10 +413,42 @@ production:
419
413
  management_url: <%= ENV['RABBITMQ_MANAGEMENT_URL'] %>
420
414
  ```
421
415
 
416
+ The [Bunny](https://github.com/ruby-amqp/bunny) _RabbitMQ_ gem does not recognise `config/rabbitmq.yml` or `RABBITMQ_URL`. If your application uses _RabbitMQ_ then you must manually update your code to reference this file, e.g.:
417
+
418
+ ```ruby
419
+ connection = Bunny.new(Rails.application.config_for(:rabbit_mq)['url'])
420
+ connection.start
421
+ ```
422
+
422
423
  Using this approach, the environment variable `RABBITMQ_URL` can be used to configure _Bunny_ in production (similar to `DATABASE_URL` and `MONGO_URL`).
423
424
 
424
425
  This is a convention of the _Orchestration_ gem intended to make _RabbitMQ_ configuration consistent with other services.
425
426
 
427
+ <a name="redis-configuration"></a>
428
+ ## Redis Configuration
429
+
430
+ _Orchestration_ generates the following `config/redis.yml`:
431
+
432
+ ```
433
+ development:
434
+ url: redis://127.0.0.1:51071
435
+
436
+ test:
437
+ url: redis://127.0.0.1:51069
438
+ ```
439
+
440
+ The [Redis](https://github.com/redis/redis-rb) gem does not recognise `config/redis.yml`. If your application uses _Redis_ then you must manually update your code to reference this file, e.g.:
441
+
442
+ ```ruby
443
+ # config/initializers/redis.rb
444
+
445
+ ENV['REDIS_URL'] ||= Rails.application.config_for(:redis)['url']
446
+ ```
447
+ _Redis_ will then use `REDIS_URL` for all connections.
448
+
449
+ This allows `development` and `test` environments to auto-load the correct config for the relevant containers while also allowing `production` to use either the auto-generated _Redis_ service or an external _Redis_ instance.
450
+
451
+
426
452
  ## Alternate Database Configuration Files
427
453
 
428
454
  If you have multiple databases configured in various `config/database.*.yml` files then the `make wait` command will automatically detect database configurations.
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Orchestration
4
4
  module DockerCompose
5
+ # rubocop:disable Metrics/ClassLength
5
6
  class AppService
6
7
  include ComposeHelpers
7
8
 
@@ -99,13 +100,19 @@ module Orchestration
99
100
  'WEB_HEALTHCHECK_PATH' => '/healthcheck',
100
101
  'WEB_PORT' => 8080,
101
102
  'DATABASE_URL' => database_url
102
- }.merge(inherited_environment.to_h { |key| [key, nil] }).merge(rabbitmq_urls)
103
+ }.merge(inherited_environment.to_h { |key| [key, nil] }).merge(rabbitmq_urls).merge(redis_url)
103
104
  end
104
105
 
105
106
  def rabbitmq_urls
106
107
  return {} unless Services::RabbitMQ::Configuration.new(Environment.new).enabled?
107
108
 
108
- { 'RABBITMQ_URL' => 'amqp://rabbitmq:5672', 'RABBITMQ_MANAGEMENT_URL' => 'http://rabbitmq:15672' }
109
+ { 'RABBITMQ_URL' => 'amqp://rabbitmq-local:5672', 'RABBITMQ_MANAGEMENT_URL' => 'http://rabbitmq-local:15672' }
110
+ end
111
+
112
+ def redis_url
113
+ return {} unless Services::Redis::Configuration.new(Environment.new).enabled?
114
+
115
+ { 'REDIS_URL' => "redis://redis-local:#{Services::Redis::PORT}" }
109
116
  end
110
117
 
111
118
  def database_url
@@ -124,5 +131,6 @@ module Orchestration
124
131
  ['${PUBLISH_PORT:?PUBLISH_PORT must be provided}:8080']
125
132
  end
126
133
  end
134
+ # rubocop:enable Metrics/ClassLength
127
135
  end
128
136
  end
@@ -39,7 +39,7 @@ module Orchestration
39
39
  return nil unless listener?(name)
40
40
  return ports(name).first[:local].to_i if remote_port.nil?
41
41
 
42
- ports(name).find { |mapping| mapping[:remote] == remote_port }
42
+ ports(name).find { |mapping| mapping[:remote].to_i == remote_port.to_i }
43
43
  .fetch(:local)
44
44
  .to_i
45
45
  rescue NoMethodError
@@ -32,7 +32,8 @@ module Orchestration
32
32
  app: AppService,
33
33
  database: DatabaseService,
34
34
  mongo: MongoService,
35
- rabbitmq: RabbitMQService
35
+ rabbitmq: RabbitMQService,
36
+ redis: RedisService
36
37
  }
37
38
  end
38
39
 
@@ -67,9 +67,9 @@ module Orchestration
67
67
  def service_names(environment)
68
68
  case environment
69
69
  when :test, :development
70
- %i[database mongo rabbitmq]
70
+ %i[database mongo rabbitmq redis]
71
71
  when :deployment
72
- %i[app database mongo rabbitmq]
72
+ %i[app database mongo rabbitmq redis]
73
73
  when :local, nil
74
74
  []
75
75
  else
@@ -88,7 +88,8 @@ module Orchestration
88
88
  app: Orchestration::Services::App::Configuration,
89
89
  database: Orchestration::Services::Database::Configuration,
90
90
  mongo: Orchestration::Services::Mongo::Configuration,
91
- rabbitmq: Orchestration::Services::RabbitMQ::Configuration
91
+ rabbitmq: Orchestration::Services::RabbitMQ::Configuration,
92
+ redis: Orchestration::Services::Redis::Configuration
92
93
  }.fetch(service).new(@env)
93
94
  end
94
95
 
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orchestration
4
+ module DockerCompose
5
+ class RedisService
6
+ include ComposeHelpers
7
+
8
+ def initialize(config, environment)
9
+ @config = config
10
+ @environment = environment
11
+ end
12
+
13
+ def definition
14
+ return nil unless @config.enabled?
15
+
16
+ { 'image' => 'library/redis:7.0', 'networks' => networks }.merge(ports)
17
+ end
18
+
19
+ def ports
20
+ return {} unless %i[development test].include?(@environment)
21
+
22
+ container_port = Orchestration::Services::Redis::PORT
23
+
24
+ { 'ports' => ["#{sidecar_port(@environment)}#{container_port}"] }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -14,3 +14,4 @@ require 'orchestration/docker_compose/app_service'
14
14
  require 'orchestration/docker_compose/database_service'
15
15
  require 'orchestration/docker_compose/mongo_service'
16
16
  require 'orchestration/docker_compose/rabbitmq_service'
17
+ require 'orchestration/docker_compose/redis_service'
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orchestration
4
+ # rubocop:disable Metrics/ClassLength
4
5
  class Environment
5
6
  def initialize(options = {})
6
7
  @environment = options.fetch(:environment, nil)
@@ -44,6 +45,10 @@ module Orchestration
44
45
  root.join('config', 'rabbitmq.yml')
45
46
  end
46
47
 
48
+ def redis_configuration_path
49
+ root.join('config', 'redis.yml')
50
+ end
51
+
47
52
  def orchestration_configuration_path
48
53
  root.join('.orchestration.yml')
49
54
  end
@@ -136,4 +141,5 @@ module Orchestration
136
141
  end.join
137
142
  end
138
143
  end
144
+ # rubocop:enable Metrics/ClassLength
139
145
  end
@@ -72,7 +72,7 @@ module Orchestration
72
72
  end
73
73
 
74
74
  def database_yml
75
- return unless defined?(ActiveRecord)
75
+ return unless defined?(::ActiveRecord)
76
76
 
77
77
  adapter = DockerCompose::ComposeConfiguration.database_adapter_name
78
78
  return if adapter == 'sqlite3'
@@ -81,17 +81,23 @@ module Orchestration
81
81
  end
82
82
 
83
83
  def mongoid_yml
84
- return unless defined?(Mongoid)
84
+ return unless defined?(::Mongoid)
85
85
 
86
86
  service_config('mongoid.yml', Services::Mongo::Configuration)
87
87
  end
88
88
 
89
89
  def rabbitmq_yml
90
- return unless defined?(Bunny)
90
+ return unless defined?(::Bunny)
91
91
 
92
92
  service_config('rabbitmq.yml', Services::RabbitMQ::Configuration)
93
93
  end
94
94
 
95
+ def redis_yml
96
+ return unless defined?(::Redis)
97
+
98
+ service_config('redis.yml', Services::Redis::Configuration)
99
+ end
100
+
95
101
  def env
96
102
  simple_copy('env', @env.root.join('.env'), overwrite: false)
97
103
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orchestration
4
+ module Services
5
+ module Redis
6
+ class Configuration
7
+ include ConfigurationBase
8
+
9
+ self.service_name = 'redis'
10
+
11
+ def enabled?
12
+ defined?(::Redis)
13
+ end
14
+
15
+ def friendly_config
16
+ "[redis] redis://#{host}:#{port}"
17
+ end
18
+
19
+ def host
20
+ from_url['host'] || super
21
+ end
22
+
23
+ def port
24
+ from_url['port'] || super
25
+ end
26
+
27
+ private
28
+
29
+ def from_url
30
+ return {} if @env.redis_url.nil?
31
+
32
+ uri = URI.parse(@env.redis_url)
33
+ { 'host' => uri.host, 'port' => uri.port || PORT }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orchestration
4
+ module Services
5
+ module Redis
6
+ class Healthcheck
7
+ class NotConnectedError < OrchestrationError; end
8
+
9
+ include HealthcheckBase
10
+
11
+ dependencies 'redis'
12
+
13
+ def connection_errors
14
+ [NotConnectedError]
15
+ end
16
+
17
+ def connect
18
+ host = @configuration.host
19
+ port = @configuration.port
20
+ return if ::Redis.new(url: "redis://#{host}:#{port}").connected?
21
+
22
+ raise NotConnectedError
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orchestration
4
+ module Services
5
+ module Redis
6
+ PORT = 6379
7
+ end
8
+ end
9
+ end
10
+
11
+ require 'orchestration/services/redis/configuration'
12
+ require 'orchestration/services/redis/healthcheck'
@@ -14,3 +14,4 @@ require 'orchestration/services/database'
14
14
  require 'orchestration/services/listener'
15
15
  require 'orchestration/services/mongo'
16
16
  require 'orchestration/services/rabbitmq'
17
+ require 'orchestration/services/redis'
@@ -1,8 +1,8 @@
1
- environment ENV.fetch('RAILS_ENV') { 'development' }
1
+ environment ENV.fetch('RAILS_ENV', 'development')
2
2
 
3
- port ENV.fetch('WEB_PORT') { 3000 }
4
- workers ENV.fetch('WEB_CONCURRENCY') { 4 }
5
- threads_count = ENV.fetch('RAILS_MAX_THREADS') { 8 }
3
+ port ENV.fetch('WEB_PORT', 3000)
4
+ workers ENV.fetch('WEB_CONCURRENCY', 4)
5
+ threads_count = ENV.fetch('RAILS_MAX_THREADS', 8)
6
6
 
7
7
  pidfile './tmp/pids/server.pid'
8
8
  threads threads_count, threads_count
@@ -0,0 +1,9 @@
1
+ <% if compose.call('development').services.key?('redis') %>
2
+ development:
3
+ url: <%= "#{'<' + '%' + '='} ENV.fetch('REDIS_URL', 'redis://127.0.0.1:#{compose.call('development').local_port('redis', 6379)}') #{'%' + '>'}" %>
4
+ <% end %>
5
+
6
+ <% if compose.call('test').services.key?('redis') %>
7
+ test:
8
+ url: <%= "#{'<' + '%' + '='} ENV.fetch('REDIS_URL', 'redis://127.0.0.1:#{compose.call('test').local_port('redis', 6379)}') #{'%' + '>'}" %>
9
+ <% end %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orchestration
4
- VERSION = '0.7.1'
4
+ VERSION = '0.7.2'
5
5
  end
@@ -42,6 +42,7 @@ Gem::Specification.new do |spec|
42
42
  spec.add_development_dependency 'pg', '~> 1.3'
43
43
  spec.add_development_dependency 'rails'
44
44
  spec.add_development_dependency 'rake', '~> 13.0'
45
+ spec.add_development_dependency 'redis', '~> 4.6'
45
46
  spec.add_development_dependency 'rspec', '~> 3.11'
46
47
  spec.add_development_dependency 'rspec-its', '~> 1.3'
47
48
  spec.add_development_dependency 'rubocop', '~> 1.28'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orchestration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-27 00:00:00.000000000 Z
11
+ date: 2022-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: database_url
@@ -206,6 +206,20 @@ dependencies:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: '13.0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: redis
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '4.6'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '4.6'
209
223
  - !ruby/object:Gem::Dependency
210
224
  name: rspec
211
225
  requirement: !ruby/object:Gem::Requirement
@@ -367,6 +381,7 @@ files:
367
381
  - lib/orchestration/docker_compose/install_generator.rb
368
382
  - lib/orchestration/docker_compose/mongo_service.rb
369
383
  - lib/orchestration/docker_compose/rabbitmq_service.rb
384
+ - lib/orchestration/docker_compose/redis_service.rb
370
385
  - lib/orchestration/docker_healthcheck.rb
371
386
  - lib/orchestration/environment.rb
372
387
  - lib/orchestration/errors.rb
@@ -400,6 +415,9 @@ files:
400
415
  - lib/orchestration/services/rabbitmq.rb
401
416
  - lib/orchestration/services/rabbitmq/configuration.rb
402
417
  - lib/orchestration/services/rabbitmq/healthcheck.rb
418
+ - lib/orchestration/services/redis.rb
419
+ - lib/orchestration/services/redis/configuration.rb
420
+ - lib/orchestration/services/redis/healthcheck.rb
403
421
  - lib/orchestration/settings.rb
404
422
  - lib/orchestration/templates/Dockerfile.erb
405
423
  - lib/orchestration/templates/application.mk.erb
@@ -409,6 +427,7 @@ files:
409
427
  - lib/orchestration/templates/mongoid.yml.erb
410
428
  - lib/orchestration/templates/puma.rb.erb
411
429
  - lib/orchestration/templates/rabbitmq.yml.erb
430
+ - lib/orchestration/templates/redis.yml.erb
412
431
  - lib/orchestration/templates/unicorn.rb.erb
413
432
  - lib/orchestration/terminal.rb
414
433
  - lib/orchestration/version.rb