docker-stack 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.rubocop_todo.yml +2 -0
  4. data/Gemfile +2 -0
  5. data/Rakefile +2 -0
  6. data/bin/console +1 -0
  7. data/config/stack.yml +15 -0
  8. data/docker-stack.gemspec +2 -0
  9. data/lib/docker/stack.rb +14 -0
  10. data/lib/docker/stack/container.rb +2 -0
  11. data/lib/docker/stack/controller.rb +11 -13
  12. data/lib/docker/stack/localstack/endpoint_stub.rb +58 -0
  13. data/lib/docker/stack/rake_task.rb +2 -0
  14. data/lib/docker/stack/version.rb +3 -1
  15. data/lib/generators/docker/stack/install_generator.rb +2 -0
  16. data/lib/generators/docker/stack/service.rb +4 -5
  17. data/lib/generators/docker/stack/service/fedora_generator.rb +2 -0
  18. data/lib/generators/docker/stack/service/localstack_generator.rb +23 -0
  19. data/lib/generators/docker/stack/service/postgres_generator.rb +2 -0
  20. data/lib/generators/docker/stack/service/redis_generator.rb +2 -0
  21. data/lib/generators/docker/stack/service/solr_generator.rb +2 -0
  22. data/lib/generators/docker/stack/templates/config/database.yml +1 -2
  23. data/lib/generators/docker/stack/templates/config/fedora.yml +2 -2
  24. data/lib/generators/docker/stack/templates/config/initializers/localstack_stub.rb +5 -0
  25. data/lib/generators/docker/stack/templates/config/redis.yml +2 -2
  26. data/lib/generators/docker/stack/templates/config/solr.yml +2 -2
  27. data/lib/generators/docker/stack/templates/docker.rake +3 -1
  28. data/lib/generators/docker/stack/templates/services/fedora.yml.erb +1 -1
  29. data/lib/generators/docker/stack/templates/services/localstack.yml.erb +17 -0
  30. data/lib/generators/docker/stack/templates/services/postgres.yml.erb +1 -1
  31. data/lib/generators/docker/stack/templates/services/redis.yml.erb +1 -1
  32. data/lib/generators/docker/stack/templates/services/solr.yml.erb +1 -1
  33. data/lib/generators/docker/stack/util.rb +3 -1
  34. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcd36792e8fd4007c8d21e051c7d1752aa4ecbfb3dd98055f4b3914ac24d3799
4
- data.tar.gz: 6e87294ea6e21cc4e22e21987c1dfb4285eb790362c3ed4186cb87d86a2c8aca
3
+ metadata.gz: 459b321cbce7417b7e02f01e338162fabf1a1d9109757feff3d6675821ab17d4
4
+ data.tar.gz: 15e5832ed64387b472f60e5514171c64d7349daec651423feab004de11287c57
5
5
  SHA512:
6
- metadata.gz: d42f1ab254370abb44fcaa6b7ce27293d955f82a3a8b8f4b0b45f21a6424aa44892aa3fa4b68205fe8e4f5daa1dfca2a52b65146c022ab646d8f9eae31550e3f
7
- data.tar.gz: 87081d43640cc58b2c18bb9401bc51830af3a3b1416f02a72ca76a4de6296079155db4390f97a269b4f68cf287d5d3ceb61563cf7c711a97239c4c63248bd969
6
+ metadata.gz: 04f40264d833ecfd68f76600b950c814a2c6b4f9e18e07833e5ed14b3226c6e23c155a442dfe08c7cdd33d32e2940c24e039305c7d214e0b603b9dce68a36dc9
7
+ data.tar.gz: 8a183d19433fae5718292935d0c57140424aefb15a5e4bf6ec1cd34ad7a9b10a92aae6f955a1a0fb795d73fe2b1713b57f0997aec26f50e9e1b46fcb56487eb2
@@ -1,5 +1,8 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
5
+
3
6
  Lint/NestedMethodDefinition:
4
7
  Exclude:
5
8
  - 'lib/generators/docker/stack/service.rb'
@@ -13,10 +13,12 @@ Style/Documentation:
13
13
  - 'lib/docker/stack.rb'
14
14
  - 'lib/docker/stack/container.rb'
15
15
  - 'lib/docker/stack/controller.rb'
16
+ - 'lib/docker/stack/localstack/endpoint_stub.rb'
16
17
  - 'lib/generators/docker/stack/util.rb'
17
18
  - 'lib/generators/docker/stack/service.rb'
18
19
  - 'lib/generators/docker/stack/install_generator.rb'
19
20
  - 'lib/generators/docker/stack/service/fedora_generator.rb'
21
+ - 'lib/generators/docker/stack/service/localstack_generator.rb'
20
22
  - 'lib/generators/docker/stack/service/postgres_generator.rb'
21
23
  - 'lib/generators/docker/stack/service/redis_generator.rb'
22
24
  - 'lib/generators/docker/stack/service/solr_generator.rb'
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'engine_cart/rake_task'
3
5
  require 'rspec/core/rake_task'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'docker/stack'
@@ -0,0 +1,15 @@
1
+ fedora:
2
+ development: 8984
3
+ test: 8986
4
+ localstack:
5
+ development: 0
6
+ test: 200
7
+ postgres:
8
+ development: 5433
9
+ test: 5434
10
+ redis:
11
+ development: 6380
12
+ test: 6381
13
+ solr:
14
+ development: 8983
15
+ test: 8985
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'docker/stack/version'
@@ -1,8 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'docker/stack/container'
2
4
  require 'docker/stack/controller'
3
5
  require 'docker/stack/version'
4
6
 
5
7
  module Docker
6
8
  module Stack
9
+ def self.port_for(service, environment = Rails.env)
10
+ port_map[service.to_s][environment.to_s]
11
+ end
12
+
13
+ def self.port_map
14
+ return @port_map unless @port_map.nil?
15
+ config_file = [
16
+ Rails.root&.join('config', 'stack.yml'),
17
+ File.expand_path('../../config/stack.yml', __dir__)
18
+ ].find { |f| File.exist?(f.to_s) }
19
+ @port_map = YAML.safe_load(File.read(config_file))
20
+ end
7
21
  end
8
22
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'action_view'
2
4
 
3
5
  module Docker
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'docker/compose'
2
4
  require 'docker-api'
3
5
 
@@ -23,13 +25,11 @@ module Docker
23
25
  down(cleanup: true)
24
26
  images = config['services'].values.map { |conf| conf['image'] }
25
27
  images.each do |image_name|
26
- begin
27
- image = ::Docker::Image.get(image_name)
28
- result = image.remove(prune: true)
29
- yield result if block_given?
30
- rescue ::Docker::Error::NotFoundError
31
- yield %{[{"Skipped":"#{image_name} (image not present)"}]}
32
- end
28
+ image = ::Docker::Image.get(image_name)
29
+ result = image.remove(prune: true)
30
+ yield result if block_given?
31
+ rescue ::Docker::Error::NotFoundError
32
+ yield %{[{"Skipped":"#{image_name} (image not present)"}]}
33
33
  end
34
34
  ::Docker::Image.prune
35
35
  end
@@ -37,12 +37,10 @@ module Docker
37
37
  def status
38
38
  containers = dc.ps.map(&:id)
39
39
  containers.map do |c|
40
- begin
41
- container = Container.new(c)
42
- container.to_h
43
- rescue StandardError
44
- { id: c, service: 'unknown', status: 'unknown', started: 'unknown', running: 'unknown' }
45
- end
40
+ container = Container.new(c)
41
+ container.to_h
42
+ rescue StandardError
43
+ { id: c, service: 'unknown', status: 'unknown', started: 'unknown', running: 'unknown' }
46
44
  end
47
45
  end
48
46
 
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-sdk'
4
+
5
+ module Docker
6
+ module Stack
7
+ module Localstack
8
+ module EndpointStub
9
+ class Plugin < Seahorse::Client::Plugin
10
+ PORT_MAP = {
11
+ 'Aws::APIGateway' => 4567,
12
+ 'Aws::CloudFormation' => 4581,
13
+ 'Aws::CloudWatch' => 4582,
14
+ 'Aws::DynamoDB' => 4569,
15
+ 'Aws::DynamoDBStreams' => 4570,
16
+ 'Aws::Elasticsearch' => 4571,
17
+ 'Aws::ElasticsearchService' => 4578,
18
+ 'Aws::Firehose' => 4573,
19
+ 'Aws::Kinesis' => 4568,
20
+ 'Aws::Lambda' => 4574,
21
+ 'Aws::Redshift' => 4577,
22
+ 'Aws::Route53' => 4580,
23
+ 'Aws::S3' => 4572,
24
+ 'Aws::SES' => 4579,
25
+ 'Aws::SNS' => 4575,
26
+ 'Aws::SQS' => 4576,
27
+ 'Aws::SSM' => 4583
28
+ }.freeze
29
+
30
+ def after_initialize(client)
31
+ client.config.endpoint = endpoint_for(client) || client.config.endpoint
32
+ end
33
+
34
+ private
35
+
36
+ def endpoint_for(client)
37
+ base_port = PORT_MAP[client.class.parent_name]
38
+ return nil if base_port.nil?
39
+ base_url = 'http://localhost'
40
+ offset = Docker::Stack.port_for(:localstack)
41
+ base_uri = URI.parse(base_url)
42
+ base_uri.port = base_port + offset
43
+ base_uri.to_s
44
+ end
45
+ end
46
+
47
+ def self.stub_endpoints!
48
+ Aws.config.update(
49
+ region: 'us-east-1',
50
+ credentials: Aws::Credentials.new('localstack-key', 'localstack-secret')
51
+ )
52
+ Seahorse::Client::Base.add_plugin(Plugin)
53
+ Aws::S3::Plugins::BucketDns.options.find { |opt| opt.name == :force_path_style }.default = true
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'docker/stack'
2
4
 
3
5
  # rubocop:disable all
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Docker
2
4
  module Stack
3
- VERSION = '0.1.1'.freeze
5
+ VERSION = '0.2.1'
4
6
  end
5
7
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'generators/docker/stack/util'
2
4
  require 'active_support/core_ext/hash/keys'
3
5
 
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'docker/stack'
1
4
  require 'generators/docker/stack/util'
2
5
  require 'active_support/core_ext/hash/deep_merge'
3
6
  require 'ostruct'
@@ -32,16 +35,12 @@ module Docker
32
35
 
33
36
  def service_from_template(service)
34
37
  source = File.expand_path(find_in_source_paths("services/#{service}.yml.erb"))
35
- context = OpenStruct.new(env: @env, port_offset: port_offset).instance_eval { binding }
38
+ context = OpenStruct.new(env: @env, port: Docker::Stack.port_for(service)).instance_eval { binding }
36
39
  yaml = Thor::Actions::CapturableERB.new(::File.binread(source), nil, '-', '@output_buffer').tap do |erb|
37
40
  erb.filename = source
38
41
  end.result(context)
39
42
  YAML.safe_load(yaml)
40
43
  end
41
-
42
- def port_offset
43
- { 'development' => 0, 'test' => 2 }[@env] || 0
44
- end
45
44
  end
46
45
  end
47
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'generators/docker/stack/service'
2
4
 
3
5
  module Docker
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'generators/docker/stack/service'
4
+
5
+ module Docker
6
+ module Stack
7
+ module Service
8
+ class LocalstackGenerator < Rails::Generators::Base
9
+ include Docker::Stack::Service
10
+
11
+ desc %(This generator makes the following changes to your application:
12
+ 1. Adds a localstack service configuration to the docker-compose.yml files.
13
+ 2. Creates a config/initializers/localstack_stub.rb file pointing to the new service.
14
+ )
15
+
16
+ def install_service
17
+ copy_file 'config/initializers/localstack_stub.rb', 'config/initializers/localstack_stub.rb'
18
+ gem 'aws-sdk', '~> 3.0'
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'generators/docker/stack/service'
2
4
 
3
5
  module Docker
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'generators/docker/stack/service'
2
4
 
3
5
  module Docker
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'generators/docker/stack/service'
2
4
 
3
5
  module Docker
@@ -1,6 +1,7 @@
1
1
  default: &default
2
2
  adapter: postgresql
3
3
  host: localhost
4
+ port: <%= Docker::Stack.port_for(:postgres) %>
4
5
  encoding: unicode
5
6
  pool: 5
6
7
  username: docker
@@ -8,12 +9,10 @@ default: &default
8
9
 
9
10
  development:
10
11
  <<: *default
11
- port: 5433
12
12
  database: docker_dev
13
13
 
14
14
  test:
15
15
  <<: *default
16
- port: <%= Rails.env.development? ? 5433 : 5435 %>
17
16
  database: docker_test
18
17
 
19
18
  production:
@@ -1,12 +1,12 @@
1
1
  development:
2
2
  user: fedoraAdmin
3
3
  password: fedoraAdmin
4
- url: http://127.0.0.1:<%= ENV['FCREPO_DEVELOPMENT_PORT'] || 8984 %>/rest
4
+ url: http://127.0.0.1:<%= ENV['FCREPO_DEVELOPMENT_PORT'] || Docker::Stack::port_for(:fedora) %>/rest
5
5
  base_path: /dev
6
6
  test:
7
7
  user: fedoraAdmin
8
8
  password: fedoraAdmin
9
- url: http://127.0.0.1:<%= ENV['FCREPO_TEST_PORT'] || 8986 %>/rest
9
+ url: http://127.0.0.1:<%= ENV['FCREPO_TEST_PORT'] || Docker::Stack::port_for(:fedora) %>/rest
10
10
  base_path: /test
11
11
  production:
12
12
  user: fedoraAdmin
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'docker/stack/localstack/endpoint_stub'
4
+
5
+ Docker::Stack::Localstack::EndpointStub.stub_endpoints!
@@ -1,9 +1,9 @@
1
1
  development:
2
2
  host: localhost
3
- port: 6380
3
+ port: Docker::Stack.port_for(:redis)
4
4
  test:
5
5
  host: localhost
6
- port: 6381
6
+ port: Docker::Stack.port_for(:redis)
7
7
  production:
8
8
  host: <%= ENV['REDIS_HOST'] || 'localhost' %>
9
9
  port: <%= ENV['REDIS_PORT'] || 6379 %>
@@ -1,7 +1,7 @@
1
1
  # This is a sample config file that points to a solr server for each environment
2
2
  development:
3
- url: http://127.0.0.1:<%= ENV['SOLR_TEST_PORT'] || 8983 %>/solr/development-core
3
+ url: http://127.0.0.1:<%= ENV['SOLR_TEST_PORT'] || Docker::Stack.port_for(:solr) %>/solr/development-core
4
4
  test:
5
- url: http://127.0.0.1:<%= ENV['SOLR_TEST_PORT'] || 8985 %>/solr/test-core
5
+ url: http://127.0.0.1:<%= ENV['SOLR_TEST_PORT'] || Docker::Stack.port_for(:solr) %>/solr/test-core
6
6
  production:
7
7
  url: http://127.0.0.1:8983/solr/donut
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'docker/stack/rake_task'
2
4
 
3
5
  def get_named_task(task_name)
@@ -19,7 +21,7 @@ namespace :docker do
19
21
  task = get_named_task(ENV['SPEC_TASK']) ||
20
22
  get_named_task('spec') ||
21
23
  get_named_task('rspec')
22
- task.invoke unless task.nil?
24
+ task&.invoke
23
25
  end
24
26
  end
25
27
  end
@@ -6,4 +6,4 @@ services:
6
6
  volumes:
7
7
  - fedora:/data
8
8
  ports:
9
- - "<%= 8984 + port_offset %>:8080"
9
+ - "<%= port %>:8080"
@@ -0,0 +1,17 @@
1
+ volumes:
2
+ localstack:
3
+ services:
4
+ localstack:
5
+ image: localstack/localstack
6
+ ports:
7
+ - "<%= 4772 + port %>:4572"
8
+ volumes:
9
+ - localstack:/data
10
+ environment:
11
+ SERVICES: s3
12
+ DATA_DIR: /data
13
+ healthcheck:
14
+ test: ["CMD", "curl", "-f", "http://localhost:4572/"]
15
+ interval: 30s
16
+ timeout: 5s
17
+ retries: 3
@@ -10,4 +10,4 @@ services:
10
10
  - POSTGRES_USER=docker
11
11
  - POSTGRES_PASSWORD=d0ck3r
12
12
  ports:
13
- - "<%= 5433 + port_offset %>:5432"
13
+ - "<%= port %>:5432"
@@ -2,7 +2,7 @@ services:
2
2
  redis:
3
3
  image: redis:alpine
4
4
  ports:
5
- - "<%= 6380 + port_offset %>:6379"
5
+ - "<%= port %>:6379"
6
6
  healthcheck:
7
7
  test: ["CMD", "redis-cli", "ping"]
8
8
  interval: 30s
@@ -4,7 +4,7 @@ services:
4
4
  solr:
5
5
  image: solr:7.2-alpine
6
6
  ports:
7
- - "<%= 8983 + port_offset %>:8983"
7
+ - "<%= port %>:8983"
8
8
  volumes:
9
9
  - solr:/opt/solr/server/solr/mycores
10
10
  - ../../solr:/solr_config
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Docker
2
4
  module Stack
3
5
  module Util
4
- COMPOSE_FILE_VERSION = '3.4'.freeze
6
+ COMPOSE_FILE_VERSION = '3.4'
5
7
 
6
8
  def self.included(base)
7
9
  base.source_root File.expand_path('templates', __dir__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klein
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-21 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api
@@ -210,24 +210,29 @@ files:
210
210
  - Rakefile
211
211
  - bin/console
212
212
  - bin/setup
213
+ - config/stack.yml
213
214
  - docker-stack.gemspec
214
215
  - lib/docker/stack.rb
215
216
  - lib/docker/stack/container.rb
216
217
  - lib/docker/stack/controller.rb
218
+ - lib/docker/stack/localstack/endpoint_stub.rb
217
219
  - lib/docker/stack/rake_task.rb
218
220
  - lib/docker/stack/version.rb
219
221
  - lib/generators/docker/stack/install_generator.rb
220
222
  - lib/generators/docker/stack/service.rb
221
223
  - lib/generators/docker/stack/service/fedora_generator.rb
224
+ - lib/generators/docker/stack/service/localstack_generator.rb
222
225
  - lib/generators/docker/stack/service/postgres_generator.rb
223
226
  - lib/generators/docker/stack/service/redis_generator.rb
224
227
  - lib/generators/docker/stack/service/solr_generator.rb
225
228
  - lib/generators/docker/stack/templates/config/database.yml
226
229
  - lib/generators/docker/stack/templates/config/fedora.yml
230
+ - lib/generators/docker/stack/templates/config/initializers/localstack_stub.rb
227
231
  - lib/generators/docker/stack/templates/config/redis.yml
228
232
  - lib/generators/docker/stack/templates/config/solr.yml
229
233
  - lib/generators/docker/stack/templates/docker.rake
230
234
  - lib/generators/docker/stack/templates/services/fedora.yml.erb
235
+ - lib/generators/docker/stack/templates/services/localstack.yml.erb
231
236
  - lib/generators/docker/stack/templates/services/postgres.yml.erb
232
237
  - lib/generators/docker/stack/templates/services/redis.yml.erb
233
238
  - lib/generators/docker/stack/templates/services/solr.yml.erb