orchestration 0.5.14 → 0.6.3

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.
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'orchestration'
4
+ puts Orchestration.makefile
@@ -3,7 +3,7 @@
3
3
  module Orchestration
4
4
  class ServiceCheck
5
5
  ATTEMPT_LIMIT = ENV.fetch('ORCHESTRATION_RETRY_LIMIT', '15').to_i
6
- RETRY_INTERVAL = ENV.fetch('ORCHESTRATION_RETRY_INTERVAL', '10').to_i
6
+ RETRY_INTERVAL = ENV.fetch('ORCHESTRATION_RETRY_INTERVAL', '15').to_i
7
7
 
8
8
  def initialize(service, terminal, options = {})
9
9
  @service = service
@@ -31,36 +31,36 @@ module Orchestration
31
31
  @service.connect
32
32
  true
33
33
  rescue *@service.connection_errors => e
34
- @attempts += 1
35
- sleep @retry_interval
34
+ wait_failure(e)
36
35
  retry unless @attempts == @attempt_limit
37
36
  echo_error(e)
38
37
  echo_failure
39
38
  false
40
39
  end
41
40
 
42
- def echo_start
43
- @terminal.write(@service_name.to_sym, '', :status)
41
+ def wait_failure(error)
42
+ @attempts += 1
43
+ @last_error = error
44
+ sleep @retry_interval
44
45
  end
45
46
 
46
- def echo_waiting
47
- @terminal.write(:waiting, service_waiting)
47
+ def last_error
48
+ return nil if @last_error.nil?
49
+
50
+ last_error_message
48
51
  end
49
52
 
50
- def service_waiting
51
- I18n.t(
52
- "orchestration.#{@service_name}.waiting",
53
- config: friendly_config,
54
- default: default_waiting
55
- )
53
+ def last_error_message
54
+ "(#{@last_error&.cause&.class&.name || @last_error&.class&.name})"
56
55
  end
57
56
 
58
- def default_waiting
59
- I18n.t(
60
- 'orchestration.custom_service.waiting',
61
- config: friendly_config,
62
- service: @service_name
63
- )
57
+ def echo_start
58
+ @terminal.write(@service_name.to_sym, '', :status)
59
+ @terminal.write(:config, friendly_config)
60
+ end
61
+
62
+ def echo_waiting
63
+ @terminal.write(:waiting, last_error)
64
64
  end
65
65
 
66
66
  def echo_ready
@@ -68,30 +68,16 @@ module Orchestration
68
68
  end
69
69
 
70
70
  def service_ready
71
- I18n.t(
72
- "orchestration.#{@service_name}.ready",
73
- config: friendly_config,
74
- default: default_ready
75
- )
76
- end
77
-
78
- def default_ready
79
- I18n.t(
80
- 'orchestration.custom_service.ready',
81
- config: friendly_config,
82
- service: @service_name
83
- )
71
+ I18n.t('orchestration.service.ready', service: @service_name)
84
72
  end
85
73
 
86
74
  def echo_failure
87
- @terminal.write(
88
- :failure,
89
- I18n.t('orchestration.attempt_limit', limit: @attempt_limit)
90
- )
75
+ @terminal.write(:failure, I18n.t('orchestration.attempt_limit', limit: @attempt_limit))
91
76
  end
92
77
 
93
78
  def echo_error(error)
94
- @terminal.write(:error, "[#{error.class.name}] #{error.message}")
79
+ cause = error.cause.nil? ? error : error.cause
80
+ @terminal.write(:error, "[#{cause.class.name}] #{cause.message}")
95
81
  end
96
82
 
97
83
  def friendly_config
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orchestration
4
+ module Services
5
+ module Database
6
+ module Adapters
7
+ module AdapterBase
8
+ attr_reader :config
9
+
10
+ def initialize(config = nil)
11
+ @config = config
12
+ end
13
+
14
+ def console_command
15
+ I18n.t("orchestration.dbconsole.#{name}") % config.settings.transform_keys(&:to_sym)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -5,6 +5,8 @@ module Orchestration
5
5
  module Database
6
6
  module Adapters
7
7
  class Mysql2
8
+ include AdapterBase
9
+
8
10
  def name
9
11
  'mysql2'
10
12
  end
@@ -5,6 +5,8 @@ module Orchestration
5
5
  module Database
6
6
  module Adapters
7
7
  class Postgresql
8
+ include AdapterBase
9
+
8
10
  def name
9
11
  'postgresql'
10
12
  end
@@ -5,6 +5,8 @@ module Orchestration
5
5
  module Database
6
6
  module Adapters
7
7
  class Sqlite3
8
+ include AdapterBase
9
+
8
10
  def name
9
11
  'sqlite3'
10
12
  end
@@ -9,6 +9,7 @@ module Orchestration
9
9
  end
10
10
  end
11
11
 
12
+ require 'orchestration/services/database/adapters/adapter_base'
12
13
  require 'orchestration/services/database/adapters/mysql2'
13
14
  require 'orchestration/services/database/adapters/postgresql'
14
15
  require 'orchestration/services/database/adapters/sqlite3'
@@ -33,6 +33,10 @@ module Orchestration
33
33
  sqlite? || super
34
34
  end
35
35
 
36
+ def console_command
37
+ adapter.console_command
38
+ end
39
+
36
40
  def adapter
37
41
  url_adapter = url_config['adapter']
38
42
  file_adapter = file_config['adapter']
@@ -115,7 +119,7 @@ module Orchestration
115
119
  'mysql' => adapters::Mysql2,
116
120
  'postgresql' => adapters::Postgresql,
117
121
  'sqlite3' => adapters::Sqlite3
118
- }.fetch(name).new
122
+ }.fetch(name).new(self)
119
123
  rescue KeyError
120
124
  Orchestration.error('database.unknown_adapter', adapter: name.inspect)
121
125
  raise
@@ -53,7 +53,7 @@ module Orchestration
53
53
  local, remote = parse_port(service).map(&:to_i)
54
54
  return remote if @env.environment == 'test' && @options[:sidecar]
55
55
 
56
- (@env.environment == 'production' ? remote : local)
56
+ (@env.environment == 'deployment' ? remote : local)
57
57
  end
58
58
 
59
59
  def service
@@ -2,7 +2,7 @@ FROM ruby:<%= ruby_version %>
2
2
  ARG BUNDLE_BITBUCKET__ORG
3
3
  ARG BUNDLE_GITHUB__COM
4
4
  ARG GIT_COMMIT
5
- RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
5
+ RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \
6
6
  && apt-get update \
7
7
  && DEBIAN_FRONTEND=noninteractive apt-get install -y \
8
8
  nodejs \
@@ -13,17 +13,15 @@ RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
13
13
  && mkdir /app<%if defined?(Webpacker) %> \
14
14
  && curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash \
15
15
  && . /root/.bashrc \
16
- && nvm install 10.13.0 \
16
+ && nvm install 14.16.0 \
17
17
  && npm config set user 0 \
18
18
  && npm config set unsafe-perm true \
19
19
  && npm install -g yarn<% end %>
20
20
  WORKDIR /app
21
21
  COPY .build/Gemfile .build/Gemfile.lock ./
22
- RUN bundle install --without development test --deployment
23
- <% if defined?(Webpacker) %>
24
- COPY .build/package.json .build/yarn.lock ./
25
- RUN . /root/.bashrc ; yarn install
26
- <% end %>
22
+ RUN bundle config set deployment 'true' \
23
+ && bundle config set without 'development test' \
24
+ && bundle install
27
25
  ADD .build/context.tar .
28
26
  <% if defined?(Webpacker) %>RUN . /root/.bashrc ; NODE_ENV=production RAILS_ENV=production yarn install && NODE_ENV=production RAILS_ENV=production SECRET_KEY_BASE=abc123 bundle exec rake assets:precompile<% elsif Rake::Task.tasks.map(&:name).include?('assets:precompile') %>RUN NODE_ENV=production RAILS_ENV=production SECRET_KEY_BASE=abc123 bundle exec rake assets:precompile<% end %>
29
27
  RUN echo "${GIT_COMMIT}" > /app/GIT_COMMIT
@@ -1,20 +1,36 @@
1
+ include $(shell bundle exec ruby -e 'require "orchestration/make"')
2
+
1
3
  #
2
4
  # Example test command
3
5
  #
4
- # This command will call `test-setup` before running your usual test pipeline.
6
+ # Define your test tasks here. The default command runs RSpec and Rubocop but
7
+ # you can feel free to add any other tasks you like.
5
8
  #
6
- # `test-setup` starts all containers specified in `docker-compose.test.yml`,
7
- # waits for them to be ready, and runs DB migrations.
9
+ # Set up your test dependencies and run tests by calling: `make setup test`
8
10
  #
9
- # In your CI environment, simply run `make test`.
11
+ # Subsequent test runs can skip the setup step and simply run: `make test`
10
12
  #
11
13
  .PHONY: test
12
- test: test-setup
14
+ test:
13
15
  bundle exec rspec
14
16
  bundle exec rubocop
15
17
 
16
- # Start development containers and create/migrate/seed database
17
- .PHONY: develop
18
+ #
19
+ # Define any custom setup that needs to take place before running tests.
20
+ # If the command exists, it will be called immediately after the `setup`
21
+ # command (which starts containers and sets up the database).
22
+ #
23
+ # This command can be deleted if it is not needed.
24
+ #
25
+ .PHONY: post-setup
26
+ post-setup:
27
+ @# Setup tasks that are not already provided by Orchestration go here.
28
+
29
+ #
30
+ # Launch all dependencies needed for a development environment and set up the
31
+ # development database.
32
+ #
33
+ .PHONY: setup
18
34
  develop:
19
35
  bundle install
20
36
  @$(MAKE) start env=test
@@ -1,6 +1,6 @@
1
1
  environment ENV.fetch('RAILS_ENV') { 'development' }
2
2
 
3
- port ENV.fetch('WEB_PORT') { 8080 }
3
+ port ENV.fetch('WEB_PORT') { 3000 }
4
4
  workers ENV.fetch('WEB_CONCURRENCY') { 4 }
5
5
  threads_count = ENV.fetch('RAILS_MAX_THREADS') { 8 }
6
6
 
@@ -4,7 +4,6 @@ module Orchestration
4
4
  COLOR_MAP = {
5
5
  failure: %i[red bright],
6
6
  error: %i[red],
7
- waiting: %i[yellow],
8
7
  ready: %i[green],
9
8
  create: %i[green],
10
9
  update: %i[yellow],
@@ -12,7 +11,9 @@ module Orchestration
12
11
  status: %i[blue],
13
12
  setup: %i[blue],
14
13
  input: %i[red],
15
- skip: %i[yellow bright]
14
+ skip: %i[yellow bright],
15
+ waiting: %i[yellow],
16
+ config: %i[cyan]
16
17
  }.freeze
17
18
 
18
19
  class Terminal
@@ -20,7 +21,7 @@ module Orchestration
20
21
  @settings = settings
21
22
  end
22
23
 
23
- def write(desc, message, color_name = nil, newline: true)
24
+ def write(desc, message = nil, color_name = nil, newline: true)
24
25
  output = newline ? "#{message}\n" : message.to_s
25
26
  $stdout.print colorize(desc, output, color_name)
26
27
  $stdout.flush
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orchestration
4
- VERSION = '0.5.14'
4
+ VERSION = '0.6.3'
5
5
  end
data/lib/orchestration.rb CHANGED
@@ -36,6 +36,10 @@ module Orchestration
36
36
  Pathname.new(File.dirname(__dir__))
37
37
  end
38
38
 
39
+ def self.makefile
40
+ root.join('lib', 'orchestration', 'make', 'orchestration.mk')
41
+ end
42
+
39
43
  def self.rakefile
40
44
  root.join('lib', 'Rakefile')
41
45
  end
@@ -8,11 +8,9 @@ namespace :orchestration do
8
8
  Orchestration::InstallGenerator.start
9
9
  end
10
10
 
11
- namespace :install do
12
- desc I18n.t('orchestration.rake.install_makefile')
13
- task :makefile do
14
- Orchestration::InstallGenerator.new.orchestration_makefile
15
- end
11
+ desc I18n.t('orchestration.makefile')
12
+ task :makefile do
13
+ Orchestration.makefile
16
14
  end
17
15
 
18
16
  desc I18n.t('orchestration.rake.config')
@@ -21,6 +19,26 @@ namespace :orchestration do
21
19
  puts "#{config['docker']['organization']} #{config['docker']['repository']}"
22
20
  end
23
21
 
22
+ namespace :db do
23
+ desc I18n.t('orchestration.rake.db.url')
24
+ task :url do
25
+ config = Rails.application.config_for(:database)
26
+
27
+ if config[:adapter] == 'sqlite3'
28
+ puts "sqlite3:#{config[:database]}"
29
+ else
30
+ puts DatabaseUrl.to_active_record_url(config)
31
+ end
32
+ end
33
+
34
+ desc I18n.t('orchestration.rake.db.console')
35
+ task :console do
36
+ env = Orchestration::Environment.new
37
+ options = ENV['db'] ? { config_path: "config/database.#{ENV['db']}.yml" } : {}
38
+ sh Orchestration::Services::Database::Configuration.new(env, nil, options).console_command
39
+ end
40
+ end
41
+
24
42
  desc I18n.t('orchestration.rake.healthcheck')
25
43
  task :healthcheck do
26
44
  Orchestration::DockerHealthcheck.execute
@@ -28,7 +46,6 @@ namespace :orchestration do
28
46
 
29
47
  desc I18n.t('orchestration.rake.wait')
30
48
  task :wait do
31
- Orchestration::InstallGenerator.new.verify_makefile(skip: false)
32
49
  env = Orchestration::Environment.new
33
50
  services = Orchestration::Services
34
51
  env.docker_compose_config['services'].each do |name, _service|
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_runtime_dependency 'erubis', '~> 2.7'
31
31
  spec.add_runtime_dependency 'i18n', '>= 0.5'
32
32
  spec.add_runtime_dependency 'paint', '~> 2.0'
33
+ spec.add_runtime_dependency 'rails', '~> 6.0'
33
34
  spec.add_runtime_dependency 'thor', '~> 1.0'
34
35
 
35
36
  spec.add_development_dependency 'activerecord', '~> 6.0'
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.5.14
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-25 00:00:00.000000000 Z
11
+ date: 2021-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: database_url
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '6.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '6.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: thor
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -335,6 +349,7 @@ files:
335
349
  - Makefile
336
350
  - README.md
337
351
  - Rakefile
352
+ - UPGRADE.md
338
353
  - bin/console
339
354
  - bin/setup
340
355
  - config/locales/en.yml
@@ -355,6 +370,8 @@ files:
355
370
  - lib/orchestration/errors.rb
356
371
  - lib/orchestration/file_helpers.rb
357
372
  - lib/orchestration/install_generator.rb
373
+ - lib/orchestration/make.rb
374
+ - lib/orchestration/make/orchestration.mk
358
375
  - lib/orchestration/railtie.rb
359
376
  - lib/orchestration/service_check.rb
360
377
  - lib/orchestration/services.rb
@@ -363,6 +380,7 @@ files:
363
380
  - lib/orchestration/services/app/healthcheck.rb
364
381
  - lib/orchestration/services/database.rb
365
382
  - lib/orchestration/services/database/adapters.rb
383
+ - lib/orchestration/services/database/adapters/adapter_base.rb
366
384
  - lib/orchestration/services/database/adapters/mysql2.rb
367
385
  - lib/orchestration/services/database/adapters/postgresql.rb
368
386
  - lib/orchestration/services/database/adapters/sqlite3.rb
@@ -386,9 +404,7 @@ files:
386
404
  - lib/orchestration/templates/database.yml.erb
387
405
  - lib/orchestration/templates/entrypoint.sh.erb
388
406
  - lib/orchestration/templates/env.erb
389
- - lib/orchestration/templates/makefile_macros.mk.erb
390
407
  - lib/orchestration/templates/mongoid.yml.erb
391
- - lib/orchestration/templates/orchestration.mk.erb
392
408
  - lib/orchestration/templates/puma.rb.erb
393
409
  - lib/orchestration/templates/rabbitmq.yml.erb
394
410
  - lib/orchestration/templates/unicorn.rb.erb