orchestration 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ff223f91a5979874db88e7e55a788b9c7a645f5
4
- data.tar.gz: d910c778ab54470515efdfa2f514853a91f5f0ea
3
+ metadata.gz: c7209f425f6556b4cb2ea6747c24f69556faef24
4
+ data.tar.gz: 6b538236943c3c773221b0c6908b16e4dc89d5ac
5
5
  SHA512:
6
- metadata.gz: e03236d51bfd3476b89cbe27a3811f2e4455c1c50b741901bd98a9db539cd029df39d8bdd0547228279b532252a1a484e7716f37c0f86a82c162847ff48a293a
7
- data.tar.gz: 1538b05bdf17e1ecb6478992aff82ededd06cbfcf23b87dec959f2a8afc66cc408f5171de36539d9ba148b0b66372e57126c7f7023c0b135fbbefff881b6853d
6
+ metadata.gz: e6a949edc104c97a4b68520e37127ab654c75825505bfe0d8831eb0f786ce2cee75c5a900ecd5c19d0313c2bdaf89ad115632c5b5554344a974f36271439e0c8
7
+ data.tar.gz: 28ca0e8e45f4109ff081f9581d62fa5466b3dcbba648ebe6c392c4c0d3d45d1375c72e9165e72b0f845a15b9973f7b9dbb3cba8b2a636043242a8c92596585f9
data/.gitignore CHANGED
@@ -23,4 +23,6 @@ spec/dummy/docker/*
23
23
  spec/dummy/docker-compose.yml
24
24
  spec/dummy/config/unicorn.rb
25
25
 
26
+ orchestration-*.gem
27
+
26
28
  .byebug_history
@@ -16,7 +16,7 @@ en:
16
16
  waiting: "Waiting for Mongo: %{config}"
17
17
  ready: "Mongo is ready."
18
18
 
19
- nginxproxy:
19
+ nginx-proxy:
20
20
  waiting: "Waiting for Nginx proxy: %{config}"
21
21
  ready: "Nginx proxy is ready."
22
22
 
@@ -24,5 +24,34 @@ en:
24
24
  waiting: "Waiting for RabbitMQ: %{config}"
25
25
  ready: "RabbitMQ is ready."
26
26
 
27
+ custom_service:
28
+ waiting: "Waiting for [%{service}]: %{config}"
29
+ ready: "[%{service}] is ready."
30
+
27
31
  docker:
28
32
  username_request: "Enter your Docker registry username (used for tagging images)"
33
+
34
+ rake:
35
+ docker:
36
+ username: "Output configured Docker username"
37
+
38
+ application:
39
+ wait: "Wait for database to become available"
40
+
41
+ database:
42
+ wait: "Wait for database to become available"
43
+
44
+ listener:
45
+ wait: "Wait for a locally-bound service to accept connections (pass `service=NAME`)"
46
+
47
+ mongo:
48
+ wait: "Wait for Mongo to become available"
49
+
50
+ nginx-proxy:
51
+ wait: "Wait for Nginx proxy to become available"
52
+
53
+ rabbitmq:
54
+ wait: "Wait for RabbitMQ to become available"
55
+
56
+ rabbitmq:
57
+ wait: "Initialise boilerplate for adding Docker to your application"
@@ -7,7 +7,7 @@ module Orchestration
7
7
 
8
8
  def initialize(service, terminal, options = {})
9
9
  @service = service
10
- @service_name = service_name(service)
10
+ @service_name = service.service_name
11
11
  @terminal = terminal
12
12
  @attempt_limit = options.fetch(:attempt_limit, ATTEMPT_LIMIT)
13
13
  @retry_interval = options.fetch(:retry_interval, RETRY_INTERVAL)
@@ -42,22 +42,42 @@ module Orchestration
42
42
  end
43
43
 
44
44
  def echo_waiting
45
- @terminal.write(
46
- :waiting,
47
- I18n.t(
48
- "orchestration.#{@service_name}.waiting",
49
- config: @service.configuration.friendly_config
50
- )
45
+ @terminal.write(:waiting, service_waiting)
46
+ end
47
+
48
+ def service_waiting
49
+ I18n.t(
50
+ "orchestration.#{@service_name}.waiting",
51
+ config: friendly_config,
52
+ default: default_waiting
53
+ )
54
+ end
55
+
56
+ def default_waiting
57
+ I18n.t(
58
+ 'orchestration.custom_service.waiting',
59
+ config: friendly_config,
60
+ service: @service_name
51
61
  )
52
62
  end
53
63
 
54
64
  def echo_ready
55
- @terminal.write(
56
- :ready,
57
- I18n.t(
58
- "orchestration.#{@service_name}.ready",
59
- config: @service.configuration.friendly_config
60
- )
65
+ @terminal.write(:ready, service_ready)
66
+ end
67
+
68
+ def service_ready
69
+ I18n.t(
70
+ "orchestration.#{@service_name}.ready",
71
+ config: friendly_config,
72
+ default: default_ready
73
+ )
74
+ end
75
+
76
+ def default_ready
77
+ I18n.t(
78
+ 'orchestration.custom_service.ready',
79
+ config: friendly_config,
80
+ service: @service_name
61
81
  )
62
82
  end
63
83
 
@@ -72,10 +92,8 @@ module Orchestration
72
92
  @terminal.write(:error, "[#{error.class.name}] #{error.message}")
73
93
  end
74
94
 
75
- def service_name(service)
76
- # e.g.:
77
- # Orchestration::Services::RabbitMQ::Healthcheck => 'rabbitmq'
78
- service.class.name.split('::')[-2].downcase
95
+ def friendly_config
96
+ @service.configuration.friendly_config
79
97
  end
80
98
  end
81
99
  end
@@ -10,6 +10,7 @@ require 'orchestration/services/healthcheck_base'
10
10
 
11
11
  require 'orchestration/services/application'
12
12
  require 'orchestration/services/database'
13
+ require 'orchestration/services/listener'
13
14
  require 'orchestration/services/mongo'
14
15
  require 'orchestration/services/nginx_proxy'
15
16
  require 'orchestration/services/rabbitmq'
@@ -8,8 +8,8 @@ module Orchestration
8
8
 
9
9
  self.service_name = 'application'
10
10
 
11
- def initialize(env)
12
- @env = env
11
+ def initialize(env, service_name = nil)
12
+ super
13
13
  @settings = {} # Included for interface consistency; currently unused.
14
14
  end
15
15
 
@@ -6,10 +6,6 @@ module Orchestration
6
6
  class Healthcheck
7
7
  include HealthcheckBase
8
8
 
9
- def initialize(env)
10
- @configuration = Configuration.new(env)
11
- end
12
-
13
9
  def connect
14
10
  response = Net::HTTP.get_response(
15
11
  URI("http://localhost:#{@configuration.local_port}")
@@ -3,7 +3,7 @@
3
3
  module Orchestration
4
4
  module Services
5
5
  module ConfigurationBase
6
- attr_reader :settings
6
+ attr_reader :settings, :service_name
7
7
 
8
8
  def self.included(base)
9
9
  base.extend(ClassMethods)
@@ -22,13 +22,17 @@ module Orchestration
22
22
  end
23
23
  end
24
24
 
25
+ def initialize(env, service_name = nil)
26
+ @env = env
27
+ @service_name = service_name || self.class.service_name
28
+ end
29
+
25
30
  def host
26
31
  'localhost'
27
32
  end
28
33
 
29
34
  def local_port
30
- name = self.class.service_name
31
- key = name == 'application' ? 'nginx-proxy' : name
35
+ key = @service_name == 'application' ? 'nginx-proxy' : @service_name
32
36
 
33
37
  @env.docker_compose_config
34
38
  .fetch('services')
@@ -10,8 +10,8 @@ module Orchestration
10
10
 
11
11
  attr_reader :adapter
12
12
 
13
- def initialize(env)
14
- @env = env
13
+ def initialize(env, service_name = nil)
14
+ super
15
15
  @adapter = nil
16
16
  @settings = nil
17
17
  return unless defined?(ActiveRecord)
@@ -8,10 +8,6 @@ module Orchestration
8
8
 
9
9
  dependencies 'active_record'
10
10
 
11
- def initialize(env)
12
- @configuration = Configuration.new(env)
13
- end
14
-
15
11
  def connect
16
12
  ActiveRecord::Base.establish_connection(@configuration.settings)
17
13
  ActiveRecord::Base.connection
@@ -16,7 +16,8 @@ module Orchestration
16
16
  options.delete(:exit_on_error)
17
17
  env ||= Environment.new
18
18
  terminal ||= Terminal.new
19
- check = ServiceCheck.new(new(env), terminal, options)
19
+ name = options.delete(:service_name)
20
+ check = ServiceCheck.new(new(env, name), terminal, options)
20
21
 
21
22
  exit 1 if !check.run && exit_on_error
22
23
  end
@@ -33,6 +34,22 @@ module Orchestration
33
34
  @dependencies.map { |dependency| require dependency }
34
35
  end
35
36
  end
37
+
38
+ def initialize(env, service_name = nil)
39
+ @configuration = configuration_class.new(env, service_name)
40
+ end
41
+
42
+ def service_name
43
+ @configuration.service_name
44
+ end
45
+
46
+ private
47
+
48
+ def configuration_class
49
+ # Find the relevant `Configuration` class for whatever `Healthcheck`
50
+ # class we happen to be included in.
51
+ self.class.parent.const_get(:Configuration)
52
+ end
36
53
  end
37
54
  end
38
55
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orchestration
4
+ module Services
5
+ module Listener
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'orchestration/services/listener/configuration'
11
+ require 'orchestration/services/listener/healthcheck'
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orchestration
4
+ module Services
5
+ module Listener
6
+ class Configuration
7
+ include ConfigurationBase
8
+
9
+ def self.service_name
10
+ raise ArgumentError
11
+ end
12
+
13
+ def friendly_config
14
+ "[#{@service_name}] #{host}:#{local_port}"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orchestration
4
+ module Services
5
+ module Listener
6
+ class Healthcheck
7
+ include HealthcheckBase
8
+
9
+ def connect
10
+ Net::HTTP.start('localhost', @configuration.local_port)
11
+ end
12
+
13
+ def connection_errors
14
+ [Errno::ECONNREFUSED]
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -8,8 +8,8 @@ module Orchestration
8
8
 
9
9
  self.service_name = 'mongo'
10
10
 
11
- def initialize(env)
12
- @env = env
11
+ def initialize(env, service_name = nil)
12
+ super
13
13
  @settings = nil
14
14
  return unless defined?(Mongoid)
15
15
  return unless File.exist?(@env.mongoid_configuration_path)
@@ -8,10 +8,6 @@ module Orchestration
8
8
 
9
9
  dependencies 'mongoid'
10
10
 
11
- def initialize(env)
12
- @configuration = Configuration.new(env)
13
- end
14
-
15
11
  def connection_errors
16
12
  [::Mongo::Error::NoServerAvailable]
17
13
  end
@@ -8,10 +8,6 @@ module Orchestration
8
8
 
9
9
  self.service_name = 'nginx-proxy'
10
10
 
11
- def initialize(env)
12
- @env = env
13
- end
14
-
15
11
  def friendly_config
16
12
  "[nginx-proxy] #{host}:#{local_port}"
17
13
  end
@@ -6,12 +6,8 @@ module Orchestration
6
6
  class Healthcheck
7
7
  include HealthcheckBase
8
8
 
9
- def initialize(env)
10
- @configuration = Configuration.new(env)
11
- end
12
-
13
9
  def connect
14
- Net::HTTP.start('localhost', 3000)
10
+ Net::HTTP.start('localhost', @configuration.local_port)
15
11
  end
16
12
 
17
13
  def connection_errors
@@ -8,8 +8,8 @@ module Orchestration
8
8
 
9
9
  self.service_name = 'rabbitmq'
10
10
 
11
- def initialize(env)
12
- @env = env
11
+ def initialize(env, service_name = nil)
12
+ super
13
13
  @settings = nil
14
14
  return unless defined?(RabbitMQ)
15
15
  return unless File.exist?(@env.rabbitmq_configuration_path)
@@ -8,10 +8,6 @@ module Orchestration
8
8
 
9
9
  dependencies 'bunny'
10
10
 
11
- def initialize(env)
12
- @configuration = Configuration.new(env)
13
- end
14
-
15
11
  def connection_errors
16
12
  [
17
13
  Bunny::TCPConnectionFailedForAllHosts,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orchestration
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.4'
5
5
  end
@@ -3,48 +3,48 @@
3
3
  require 'orchestration'
4
4
 
5
5
  namespace :orchestration do
6
- desc 'Initialise boilerplate for adding Docker to your application'
6
+ desc I18n.t('orchestration.rake.install')
7
7
  task :install do
8
8
  Orchestration::InstallGenerator.start
9
9
  end
10
10
 
11
11
  namespace :application do
12
- desc 'Wait for application to become available'
12
+ desc I18n.t('orchestration.application.wait')
13
13
  task :wait do
14
14
  Orchestration::Services::Application::Healthcheck.start
15
15
  end
16
16
  end
17
17
 
18
18
  namespace :database do
19
- desc 'Wait for database to become available'
19
+ desc I18n.t('orchestration.database.wait')
20
20
  task :wait do
21
21
  Orchestration::Services::Database::Healthcheck.start
22
22
  end
23
23
  end
24
24
 
25
25
  namespace :mongo do
26
- desc 'Wait for mongo to become available'
26
+ desc I18n.t('orchestration.mongo.wait')
27
27
  task :wait do
28
28
  Orchestration::Services::Mongo::Healthcheck.start
29
29
  end
30
30
  end
31
31
 
32
32
  namespace :nginx_proxy do
33
- desc 'Wait for Nginx proxy to become available'
33
+ desc I18n.t('orchestration.nginx-proxy.wait')
34
34
  task :wait do
35
35
  Orchestration::Services::NginxProxy::Healthcheck.start
36
36
  end
37
37
  end
38
38
 
39
39
  namespace :rabbitmq do
40
- desc 'Wait for database to become available'
40
+ desc I18n.t('orchestration.rabbitmq.wait')
41
41
  task :wait do
42
42
  Orchestration::Services::RabbitMQ::Healthcheck.start
43
43
  end
44
44
  end
45
45
 
46
46
  namespace :docker do
47
- desc 'Output configured Docker username'
47
+ desc I18n.t('orchestration.rake.listener.wait')
48
48
  task :username do
49
49
  STDOUT.write(
50
50
  Orchestration::Environment.new.settings.get('docker.username')
@@ -52,4 +52,13 @@ namespace :orchestration do
52
52
  STDOUT.flush
53
53
  end
54
54
  end
55
+
56
+ namespace :listener do
57
+ desc I18n.t('orchestration.rake.listener.wait')
58
+ task :wait do
59
+ Orchestration::Services::Listener::Healthcheck.start(
60
+ nil, nil, service_name: ENV.fetch('service')
61
+ )
62
+ end
63
+ end
55
64
  end
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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-02 00:00:00.000000000 Z
11
+ date: 2018-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -315,6 +315,9 @@ files:
315
315
  - lib/orchestration/services/database/configuration.rb
316
316
  - lib/orchestration/services/database/healthcheck.rb
317
317
  - lib/orchestration/services/healthcheck_base.rb
318
+ - lib/orchestration/services/listener.rb
319
+ - lib/orchestration/services/listener/configuration.rb
320
+ - lib/orchestration/services/listener/healthcheck.rb
318
321
  - lib/orchestration/services/mongo.rb
319
322
  - lib/orchestration/services/mongo/configuration.rb
320
323
  - lib/orchestration/services/mongo/healthcheck.rb