minke 1.6.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/docker/Dockerfile +4 -0
- data/docker/Gemfile +9 -0
- data/lib/minke.rb +1 -0
- data/lib/minke/docker/docker_compose.rb +20 -22
- data/lib/minke/docker/docker_runner.rb +10 -0
- data/lib/minke/docker/service_discovery.rb +37 -13
- data/lib/minke/rake/app.rake +5 -3
- data/lib/minke/tasks/task.rb +11 -7
- data/lib/minke/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmRhZmY1MDljOWIyNjkxOWU0Y2NhYTg5MTdmZjI5ZGFjNDdjYWM5Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODVkMWRmODEzYWZhZmYwY2FlODFiMTY2MTIzYzNmMjI4OTI5M2M1ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzBiNmE2YjA3ZDRhMjY1NjYzM2M4MzJkYmI4NjZlZTNjZDBlODZlMTNiMTEw
|
10
|
+
ZTQyNmMxYmJjNzhiODFkNzhmZTBmNTBlMjQwNjQyNGMwYzNlNDJhNDM5ODE2
|
11
|
+
ZmYzMDZhYTM0NzBhMGQ4NmU0NGE0NDIxZjg2OWJlMDg1OTE5ZGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2UyMWYwMzNiYzI2NzFhMjQ5ZjVjYTgxNzFjNWI1Y2E4ZTE0MDMwMTFkNzQw
|
14
|
+
ZjZlYmM1ZjU0MTU2NzcwYThkZmFlYjA4MjI0YzJjOTM4NjJkYWE0NzFiZTc1
|
15
|
+
MGVjYmM2OGE3MTY1MjVkMWY5MmY1ZjhkNmViMTQyZmFkNzVlZTI=
|
data/docker/Dockerfile
ADDED
data/docker/Gemfile
ADDED
data/lib/minke.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
module Minke
|
2
2
|
module Docker
|
3
3
|
class DockerComposeFactory
|
4
|
-
def initialize system_runner
|
4
|
+
def initialize system_runner, project_name
|
5
|
+
@project_name = project_name
|
5
6
|
@system_runner = system_runner
|
6
7
|
end
|
7
8
|
|
8
9
|
def create compose_file
|
9
|
-
Minke::Docker::DockerCompose.new compose_file, @system_runner
|
10
|
+
Minke::Docker::DockerCompose.new compose_file, @system_runner, @project_name
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
class DockerCompose
|
14
15
|
@compose_file = nil
|
15
16
|
|
16
|
-
def initialize compose_file, system_runner
|
17
|
+
def initialize compose_file, system_runner, project_name
|
18
|
+
@project_name = project_name
|
17
19
|
@compose_file = compose_file
|
18
20
|
@system_runner = system_runner
|
19
21
|
end
|
@@ -21,41 +23,26 @@ module Minke
|
|
21
23
|
##
|
22
24
|
# start the containers in a stack defined by the docker compose file
|
23
25
|
def up
|
24
|
-
|
25
|
-
directory = create_compose_network_file
|
26
|
-
|
27
|
-
@system_runner.execute "docker-compose -f #{@compose_file} -f #{directory + '/docker-compose.yml'} up -d"
|
28
|
-
@system_runner.remove_entry_secure directory
|
29
|
-
else
|
30
|
-
@system_runner.execute "docker-compose -f #{@compose_file} up -d"
|
31
|
-
end
|
32
|
-
|
26
|
+
execute_command "up -d"
|
33
27
|
sleep 2
|
34
28
|
end
|
35
29
|
|
36
30
|
##
|
37
31
|
# stop the containers in a stack and removes them as defined by the docker compose file
|
38
32
|
def down
|
39
|
-
|
40
|
-
directory = create_compose_network_file
|
41
|
-
|
42
|
-
@system_runner.execute "docker-compose -f #{@compose_file} -f #{directory + '/docker-compose.yml'} down"
|
43
|
-
@system_runner.remove_entry_secure directory
|
44
|
-
else
|
45
|
-
@system_runner.execute "docker-compose -f #{@compose_file} down -v"
|
46
|
-
end
|
33
|
+
execute_command "down -v"
|
47
34
|
end
|
48
35
|
|
49
36
|
##
|
50
37
|
# remove the containers started in a stack defined by the docker compose file
|
51
38
|
def rm
|
52
|
-
|
39
|
+
execute_command 'rm -v' unless ::Docker.info["Driver"] == "btrfs"
|
53
40
|
end
|
54
41
|
|
55
42
|
##
|
56
43
|
# stream the logs for the current running stack
|
57
44
|
def logs
|
58
|
-
|
45
|
+
execute_command 'logs -f'
|
59
46
|
end
|
60
47
|
|
61
48
|
##
|
@@ -64,6 +51,17 @@ module Minke
|
|
64
51
|
@system_runner.execute_and_return "docker-compose -f #{@compose_file} port #{container} #{private_port}"
|
65
52
|
end
|
66
53
|
|
54
|
+
def execute_command command
|
55
|
+
unless ENV['DOCKER_NETWORK'].to_s.empty?
|
56
|
+
directory = create_compose_network_file
|
57
|
+
|
58
|
+
@system_runner.execute "docker-compose -f #{@compose_file} -f #{directory + '/docker-compose.yml'} -p #{@project_name} #{command}"
|
59
|
+
@system_runner.remove_entry_secure directory
|
60
|
+
else
|
61
|
+
@system_runner.execute "docker-compose -f #{@compose_file} -p #{@project_name} #{command}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
67
65
|
def create_compose_network_file
|
68
66
|
content = { 'version' => '2'.to_s, 'networks' => {'default' => { 'external' => { 'name' => ENV['DOCKER_NETWORK'] } } } }
|
69
67
|
|
@@ -42,6 +42,16 @@ module Minke
|
|
42
42
|
::Docker::Image.create('fromImage' => image_name)
|
43
43
|
end
|
44
44
|
|
45
|
+
##
|
46
|
+
# running_images returns a list of running containers
|
47
|
+
# Returns
|
48
|
+
#
|
49
|
+
# Array of Docker::Image
|
50
|
+
def running_containers
|
51
|
+
containers = ::Docker::Container.all(all: true, filters: { status: ["running"] }.to_json)
|
52
|
+
return containers
|
53
|
+
end
|
54
|
+
|
45
55
|
##
|
46
56
|
# create_and_run_container starts a conatainer of the given image name and executes a command
|
47
57
|
#
|
@@ -3,30 +3,54 @@ module Minke
|
|
3
3
|
##
|
4
4
|
# ServiceDiscovery allows you to look up the publicly accessible address and port for a server
|
5
5
|
class ServiceDiscovery
|
6
|
-
def initialize
|
7
|
-
|
8
|
-
@
|
6
|
+
def initialize project_name, docker_runner
|
7
|
+
@project_name = project_name
|
8
|
+
@docker_runner = docker_runner
|
9
9
|
end
|
10
10
|
|
11
11
|
##
|
12
12
|
# Will attempt to locate the public details for a running container given
|
13
13
|
# its name and private port
|
14
14
|
# Parameters:
|
15
|
-
# -
|
15
|
+
# - service_name: the name of the running service
|
16
16
|
# - private_port: the private port which you wish to retrieve an address for
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
# Returns:
|
18
|
+
# public address for the container e.g. 0.0.0.0:8080
|
19
|
+
def public_address_for service_name, private_port
|
20
|
+
begin
|
21
|
+
ip = @docker_runner.get_docker_ip_address
|
22
|
+
container_details = find_container_by_name "/#{@project_name}_#{service_name}_1"
|
23
|
+
ports = container_details.first.info['Ports'].select { |p| p['PrivatePort'] == private_port }.first
|
24
|
+
rescue
|
25
|
+
raise "Unable to find public address for '#{service_name}' on port #{private_port}"
|
26
|
+
end
|
21
27
|
|
22
|
-
|
28
|
+
return "#{ip}:#{ports['PublicPort']}"
|
29
|
+
end
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
##
|
32
|
+
# Will attempt to locate the private details for a running container given
|
33
|
+
# its name and private port
|
34
|
+
# Parameters:
|
35
|
+
# - service_name: the name of the running service
|
36
|
+
# - private_port: the private port which you wish to retrieve an address for
|
37
|
+
# Returns:
|
38
|
+
# private address for the container e.g. 172.17.0.2:8080
|
39
|
+
def bridge_address_for service_name, private_port
|
40
|
+
begin
|
41
|
+
puts "/#{@project_name}_#{service_name}_1"
|
42
|
+
container_details = find_container_by_name "/#{@project_name}_#{service_name}_1"
|
43
|
+
ip = container_details.first.info['NetworkSettings']['Networks']['bridge']['IPAddress']
|
44
|
+
rescue
|
45
|
+
raise "Unable to find bridge address for '#{service_name}' on port #{private_port}"
|
27
46
|
end
|
47
|
+
return "#{ip}:#{private_port}"
|
48
|
+
end
|
28
49
|
|
29
|
-
|
50
|
+
:private
|
51
|
+
def find_container_by_name name
|
52
|
+
containers = @docker_runner.running_containers
|
53
|
+
containers.select { |c| c.info['Names'].include?(name) }
|
30
54
|
end
|
31
55
|
end
|
32
56
|
end
|
data/lib/minke/rake/app.rake
CHANGED
@@ -46,7 +46,7 @@ namespace :app do
|
|
46
46
|
create_dependencies
|
47
47
|
|
48
48
|
if @config.run != nil
|
49
|
-
runner = Minke::Tasks::Run.new @config, :run, @generator_config, @docker_runner, @docker_compose_factory, @logger, @helper
|
49
|
+
runner = Minke::Tasks::Run.new @config, :run, @generator_config, @docker_runner, @docker_compose_factory, @service_discovery, @logger, @helper
|
50
50
|
runner.run
|
51
51
|
end
|
52
52
|
end
|
@@ -59,7 +59,7 @@ namespace :app do
|
|
59
59
|
create_dependencies
|
60
60
|
|
61
61
|
if @config.cucumber != nil
|
62
|
-
runner = Minke::Tasks::Cucumber.new @config, :cucumber, @generator_config, @docker_runner, @docker_compose_factory, @logger, @helper
|
62
|
+
runner = Minke::Tasks::Cucumber.new @config, :cucumber, @generator_config, @docker_runner, @docker_compose_factory, @service_discovery, @logger, @helper
|
63
63
|
runner.run
|
64
64
|
end
|
65
65
|
end
|
@@ -72,9 +72,11 @@ namespace :app do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def create_dependencies
|
75
|
+
@project_name = "minke#{SecureRandom.urlsafe_base64(12)}".downcase
|
75
76
|
@system_runner = Minke::Docker::SystemRunner.new
|
76
|
-
@docker_compose_factory ||= Minke::Docker::DockerComposeFactory.new @system_runner
|
77
|
+
@docker_compose_factory ||= Minke::Docker::DockerComposeFactory.new @system_runner, @project_name
|
77
78
|
@docker_runner ||= Minke::Docker::DockerRunner.new
|
79
|
+
@service_discovery ||= Minke::Docker::ServiceDiscovery.new @project_name, @docker_runner
|
78
80
|
|
79
81
|
if @config == nil
|
80
82
|
reader = Minke::Config::Reader.new
|
data/lib/minke/tasks/task.rb
CHANGED
@@ -4,11 +4,12 @@ module Minke
|
|
4
4
|
# Task is a base implementation of a rake task such as fetch, build, etc
|
5
5
|
class Task
|
6
6
|
|
7
|
-
def initialize config, task, generator_settings, docker_runner, docker_compose_factory, logger, helper
|
7
|
+
def initialize config, task, generator_settings, docker_runner, docker_compose_factory, service_discovery, logger, helper
|
8
8
|
@config = config
|
9
9
|
@task = task
|
10
10
|
@generator_settings = generator_settings
|
11
11
|
@docker_runner = docker_runner
|
12
|
+
@service_discovery = service_discovery
|
12
13
|
@logger = logger
|
13
14
|
@helper = helper
|
14
15
|
@task_settings = config.send(task)
|
@@ -84,18 +85,21 @@ module Minke
|
|
84
85
|
end
|
85
86
|
|
86
87
|
def build_address url
|
87
|
-
if url.type == '
|
88
|
+
if url.type == 'external'
|
88
89
|
"#{url.protocol}://#{url.address}:#{url.port}#{url.path}"
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
elsif url.type == 'bridge'
|
91
|
+
address = @service_discovery.bridge_address_for url.address, url.port
|
92
|
+
"#{url.protocol}://#{address}#{url.path}"
|
93
|
+
elsif url.type == 'public'
|
94
|
+
address = @service_discovery.public_address_for url.address, url.port
|
92
95
|
|
96
|
+
# if running on docker for mac we need to replace the ip address with the docker hosts
|
93
97
|
ip = @docker_runner.get_docker_ip_address
|
94
98
|
if ip != "127.0.0.1" && ip != "0.0.0.0" && ip != nil
|
95
|
-
|
99
|
+
address.gsub!('0.0.0.0', ip)
|
96
100
|
end
|
97
101
|
|
98
|
-
"#{url.protocol}://#{
|
102
|
+
"#{url.protocol}://#{address}#{url.path}"
|
99
103
|
end
|
100
104
|
end
|
101
105
|
|
data/lib/minke/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nic Jackson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -201,6 +201,8 @@ files:
|
|
201
201
|
- bin/console
|
202
202
|
- bin/minke
|
203
203
|
- bin/setup
|
204
|
+
- docker/Dockerfile
|
205
|
+
- docker/Gemfile
|
204
206
|
- examples/config_go.yml
|
205
207
|
- examples/config_swift.yml
|
206
208
|
- lib/minke.rb
|