kontena-cli 0.14.1 → 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/kontena/cli/apps/common.rb +2 -4
- data/lib/kontena/cli/apps/docker_compose_generator.rb +27 -15
- data/lib/kontena/cli/apps/init_command.rb +16 -16
- data/lib/kontena/cli/apps/kontena_yml_generator.rb +19 -8
- data/lib/kontena/cli/registry/create_command.rb +3 -1
- data/lib/kontena/cli/vpn/create_command.rb +21 -14
- data/spec/fixtures/app.json +42 -0
- data/spec/kontena/cli/app/init_command_spec.rb +110 -0
- data/spec/kontena/cli/vpn/create_command_spec.rb +116 -0
- data/spec/spec_helper.rb +1 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f71c08239bc2780793aa394f980332a5b497d8c0
|
4
|
+
data.tar.gz: 932ba40653c1709ad494e21d8eb863a0269307f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6169ec0c9621c1c3ab5ed29bffa0e1714e37bfccb80e1ba19d2093a7cbd1c166ffe870b635418163ea285be928593ccab0eccec430bbf187d5a29780b109685
|
7
|
+
data.tar.gz: 9d1affd436e49874e937671d8bdfc11c1547916c2cb0444a9adeb4c6097b65c5ed141f1667a6f6a7ad463f552ef6e8da2f5bc53f81eed6e058a94bfae72d5dd8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.14.
|
1
|
+
0.14.2
|
@@ -56,7 +56,7 @@ module Kontena::Cli::Apps
|
|
56
56
|
|
57
57
|
def project_name_from_yaml(file)
|
58
58
|
reader = YAML::Reader.new(file, true)
|
59
|
-
outcome = reader.execute
|
59
|
+
outcome = reader.execute
|
60
60
|
if outcome[:version] == '2'
|
61
61
|
outcome[:name]
|
62
62
|
else
|
@@ -100,10 +100,8 @@ module Kontena::Cli::Apps
|
|
100
100
|
def app_json
|
101
101
|
if !@app_json && File.exist?('app.json')
|
102
102
|
@app_json = JSON.parse(File.read('app.json'))
|
103
|
-
else
|
104
|
-
@app_json = {}
|
105
103
|
end
|
106
|
-
@app_json
|
104
|
+
@app_json ||= {}
|
107
105
|
end
|
108
106
|
|
109
107
|
def display_notifications(messages, color = :yellow)
|
@@ -14,36 +14,48 @@ module Kontena::Cli::Apps
|
|
14
14
|
def generate(procfile, addons, env_file)
|
15
15
|
if procfile.keys.size > 0
|
16
16
|
# generate services found in Procfile
|
17
|
-
docker_compose = {
|
18
|
-
|
19
|
-
|
17
|
+
docker_compose = {
|
18
|
+
'version' => '2'
|
19
|
+
}
|
20
|
+
services = {}
|
21
|
+
procfile.each do |service, command|
|
22
|
+
services[service] = {'build' => '.' }
|
20
23
|
if app_json && service == 'web' # Heroku generates PORT env variable so should we do too
|
21
|
-
|
22
|
-
|
24
|
+
services[service]['environment'] = ['PORT=5000']
|
25
|
+
services[service]['ports'] = ['5000:5000']
|
23
26
|
end
|
24
|
-
|
25
|
-
|
27
|
+
services[service]['command'] = "/start #{service}" if service != 'web'
|
28
|
+
services[service]['env_file'] = env_file if env_file
|
26
29
|
|
27
30
|
# generate addon services
|
28
31
|
addons.each do |addon|
|
29
32
|
addon_service = addon.split(":")[0]
|
30
33
|
addon_service.slice!('heroku-')
|
31
34
|
if valid_addons.has_key?(addon_service)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
services[service]['links'] = [] unless services[service]['links']
|
36
|
+
services[service]['links'] << "#{addon_service}:#{addon_service}"
|
37
|
+
services[service]['environment'] = [] unless services[service]['environment']
|
38
|
+
services[service]['environment'] += valid_addons[addon_service]['environment']
|
39
|
+
services[addon_service] = {'image' => valid_addons[addon_service]['image']}
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
43
|
+
docker_compose['services'] = services
|
40
44
|
else
|
41
45
|
# no Procfile found, create dummy web service
|
42
|
-
docker_compose = {
|
43
|
-
|
46
|
+
docker_compose = {
|
47
|
+
'version' => '2',
|
48
|
+
'services' => {
|
49
|
+
'web' => {
|
50
|
+
'build' => '.'
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
docker_compose['services']['web']['env_file'] = env_file if env_file
|
44
56
|
end
|
45
57
|
# create docker-compose.yml file
|
46
58
|
create_yml(docker_compose, docker_compose_file)
|
47
59
|
end
|
48
60
|
end
|
49
|
-
end
|
61
|
+
end
|
@@ -27,12 +27,12 @@ module Kontena::Cli::Apps
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.exist?('Procfile')
|
30
|
-
procfile = YAML.load(File.read('Procfile'))
|
30
|
+
procfile = ::YAML.load(File.read('Procfile'))
|
31
31
|
else
|
32
32
|
procfile = {}
|
33
33
|
end
|
34
34
|
|
35
|
-
app_env = create_env_file(app_json)
|
35
|
+
app_env = create_env_file(app_json['env']) if app_json['env']
|
36
36
|
addons = app_json['addons'] || []
|
37
37
|
|
38
38
|
if File.exist?(docker_compose_file)
|
@@ -62,26 +62,26 @@ module Kontena::Cli::Apps
|
|
62
62
|
|
63
63
|
protected
|
64
64
|
|
65
|
+
def service_prefix
|
66
|
+
@service_prefix ||= project_name || current_dir
|
67
|
+
end
|
68
|
+
|
65
69
|
def create_dockerfile?
|
66
70
|
['', 'y', 'yes'].include? ask('Dockerfile not found. Do you want to create it? [Yn]: ').downcase
|
67
71
|
end
|
68
72
|
|
69
|
-
def create_env_file(
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
else
|
77
|
-
value = env['value']
|
78
|
-
end
|
79
|
-
app_env.puts "#{key}=#{value}"
|
73
|
+
def create_env_file(env)
|
74
|
+
app_env = File.new('.env', 'w')
|
75
|
+
app_json['env'].each do |key, env|
|
76
|
+
if env['generator'] == 'secret'
|
77
|
+
value = SecureRandom.hex(64)
|
78
|
+
else
|
79
|
+
value = env['value']
|
80
80
|
end
|
81
|
-
app_env.
|
82
|
-
return '.env'
|
81
|
+
app_env.puts "#{key}=#{value}"
|
83
82
|
end
|
84
|
-
|
83
|
+
app_env.close
|
84
|
+
'.env'
|
85
85
|
end
|
86
86
|
|
87
87
|
def create_docker_compose_yml?
|
@@ -16,8 +16,8 @@ module Kontena::Cli::Apps
|
|
16
16
|
services = {}
|
17
17
|
# extend services from docker-compose.yml
|
18
18
|
file = File.read(docker_compose_file)
|
19
|
-
|
20
|
-
|
19
|
+
|
20
|
+
yml_services(file).each do |name, options|
|
21
21
|
services[name] = {'extends' => { 'file' => 'docker-compose.yml', 'service' => name }}
|
22
22
|
if options.has_key?('build')
|
23
23
|
image = image_name || "registry.kontena.local/#{File.basename(Dir.getwd)}:latest"
|
@@ -42,7 +42,15 @@ module Kontena::Cli::Apps
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
create_yml(services, 'kontena.yml')
|
45
|
+
end
|
45
46
|
|
47
|
+
def yml_services(file)
|
48
|
+
yml = ::YAML.load(file)
|
49
|
+
if yml['version'] == '2'
|
50
|
+
yml['services']
|
51
|
+
else
|
52
|
+
yml
|
53
|
+
end
|
46
54
|
end
|
47
55
|
|
48
56
|
def generate(procfile, addons, env_file)
|
@@ -79,17 +87,20 @@ module Kontena::Cli::Apps
|
|
79
87
|
end
|
80
88
|
|
81
89
|
def create_yml(services, filename)
|
82
|
-
if File.exist?(filename)
|
83
|
-
kontena_services =
|
90
|
+
if File.exist?(filename) && !File.zero?(filename)
|
91
|
+
kontena_services = yml_services(File.read(filename))
|
84
92
|
services.each do |name, options|
|
85
93
|
if kontena_services[name]
|
86
94
|
services[name].merge!(kontena_services[name])
|
87
95
|
end
|
88
96
|
end
|
89
97
|
end
|
90
|
-
|
98
|
+
kontena_services = {
|
99
|
+
'version' => '2',
|
100
|
+
'name' => service_prefix,
|
101
|
+
'services' => services
|
102
|
+
}
|
103
|
+
super(kontena_services, filename)
|
91
104
|
end
|
92
|
-
|
93
|
-
|
94
105
|
end
|
95
|
-
end
|
106
|
+
end
|
@@ -12,6 +12,7 @@ module Kontena::Cli::Registry
|
|
12
12
|
option '--s3-region', 'S3_REGION', 'S3 region', default: 'eu-west-1'
|
13
13
|
option '--s3-encrypt', :flag, 'Encrypt S3 objects', default: false
|
14
14
|
option '--s3-secure', :flag, 'Use secure connection in S3', default: true
|
15
|
+
option '--s3-v4auth', :flag, 'Use v4auth on S3', default: false
|
15
16
|
option '--azure-account-name', 'AZURE_ACCOUNT_NAME', 'Azure account name'
|
16
17
|
option '--azure-container-name', 'AZURE_CONTAINER_NAME', 'Azure container name'
|
17
18
|
|
@@ -38,7 +39,8 @@ module Kontena::Cli::Registry
|
|
38
39
|
"REGISTRY_STORAGE_S3_REGION=#{s3_region}",
|
39
40
|
"REGISTRY_STORAGE_S3_BUCKET=#{s3_bucket}",
|
40
41
|
"REGISTRY_STORAGE_S3_ENCRYPT=#{s3_encrypt?}",
|
41
|
-
"REGISTRY_STORAGE_S3_SECURE=#{s3_secure?}"
|
42
|
+
"REGISTRY_STORAGE_S3_SECURE=#{s3_secure?}",
|
43
|
+
"REGISTRY_STORAGE_S3_V4AUTH=#{s3_v4auth?}"
|
42
44
|
]
|
43
45
|
secrets = [
|
44
46
|
{secret: 'REGISTRY_STORAGE_S3_ACCESSKEY', name: 'REGISTRY_STORAGE_S3_ACCESSKEY', type: 'env'},
|
@@ -6,24 +6,17 @@ module Kontena::Cli::Vpn
|
|
6
6
|
include Kontena::Cli::GridOptions
|
7
7
|
|
8
8
|
option '--node', 'NODE', 'Node name where VPN is deployed'
|
9
|
-
option '--ip', 'IP', 'Node ip-address'
|
9
|
+
option '--ip', 'IP', 'Node ip-address to use in VPN service configuration'
|
10
10
|
|
11
11
|
def execute
|
12
12
|
require_api_url
|
13
13
|
token = require_token
|
14
14
|
preferred_node = node
|
15
|
-
|
15
|
+
|
16
16
|
vpn = client(token).get("services/#{current_grid}/vpn") rescue nil
|
17
17
|
abort('Vpn already exists') if vpn
|
18
18
|
|
19
|
-
|
20
|
-
if preferred_node.nil?
|
21
|
-
node = nodes['nodes'].find{|n| n['connected']}
|
22
|
-
abort('Cannot find any online nodes') if node.nil?
|
23
|
-
else
|
24
|
-
node = nodes['nodes'].find{|n| n['connected'] && n['name'] == preferred_node }
|
25
|
-
abort('Node not found') if node.nil?
|
26
|
-
end
|
19
|
+
node = find_node(token, preferred_node)
|
27
20
|
|
28
21
|
vpn_ip = node_vpn_ip(node)
|
29
22
|
data = {
|
@@ -50,16 +43,30 @@ module Kontena::Cli::Vpn
|
|
50
43
|
puts "Use 'kontena vpn config' to fetch OpenVPN client config to your machine (it takes a while until config is ready)."
|
51
44
|
end
|
52
45
|
|
46
|
+
|
47
|
+
def find_node(token, preferred_node = nil)
|
48
|
+
nodes = client(token).get("grids/#{current_grid}/nodes")
|
49
|
+
|
50
|
+
if preferred_node.nil?
|
51
|
+
node = nodes['nodes'].find{|n| n['connected'] && !n['public_ip'].to_s.empty?}
|
52
|
+
abort('Cannot find any online nodes with public ip. If you want to connect with private address, please use --node and/or --ip options.') if node.nil?
|
53
|
+
else
|
54
|
+
node = nodes['nodes'].find{|n| n['connected'] && n['name'] == preferred_node }
|
55
|
+
abort('Node not found') if node.nil?
|
56
|
+
end
|
57
|
+
node
|
58
|
+
end
|
59
|
+
|
53
60
|
# @param [Hash] node
|
54
61
|
# @return [String]
|
55
62
|
def node_vpn_ip(node)
|
56
63
|
return ip unless ip.nil?
|
57
|
-
|
64
|
+
|
58
65
|
# vagrant
|
59
|
-
if
|
60
|
-
node['private_ip']
|
66
|
+
if node['labels'] && node['labels'].include?('provider=vagrant')
|
67
|
+
node['private_ip'].to_s
|
61
68
|
else
|
62
|
-
node['public_ip']
|
69
|
+
node['public_ip'].to_s.empty? ? node['private_ip'].to_s : node['public_ip'].to_s
|
63
70
|
end
|
64
71
|
end
|
65
72
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
{
|
2
|
+
"name": "Small Sharp Tool",
|
3
|
+
"description": "This app does one little thing, and does it well.",
|
4
|
+
"keywords": [
|
5
|
+
"productivity",
|
6
|
+
"HTML5",
|
7
|
+
"scalpel"
|
8
|
+
],
|
9
|
+
"website": "https://small-sharp-tool.com/",
|
10
|
+
"repository": "https://github.com/jane-doe/small-sharp-tool",
|
11
|
+
"logo": "https://small-sharp-tool.com/logo.svg",
|
12
|
+
"success_url": "/welcome",
|
13
|
+
"scripts": {
|
14
|
+
"postdeploy": "bundle exec rake bootstrap"
|
15
|
+
},
|
16
|
+
"env": {
|
17
|
+
"SECRET_TOKEN": {
|
18
|
+
"description": "A secret key for verifying the integrity of signed cookies.",
|
19
|
+
"generator": "secret"
|
20
|
+
},
|
21
|
+
"WEB_CONCURRENCY": {
|
22
|
+
"description": "The number of processes to run.",
|
23
|
+
"value": "5"
|
24
|
+
}
|
25
|
+
},
|
26
|
+
"formation": {
|
27
|
+
"web": {
|
28
|
+
"quantity": 2,
|
29
|
+
"size": "Performance-M"
|
30
|
+
}
|
31
|
+
},
|
32
|
+
"image": "heroku/ruby",
|
33
|
+
"addons": [
|
34
|
+
"openredis",
|
35
|
+
"mongolab:shared-single-small"
|
36
|
+
],
|
37
|
+
"buildpacks": [
|
38
|
+
{
|
39
|
+
"url": "https://github.com/stomita/heroku-buildpack-phantomjs"
|
40
|
+
}
|
41
|
+
]
|
42
|
+
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require_relative "../../../spec_helper"
|
2
|
+
require 'kontena/cli/apps/init_command'
|
3
|
+
|
4
|
+
describe Kontena::Cli::Apps::InitCommand do
|
5
|
+
include FixturesHelpers
|
6
|
+
|
7
|
+
let(:subject) do
|
8
|
+
described_class.new(File.basename($0))
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:app_json) do
|
12
|
+
fixture('app.json')
|
13
|
+
end
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
allow(File).to receive(:exist?).and_return false
|
17
|
+
allow(subject).to receive(:create_yml).and_return nil
|
18
|
+
allow(subject).to receive(:create_dockerfile?).and_return false
|
19
|
+
allow(subject).to receive(:create_env_file).and_return nil
|
20
|
+
allow(subject).to receive(:create_docker_compose_yml?).and_return false
|
21
|
+
allow(Kontena::Cli::Apps::KontenaYmlGenerator).to receive(:new).and_return spy
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#execute' do
|
25
|
+
it 'detects Dockerfile' do
|
26
|
+
expect(File).to receive(:exist?).with('Dockerfile').once.and_return true
|
27
|
+
subject.run([])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'reads Procfile' do
|
31
|
+
allow(File).to receive(:exist?).with('Procfile').once.and_return true
|
32
|
+
expect(File).to receive(:read).with('Procfile').once.and_return 'web: bundle exec rails s'
|
33
|
+
subject.run([])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'reads app.json file' do
|
37
|
+
allow(File).to receive(:exist?).with('app.json').once.and_return true
|
38
|
+
expect(File).to receive(:read).with('app.json').once.and_return '{}'
|
39
|
+
subject.run([])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'asks creation of docker-compose.yml' do
|
43
|
+
expect(subject).to receive(:create_docker_compose_yml?).and_return false
|
44
|
+
subject.run([])
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'creates docker-compose.yml if accepted' do
|
48
|
+
allow(subject).to receive(:create_docker_compose_yml?).and_return true
|
49
|
+
generator = spy
|
50
|
+
generator_klass = Kontena::Cli::Apps::DockerComposeGenerator
|
51
|
+
expect(generator_klass).to receive(:new).with('docker-compose.yml').and_return(generator)
|
52
|
+
expect(generator).to receive(:generate).with({}, [], nil)
|
53
|
+
subject.run([])
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'passes Procfile services to docker-compose.yml creation' do
|
57
|
+
allow(File).to receive(:exist?).with('Procfile').once.and_return true
|
58
|
+
allow(File).to receive(:read).with('Procfile').once.and_return 'web: bundle exec rails s'
|
59
|
+
allow(subject).to receive(:create_docker_compose_yml?).and_return true
|
60
|
+
generator = spy
|
61
|
+
generator_klass = Kontena::Cli::Apps::DockerComposeGenerator
|
62
|
+
expect(generator_klass).to receive(:new).with('docker-compose.yml').and_return(generator)
|
63
|
+
expect(generator).to receive(:generate).with({ 'web' => 'bundle exec rails s' }, [], nil)
|
64
|
+
subject.run([])
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'passes app.json options to docker-compose.yml creation' do
|
68
|
+
expect(File).to receive(:exist?).with('app.json').and_return true
|
69
|
+
expect(File).to receive(:read).with('app.json').and_return app_json
|
70
|
+
allow(subject).to receive(:create_docker_compose_yml?).and_return true
|
71
|
+
generator = spy
|
72
|
+
generator_klass = Kontena::Cli::Apps::DockerComposeGenerator
|
73
|
+
expect(generator_klass).to receive(:new).with('docker-compose.yml').and_return(generator)
|
74
|
+
expect(generator).to receive(:generate).with({}, ["openredis","mongolab:shared-single-small"], nil)
|
75
|
+
subject.run([])
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'creates .env file' do
|
79
|
+
allow(File).to receive(:exist?).with('app.json').and_return true
|
80
|
+
allow(File).to receive(:read).with('app.json').and_return app_json
|
81
|
+
allow(subject).to receive(:create_docker_compose_yml?).and_return true
|
82
|
+
generator = spy
|
83
|
+
generator_klass = Kontena::Cli::Apps::DockerComposeGenerator
|
84
|
+
allow(generator_klass).to receive(:new).with('docker-compose.yml').and_return(generator)
|
85
|
+
app_env = JSON.parse(app_json)['env']
|
86
|
+
expect(subject).to receive(:create_env_file).with(app_env).and_return nil
|
87
|
+
subject.run([])
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'creates kontena.yml from docker-compose.yml' do
|
91
|
+
allow(File).to receive(:exist?).with('docker-compose.yml').and_return true
|
92
|
+
generator = spy
|
93
|
+
generator_klass = Kontena::Cli::Apps::KontenaYmlGenerator
|
94
|
+
expect(generator_klass).to receive(:new).with(nil, 'cli').and_return(generator)
|
95
|
+
expect(generator).to receive(:generate_from_compose_file).with('docker-compose.yml')
|
96
|
+
subject.run([])
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when docker-compose.yml not created' do
|
100
|
+
it 'creates dummy kontena.yml' do
|
101
|
+
allow(File).to receive(:exist?).with('docker-compose.yml').and_return false
|
102
|
+
generator = spy
|
103
|
+
generator_klass = Kontena::Cli::Apps::KontenaYmlGenerator
|
104
|
+
expect(generator_klass).to receive(:new).with(nil, 'cli').and_return(generator)
|
105
|
+
expect(generator).to receive(:generate).with({}, [], nil)
|
106
|
+
subject.run([])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require_relative "../../../spec_helper"
|
2
|
+
require "kontena/cli/vpn/create_command"
|
3
|
+
|
4
|
+
describe Kontena::Cli::Vpn::CreateCommand do
|
5
|
+
|
6
|
+
include ClientHelpers
|
7
|
+
|
8
|
+
let(:subject) { described_class.new(File.basename($0)) }
|
9
|
+
|
10
|
+
describe '#execute' do
|
11
|
+
it 'should abort if vpn already exists' do
|
12
|
+
expect(client).to receive(:get).with("services/test-grid/vpn").and_return({vpn: true})
|
13
|
+
|
14
|
+
expect {
|
15
|
+
subject.execute
|
16
|
+
}.to raise_error SystemExit
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#find_node' do
|
23
|
+
|
24
|
+
it 'should abort if no online nodes exists' do
|
25
|
+
expect(client).to receive(:get).with("grids/test-grid/nodes").and_return(
|
26
|
+
{
|
27
|
+
'nodes' => [
|
28
|
+
{'connected' => false},
|
29
|
+
{'connected' => false, 'public_ip' => '1.2.3.4'}
|
30
|
+
]
|
31
|
+
})
|
32
|
+
|
33
|
+
expect {
|
34
|
+
subject.find_node(token, nil)
|
35
|
+
}.to raise_error SystemExit
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should return first online node with public ip' do
|
39
|
+
expect(client).to receive(:get).with("grids/test-grid/nodes").and_return(
|
40
|
+
{
|
41
|
+
'nodes' => [
|
42
|
+
{'connected' => true},
|
43
|
+
{'connected' => true, 'public_ip' => '1.2.3.4'}
|
44
|
+
]
|
45
|
+
})
|
46
|
+
|
47
|
+
node = subject.find_node(token, nil)
|
48
|
+
expect(node['public_ip']).to eq('1.2.3.4')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should return preferred node' do
|
52
|
+
expect(client).to receive(:get).with("grids/test-grid/nodes").and_return(
|
53
|
+
{
|
54
|
+
'nodes' => [
|
55
|
+
{'connected' => true},
|
56
|
+
{'name' => 'preferred', 'connected' => true, 'public_ip' => '1.2.3.4'}
|
57
|
+
]
|
58
|
+
})
|
59
|
+
|
60
|
+
node = subject.find_node(token, 'preferred')
|
61
|
+
expect(node['name']).to eq('preferred')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should abort if no online nodes exists' do
|
65
|
+
expect(client).to receive(:get).with("grids/test-grid/nodes").and_return(
|
66
|
+
{
|
67
|
+
'nodes' => [
|
68
|
+
{'connected' => true},
|
69
|
+
{'name' => 'preferred', 'connected' => true, 'public_ip' => '1.2.3.4'}
|
70
|
+
]
|
71
|
+
})
|
72
|
+
|
73
|
+
expect {
|
74
|
+
subject.find_node(token, 'foobar')
|
75
|
+
}.to raise_error SystemExit
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#node_vpn_ip' do
|
81
|
+
|
82
|
+
it 'return ip when set' do
|
83
|
+
allow(subject).to receive(:ip).and_return('1.2.3.4')
|
84
|
+
|
85
|
+
expect(subject.node_vpn_ip(nil)).to eq('1.2.3.4')
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'return public ip when set on node' do
|
89
|
+
allow(subject).to receive(:ip).and_return(nil)
|
90
|
+
node = {
|
91
|
+
'public_ip' => '8.8.8.8',
|
92
|
+
'private_ip' => '10.1.1.2'
|
93
|
+
}
|
94
|
+
expect(subject.node_vpn_ip(node)).to eq('8.8.8.8')
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'return private ip when public not set on node' do
|
98
|
+
allow(subject).to receive(:ip).and_return(nil)
|
99
|
+
node = {
|
100
|
+
'private_ip' => '10.1.1.2'
|
101
|
+
}
|
102
|
+
expect(subject.node_vpn_ip(node)).to eq('10.1.1.2')
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'return private on vagrant nodes' do
|
106
|
+
allow(subject).to receive(:ip).and_return(nil)
|
107
|
+
node = {
|
108
|
+
'public_ip' => '8.8.8.8',
|
109
|
+
'private_ip' => '10.1.1.2',
|
110
|
+
'labels' => ['provider=vagrant']
|
111
|
+
}
|
112
|
+
expect(subject.node_vpn_ip(node)).to eq('10.1.1.2')
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kontena-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kontena, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -402,6 +402,7 @@ files:
|
|
402
402
|
- lib/kontena/machine/vagrant/node_provisioner.rb
|
403
403
|
- lib/kontena/scripts/completer
|
404
404
|
- lib/kontena/scripts/init
|
405
|
+
- spec/fixtures/app.json
|
405
406
|
- spec/fixtures/docker-compose.yml
|
406
407
|
- spec/fixtures/docker-compose_v2.yml
|
407
408
|
- spec/fixtures/kontena-invalid.yml
|
@@ -416,6 +417,7 @@ files:
|
|
416
417
|
- spec/kontena/cli/app/config_command_spec.rb
|
417
418
|
- spec/kontena/cli/app/deploy_command_spec.rb
|
418
419
|
- spec/kontena/cli/app/docker_helper_spec.rb
|
420
|
+
- spec/kontena/cli/app/init_command_spec.rb
|
419
421
|
- spec/kontena/cli/app/scale_spec.rb
|
420
422
|
- spec/kontena/cli/app/service_generator_spec.rb
|
421
423
|
- spec/kontena/cli/app/service_generator_v2_spec.rb
|
@@ -444,6 +446,7 @@ files:
|
|
444
446
|
- spec/kontena/cli/services/unlink_command_spec.rb
|
445
447
|
- spec/kontena/cli/services/update_command_spec.rb
|
446
448
|
- spec/kontena/cli/version_command_spec.rb
|
449
|
+
- spec/kontena/cli/vpn/create_command_spec.rb
|
447
450
|
- spec/spec_helper.rb
|
448
451
|
- spec/support/client_helpers.rb
|
449
452
|
- spec/support/fixtures_helpers.rb
|
@@ -473,6 +476,7 @@ signing_key:
|
|
473
476
|
specification_version: 4
|
474
477
|
summary: Kontena command line tool
|
475
478
|
test_files:
|
479
|
+
- spec/fixtures/app.json
|
476
480
|
- spec/fixtures/docker-compose.yml
|
477
481
|
- spec/fixtures/docker-compose_v2.yml
|
478
482
|
- spec/fixtures/kontena-invalid.yml
|
@@ -487,6 +491,7 @@ test_files:
|
|
487
491
|
- spec/kontena/cli/app/config_command_spec.rb
|
488
492
|
- spec/kontena/cli/app/deploy_command_spec.rb
|
489
493
|
- spec/kontena/cli/app/docker_helper_spec.rb
|
494
|
+
- spec/kontena/cli/app/init_command_spec.rb
|
490
495
|
- spec/kontena/cli/app/scale_spec.rb
|
491
496
|
- spec/kontena/cli/app/service_generator_spec.rb
|
492
497
|
- spec/kontena/cli/app/service_generator_v2_spec.rb
|
@@ -515,6 +520,7 @@ test_files:
|
|
515
520
|
- spec/kontena/cli/services/unlink_command_spec.rb
|
516
521
|
- spec/kontena/cli/services/update_command_spec.rb
|
517
522
|
- spec/kontena/cli/version_command_spec.rb
|
523
|
+
- spec/kontena/cli/vpn/create_command_spec.rb
|
518
524
|
- spec/spec_helper.rb
|
519
525
|
- spec/support/client_helpers.rb
|
520
526
|
- spec/support/fixtures_helpers.rb
|