nib-integrate 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nib/integrate/config_file.rb +1 -1
- data/lib/nib/integrate/integration_file.rb +27 -66
- data/lib/nib/integrate/integration_file_config.rb +121 -0
- data/lib/nib/integrate/integrator.rb +26 -7
- data/lib/nib/integrate/version.rb +1 -1
- data/lib/nib_integrate_plugin.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1386d7ff19edc5f38506ff83e7fcfbaa96ed25bd7b1a5b30e920d6b4f727cda
|
4
|
+
data.tar.gz: 306428b15ebf5d930b8a2b40ba7ac53d9d2155a9aa7864bff58fe882766475aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e267c1ab97254e3f9e906379c8a3ebdcc76b7e3492828a2a9742a6cf6421ca4adb49b725c5a54418fd946c2c12b7aed2bda1642ac571c0a2765b6f6df1539b3
|
7
|
+
data.tar.gz: dc2dade4cbbd84d37a60c3d5bfb46a1e9b30716cecf2b66f9b08eaa58fa7e5c0a216b7731739c51743cb65841ad71b559736222354622da5f25aea1fd07b1c1d
|
@@ -6,7 +6,7 @@ module Nib
|
|
6
6
|
# reads and writes the config file
|
7
7
|
class ConfigFile
|
8
8
|
PATH = "#{ENV['HOME']}/.nib-integrate-config".freeze
|
9
|
-
DEFAULT_CONFIG = { 'apps' => [] }.freeze
|
9
|
+
DEFAULT_CONFIG = { 'apps' => [], 'initial_port' => 10_000 }.freeze
|
10
10
|
class << self
|
11
11
|
def write(config, path = PATH)
|
12
12
|
# this will write the config file.
|
@@ -1,93 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nib
|
2
4
|
module Integrate
|
3
5
|
# dynamically generated network config file
|
4
6
|
class IntegrationFile
|
5
7
|
class << self
|
6
|
-
def write(app_name)
|
7
|
-
new(app_name).write
|
8
|
+
def write(app_name, port = 10_000)
|
9
|
+
new(app_name, port).write
|
8
10
|
end
|
9
|
-
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
def initialize(app_name)
|
14
|
-
@app_name = app_name
|
15
|
-
end
|
16
|
-
|
17
|
-
def write
|
18
|
-
File.open(path, 'w') do |f|
|
19
|
-
f.write(config.to_yaml)
|
12
|
+
def write_empty_config(app_name, port = 10_000)
|
13
|
+
new(app_name, port).write_empty_config
|
20
14
|
end
|
21
|
-
path
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def apps
|
27
|
-
@apps ||= global_config['apps']
|
28
|
-
end
|
29
|
-
|
30
|
-
def app
|
31
|
-
apps.find { |a| a['name'] == app_name }
|
32
15
|
end
|
33
16
|
|
34
|
-
|
35
|
-
apps.reject { |a| a['name'] == app_name }
|
36
|
-
end
|
17
|
+
attr_reader :app_name, :current_port
|
37
18
|
|
38
|
-
def
|
39
|
-
|
19
|
+
def initialize(app_name, port = 10_000)
|
20
|
+
@current_port = port
|
21
|
+
@app_name = app_name
|
40
22
|
end
|
41
23
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
}
|
24
|
+
def write
|
25
|
+
config.tap do |cfg|
|
26
|
+
File.open(cfg.path, 'w') do |f|
|
27
|
+
f.write(cfg.config.to_yaml)
|
28
|
+
end
|
48
29
|
end
|
49
30
|
end
|
50
31
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
lambda do |registration|
|
57
|
-
"#{container_name(registration)}_1:#{container_name(registration)}"
|
32
|
+
def write_empty_config
|
33
|
+
empty_config.tap do |cfg|
|
34
|
+
File.open(cfg.path, 'w') do |f|
|
35
|
+
f.write(cfg.config.to_yaml)
|
36
|
+
end
|
58
37
|
end
|
59
38
|
end
|
60
39
|
|
61
|
-
|
62
|
-
project_name = registration['path'].split('/').last.gsub(/[ _]/, '')
|
63
|
-
service_name = registration['service']
|
64
|
-
"#{project_name}_#{service_name}"
|
65
|
-
end
|
66
|
-
|
67
|
-
def network_config
|
68
|
-
{
|
69
|
-
'version' => '2',
|
70
|
-
'services' => {},
|
71
|
-
'networks' => {
|
72
|
-
'nib' => { 'external' => { 'name' => 'nib-integrate-network' } }
|
73
|
-
}
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
|
-
def app_docker_compose
|
78
|
-
@app_docker_compose ||= app_compose_contents
|
79
|
-
end
|
40
|
+
private
|
80
41
|
|
81
|
-
def
|
82
|
-
|
42
|
+
def config
|
43
|
+
integration_file_config.config
|
83
44
|
end
|
84
45
|
|
85
|
-
def
|
86
|
-
|
46
|
+
def empty_config
|
47
|
+
integration_file_config.empty_config
|
87
48
|
end
|
88
49
|
|
89
|
-
def
|
90
|
-
|
50
|
+
def integration_file_config
|
51
|
+
IntegrationFileConfig.new(app_name, current_port)
|
91
52
|
end
|
92
53
|
end
|
93
54
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nib
|
4
|
+
module Integrate
|
5
|
+
# IntegrationFileConfig creates a proper configuration yaml string
|
6
|
+
# and keeps track of port assignments
|
7
|
+
class IntegrationFileConfig
|
8
|
+
attr_reader :app_name, :current_port
|
9
|
+
def initialize(app_name, current_port)
|
10
|
+
@app_name = app_name
|
11
|
+
@current_port = current_port
|
12
|
+
end
|
13
|
+
|
14
|
+
def config
|
15
|
+
OpenStruct.new(
|
16
|
+
config: config_hash,
|
17
|
+
path: path,
|
18
|
+
port: current_port
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def empty_config
|
23
|
+
OpenStruct.new(
|
24
|
+
config: { 'version' => app_compose_contents['version'] },
|
25
|
+
path: empty_path
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def config_hash
|
32
|
+
app_services.each_with_object(merged_config) do |elem, acc|
|
33
|
+
service_definition = {
|
34
|
+
'external_links' => external_links,
|
35
|
+
'networks' => %w[default nib]
|
36
|
+
}
|
37
|
+
service_definition['ports'] = ports(elem) if ports(elem)
|
38
|
+
|
39
|
+
acc['services'][elem].merge!(service_definition)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def apps
|
44
|
+
@apps ||= global_config['apps']
|
45
|
+
end
|
46
|
+
|
47
|
+
def app
|
48
|
+
apps.find { |a| a['name'] == app_name }
|
49
|
+
end
|
50
|
+
|
51
|
+
def other_apps
|
52
|
+
apps.reject { |a| a['name'] == app_name }
|
53
|
+
end
|
54
|
+
|
55
|
+
def path
|
56
|
+
"#{app['path']}/.nib-integrate-network-config"
|
57
|
+
end
|
58
|
+
|
59
|
+
def empty_path
|
60
|
+
"#{app['path']}/.nib-integrate-empty-config-file"
|
61
|
+
end
|
62
|
+
|
63
|
+
def merged_config
|
64
|
+
app_compose_contents.merge(network_config)
|
65
|
+
end
|
66
|
+
|
67
|
+
def ports(service_definition)
|
68
|
+
ports = app_docker_compose['services'][service_definition]['ports']
|
69
|
+
return unless ports && !ports.empty?
|
70
|
+
ports.map do |port|
|
71
|
+
existing_ports = port.split(':')
|
72
|
+
[next_port, existing_ports[1]].join(':')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def next_port
|
77
|
+
@current_port += 1
|
78
|
+
end
|
79
|
+
|
80
|
+
def external_links
|
81
|
+
other_apps.map(&external_link)
|
82
|
+
end
|
83
|
+
|
84
|
+
def external_link
|
85
|
+
lambda do |registration|
|
86
|
+
"#{container_name(registration)}_1:#{container_name(registration)}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def container_name(registration)
|
91
|
+
project_name = registration['path'].split('/').last.gsub(/[ _]/, '')
|
92
|
+
service_name = registration['service']
|
93
|
+
"#{project_name}_#{service_name}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def network_config
|
97
|
+
{
|
98
|
+
'networks' => {
|
99
|
+
'nib' => { 'external' => { 'name' => 'nib-integrate-network' } }
|
100
|
+
}
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def app_docker_compose
|
105
|
+
@app_docker_compose ||= app_compose_contents
|
106
|
+
end
|
107
|
+
|
108
|
+
def app_compose_contents
|
109
|
+
YAML.load_file("#{app['path']}/#{app['compose_file']}")
|
110
|
+
end
|
111
|
+
|
112
|
+
def app_services
|
113
|
+
app_docker_compose['services'].keys
|
114
|
+
end
|
115
|
+
|
116
|
+
def global_config
|
117
|
+
ConfigFile.read
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -12,16 +12,18 @@ module Nib
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
attr_reader :args, :current_arg, :config_path
|
15
|
+
attr_reader :args, :current_arg, :config_path, :current_port
|
16
16
|
|
17
17
|
def initialize(args, config_path)
|
18
18
|
@args = args
|
19
19
|
@config_path = config_path
|
20
|
+
@current_port = initial_port
|
20
21
|
end
|
21
22
|
|
22
23
|
def up
|
23
24
|
args.map do |arg|
|
24
25
|
@current_arg = arg
|
26
|
+
@current_port = current_integration_object.port + 1
|
25
27
|
command
|
26
28
|
end
|
27
29
|
end
|
@@ -40,11 +42,20 @@ module Nib
|
|
40
42
|
end
|
41
43
|
|
42
44
|
def apps
|
43
|
-
@apps ||=
|
45
|
+
@apps ||= config['apps']
|
46
|
+
end
|
47
|
+
|
48
|
+
def initial_port
|
49
|
+
@initial_port ||= config['initial_port']
|
44
50
|
end
|
45
51
|
|
46
52
|
def command
|
47
|
-
|
53
|
+
integration_file.write_empty_config(app['name'])
|
54
|
+
[
|
55
|
+
cd_command,
|
56
|
+
docker_compose_command,
|
57
|
+
clean_files_command
|
58
|
+
].join(' && ')
|
48
59
|
end
|
49
60
|
|
50
61
|
def down_command
|
@@ -62,8 +73,12 @@ module Nib
|
|
62
73
|
[run_command, integration_file_flag, up_command].compact.join(' ')
|
63
74
|
end
|
64
75
|
|
76
|
+
def clean_files_command
|
77
|
+
'rm .nib-integrate*'
|
78
|
+
end
|
79
|
+
|
65
80
|
def run_command
|
66
|
-
|
81
|
+
'docker-compose -f .nib-integrate-empty-config-file'
|
67
82
|
end
|
68
83
|
|
69
84
|
def up_command
|
@@ -71,11 +86,15 @@ module Nib
|
|
71
86
|
end
|
72
87
|
|
73
88
|
def integration_file_flag
|
74
|
-
"-f #{
|
89
|
+
"-f #{current_integration_object.path}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def current_integration_object
|
93
|
+
integration_file.write(app['name'], current_port)
|
75
94
|
end
|
76
95
|
|
77
|
-
def
|
78
|
-
|
96
|
+
def config
|
97
|
+
@config ||= config_file.read(config_path)
|
79
98
|
end
|
80
99
|
|
81
100
|
def config_file
|
data/lib/nib_integrate_plugin.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nib-integrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Helm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nib
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- bin/nib-integrate
|
92
92
|
- lib/nib/integrate/config_file.rb
|
93
93
|
- lib/nib/integrate/integration_file.rb
|
94
|
+
- lib/nib/integrate/integration_file_config.rb
|
94
95
|
- lib/nib/integrate/integrator.rb
|
95
96
|
- lib/nib/integrate/lister.rb
|
96
97
|
- lib/nib/integrate/network_creator.rb
|