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.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +2 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/config/stack.yml +15 -0
- data/docker-stack.gemspec +2 -0
- data/lib/docker/stack.rb +14 -0
- data/lib/docker/stack/container.rb +2 -0
- data/lib/docker/stack/controller.rb +11 -13
- data/lib/docker/stack/localstack/endpoint_stub.rb +58 -0
- data/lib/docker/stack/rake_task.rb +2 -0
- data/lib/docker/stack/version.rb +3 -1
- data/lib/generators/docker/stack/install_generator.rb +2 -0
- data/lib/generators/docker/stack/service.rb +4 -5
- data/lib/generators/docker/stack/service/fedora_generator.rb +2 -0
- data/lib/generators/docker/stack/service/localstack_generator.rb +23 -0
- data/lib/generators/docker/stack/service/postgres_generator.rb +2 -0
- data/lib/generators/docker/stack/service/redis_generator.rb +2 -0
- data/lib/generators/docker/stack/service/solr_generator.rb +2 -0
- data/lib/generators/docker/stack/templates/config/database.yml +1 -2
- data/lib/generators/docker/stack/templates/config/fedora.yml +2 -2
- data/lib/generators/docker/stack/templates/config/initializers/localstack_stub.rb +5 -0
- data/lib/generators/docker/stack/templates/config/redis.yml +2 -2
- data/lib/generators/docker/stack/templates/config/solr.yml +2 -2
- data/lib/generators/docker/stack/templates/docker.rake +3 -1
- data/lib/generators/docker/stack/templates/services/fedora.yml.erb +1 -1
- data/lib/generators/docker/stack/templates/services/localstack.yml.erb +17 -0
- data/lib/generators/docker/stack/templates/services/postgres.yml.erb +1 -1
- data/lib/generators/docker/stack/templates/services/redis.yml.erb +1 -1
- data/lib/generators/docker/stack/templates/services/solr.yml.erb +1 -1
- data/lib/generators/docker/stack/util.rb +3 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 459b321cbce7417b7e02f01e338162fabf1a1d9109757feff3d6675821ab17d4
|
4
|
+
data.tar.gz: 15e5832ed64387b472f60e5514171c64d7349daec651423feab004de11287c57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04f40264d833ecfd68f76600b950c814a2c6b4f9e18e07833e5ed14b3226c6e23c155a442dfe08c7cdd33d32e2940c24e039305c7d214e0b603b9dce68a36dc9
|
7
|
+
data.tar.gz: 8a183d19433fae5718292935d0c57140424aefb15a5e4bf6ec1cd34ad7a9b10a92aae6f955a1a0fb795d73fe2b1713b57f0997aec26f50e9e1b46fcb56487eb2
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -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
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/config/stack.yml
ADDED
data/docker-stack.gemspec
CHANGED
data/lib/docker/stack.rb
CHANGED
@@ -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 '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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
data/lib/docker/stack/version.rb
CHANGED
@@ -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,
|
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
|
@@ -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,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'] ||
|
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'] ||
|
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
|
@@ -1,9 +1,9 @@
|
|
1
1
|
development:
|
2
2
|
host: localhost
|
3
|
-
port:
|
3
|
+
port: Docker::Stack.port_for(:redis)
|
4
4
|
test:
|
5
5
|
host: localhost
|
6
|
-
port:
|
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'] ||
|
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'] ||
|
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
|
24
|
+
task&.invoke
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -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
|
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.
|
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-
|
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
|