kontena-cli 0.7.3 → 0.8.0
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/bin/kontena +64 -2
- data/kontena-cli.gemspec +4 -2
- data/lib/kontena/cli/app_command.rb +20 -0
- data/lib/kontena/cli/apps/common.rb +53 -0
- data/lib/kontena/cli/{stacks/stacks.rb → apps/deploy_command.rb} +17 -31
- data/lib/kontena/cli/apps/init_command.rb +101 -0
- data/lib/kontena/cli/apps/list_command.rb +41 -0
- data/lib/kontena/cli/apps/logs_command.rb +58 -0
- data/lib/kontena/cli/apps/remove_command.rb +64 -0
- data/lib/kontena/cli/apps/start_command.rb +38 -0
- data/lib/kontena/cli/apps/stop_command.rb +38 -0
- data/lib/kontena/cli/container_command.rb +9 -0
- data/lib/kontena/cli/containers/{containers.rb → exec_command.rb} +5 -5
- data/lib/kontena/cli/deploy_command.rb +159 -0
- data/lib/kontena/cli/external_registries/add_command.rb +22 -0
- data/lib/kontena/cli/external_registries/delete_command.rb +13 -0
- data/lib/kontena/cli/external_registries/list_command.rb +16 -0
- data/lib/kontena/cli/external_registry_command.rb +14 -0
- data/lib/kontena/cli/forgot_password_command.rb +13 -0
- data/lib/kontena/cli/grid_command.rb +27 -0
- data/lib/kontena/cli/grids/add_user_command.rb +17 -0
- data/lib/kontena/cli/grids/{audit_log.rb → audit_log_command.rb} +7 -6
- data/lib/kontena/cli/grids/common.rb +24 -0
- data/lib/kontena/cli/grids/create_command.rb +26 -0
- data/lib/kontena/cli/grids/current_command.rb +18 -0
- data/lib/kontena/cli/grids/list_command.rb +26 -0
- data/lib/kontena/cli/grids/list_users_command.rb +18 -0
- data/lib/kontena/cli/grids/remove_command.rb +26 -0
- data/lib/kontena/cli/grids/remove_user_command.rb +16 -0
- data/lib/kontena/cli/grids/show_command.rb +19 -0
- data/lib/kontena/cli/grids/use_command.rb +21 -0
- data/lib/kontena/cli/invite_command.rb +13 -0
- data/lib/kontena/cli/login_command.rb +114 -0
- data/lib/kontena/cli/logout_command.rb +8 -0
- data/lib/kontena/cli/node_command.rb +21 -0
- data/lib/kontena/cli/nodes/digital_ocean/create_command.rb +31 -0
- data/lib/kontena/cli/nodes/digital_ocean/restart_command.rb +26 -0
- data/lib/kontena/cli/nodes/digital_ocean/terminate_command.rb +18 -0
- data/lib/kontena/cli/nodes/digital_ocean_command.rb +15 -0
- data/lib/kontena/cli/nodes/list_command.rb +28 -0
- data/lib/kontena/cli/nodes/remove_command.rb +15 -0
- data/lib/kontena/cli/nodes/show_command.rb +31 -0
- data/lib/kontena/cli/nodes/update_command.rb +18 -0
- data/lib/kontena/cli/nodes/vagrant/create_command.rb +26 -0
- data/lib/kontena/cli/nodes/vagrant/restart_command.rb +25 -0
- data/lib/kontena/cli/nodes/vagrant/ssh_command.rb +20 -0
- data/lib/kontena/cli/nodes/vagrant/start_command.rb +25 -0
- data/lib/kontena/cli/nodes/vagrant/stop_command.rb +25 -0
- data/lib/kontena/cli/nodes/vagrant/terminate_command.rb +16 -0
- data/lib/kontena/cli/nodes/vagrant_command.rb +21 -0
- data/lib/kontena/cli/register_command.rb +21 -0
- data/lib/kontena/cli/{grids/registry.rb → registry/create_command.rb} +32 -35
- data/lib/kontena/cli/registry/delete_command.rb +15 -0
- data/lib/kontena/cli/registry_command.rb +11 -0
- data/lib/kontena/cli/reset_password_command.rb +17 -0
- data/lib/kontena/cli/service_command.rb +33 -0
- data/lib/kontena/cli/services/container_command.rb +9 -0
- data/lib/kontena/cli/services/containers_command.rb +31 -0
- data/lib/kontena/cli/services/create_command.rb +62 -0
- data/lib/kontena/cli/services/delete_command.rb +17 -0
- data/lib/kontena/cli/services/deploy_command.rb +23 -0
- data/lib/kontena/cli/services/list_command.rb +20 -0
- data/lib/kontena/cli/services/logs_command.rb +51 -0
- data/lib/kontena/cli/services/restart_command.rb +16 -0
- data/lib/kontena/cli/services/scale_command.rb +20 -0
- data/lib/kontena/cli/services/services_helper.rb +94 -0
- data/lib/kontena/cli/services/show_command.rb +17 -0
- data/lib/kontena/cli/services/start_command.rb +16 -0
- data/lib/kontena/cli/services/{stats.rb → stats_command.rb} +11 -10
- data/lib/kontena/cli/services/stop_command.rb +16 -0
- data/lib/kontena/cli/services/update_command.rb +51 -0
- data/lib/kontena/cli/verify_account_command.rb +13 -0
- data/lib/kontena/cli/version_command.rb +8 -0
- data/lib/kontena/cli/vpn/config_command.rb +12 -0
- data/lib/kontena/cli/{grids/vpn.rb → vpn/create_command.rb} +12 -29
- data/lib/kontena/cli/vpn/delete_command.rb +15 -0
- data/lib/kontena/cli/vpn_command.rb +13 -0
- data/lib/kontena/cli/whoami_command.rb +19 -0
- data/lib/kontena/client.rb +14 -11
- data/lib/kontena/machine/common.rb +17 -0
- data/lib/kontena/machine/digital_ocean.rb +11 -0
- data/lib/kontena/machine/digital_ocean/cloudinit.yml +66 -0
- data/lib/kontena/machine/digital_ocean/node_destroyer.rb +38 -0
- data/lib/kontena/machine/digital_ocean/node_provisioner.rb +74 -0
- data/lib/kontena/machine/random_name.rb +42 -0
- data/lib/kontena/machine/vagrant.rb +10 -0
- data/lib/kontena/machine/vagrant/Vagrantfile.coreos.rb.erb +32 -0
- data/lib/kontena/machine/vagrant/cloudinit.yml +65 -0
- data/lib/kontena/machine/vagrant/node_destroyer.rb +36 -0
- data/lib/kontena/machine/vagrant/node_provisioner.rb +68 -0
- data/lib/kontena/scripts/completer +5 -5
- data/spec/kontena/cli/app/deploy_command_spec.rb +227 -0
- data/spec/kontena/cli/deploy_command_spec.rb +213 -0
- data/spec/kontena/cli/login_command_spec.rb +22 -0
- data/spec/kontena/cli/register_command_spec.rb +57 -0
- data/spec/spec_helper.rb +5 -1
- metadata +132 -36
- data/lib/kontena/cli/commands.rb +0 -20
- data/lib/kontena/cli/containers/commands.rb +0 -12
- data/lib/kontena/cli/grids/commands.rb +0 -169
- data/lib/kontena/cli/grids/external_registries.rb +0 -40
- data/lib/kontena/cli/grids/grids.rb +0 -108
- data/lib/kontena/cli/grids/users.rb +0 -32
- data/lib/kontena/cli/nodes/commands.rb +0 -27
- data/lib/kontena/cli/nodes/nodes.rb +0 -64
- data/lib/kontena/cli/server/commands.rb +0 -69
- data/lib/kontena/cli/server/server.rb +0 -45
- data/lib/kontena/cli/server/user.rb +0 -174
- data/lib/kontena/cli/services/commands.rb +0 -138
- data/lib/kontena/cli/services/containers.rb +0 -24
- data/lib/kontena/cli/services/logs.rb +0 -44
- data/lib/kontena/cli/services/services.rb +0 -175
- data/lib/kontena/cli/stacks/commands.rb +0 -13
- data/spec/kontena/cli/server/user_spec.rb +0 -59
- data/spec/kontena/cli/stacks/stacks_spec.rb +0 -212
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'kontena/client'
|
2
|
-
require_relative '../common'
|
3
|
-
|
4
|
-
module Kontena::Cli::Services
|
5
|
-
class Logs
|
6
|
-
include Kontena::Cli::Common
|
7
|
-
|
8
|
-
##
|
9
|
-
# @param [String] service_id
|
10
|
-
def show(service_id, options)
|
11
|
-
require_api_url
|
12
|
-
token = require_token
|
13
|
-
last_id = nil
|
14
|
-
loop do
|
15
|
-
query_params = last_id.nil? ? '' : "from=#{last_id}"
|
16
|
-
result = client(token).get("services/#{current_grid}/#{service_id}/container_logs?#{query_params}")
|
17
|
-
result['logs'].each do |log|
|
18
|
-
color = color_for_container(log['name'])
|
19
|
-
puts "#{log['name'][0..12].colorize(color)} | #{log['data']}"
|
20
|
-
last_id = log['id']
|
21
|
-
end
|
22
|
-
break unless options.follow
|
23
|
-
sleep(2)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def color_for_container(container_id)
|
28
|
-
color_maps[container_id] = colors.shift unless color_maps[container_id]
|
29
|
-
color_maps[container_id].to_sym
|
30
|
-
end
|
31
|
-
|
32
|
-
def color_maps
|
33
|
-
@color_maps ||= {}
|
34
|
-
end
|
35
|
-
|
36
|
-
def colors
|
37
|
-
if(@colors.nil? || @colors.size == 0)
|
38
|
-
@colors = [:green, :yellow, :magenta, :cyan, :red,
|
39
|
-
:light_green, :light_yellow, :ligh_magenta, :light_cyan, :light_red]
|
40
|
-
end
|
41
|
-
@colors
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,175 +0,0 @@
|
|
1
|
-
require 'kontena/client'
|
2
|
-
require_relative '../common'
|
3
|
-
require_relative 'services_helper'
|
4
|
-
|
5
|
-
module Kontena::Cli::Services
|
6
|
-
class Services
|
7
|
-
include Kontena::Cli::Common
|
8
|
-
include Kontena::Cli::Services::ServicesHelper
|
9
|
-
|
10
|
-
def list
|
11
|
-
require_api_url
|
12
|
-
token = require_token
|
13
|
-
|
14
|
-
grids = client(token).get("grids/#{current_grid}/services")
|
15
|
-
puts "%-30.30s %-40.40s %-10s %-8s" % ['NAME', 'IMAGE', 'INSTANCES', 'STATEFUL']
|
16
|
-
grids['services'].each do |service|
|
17
|
-
state = service['stateful'] ? 'yes' : 'no'
|
18
|
-
puts "%-30.30s %-40.40s %-10.10s %-8s" % [service['name'], service['image'], service['container_count'], state]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def show(service_id)
|
23
|
-
require_api_url
|
24
|
-
token = require_token
|
25
|
-
|
26
|
-
service = get_service(token, service_id)
|
27
|
-
puts "#{service['id']}:"
|
28
|
-
puts " status: #{service['state'] }"
|
29
|
-
puts " stateful: #{service['stateful'] == true ? 'yes' : 'no' }"
|
30
|
-
puts " scaling: #{service['container_count'] }"
|
31
|
-
puts " image: #{service['image']}"
|
32
|
-
if service['cmd']
|
33
|
-
puts " cmd: #{service['cmd'].join(' ')}"
|
34
|
-
else
|
35
|
-
puts " cmd: -"
|
36
|
-
end
|
37
|
-
|
38
|
-
puts " env: "
|
39
|
-
if service['env']
|
40
|
-
service['env'].each{|e| puts " - #{e}"}
|
41
|
-
end
|
42
|
-
puts " ports:"
|
43
|
-
service['ports'].each do |p|
|
44
|
-
puts " - #{p['node_port']}:#{p['container_port']}/#{p['protocol']}"
|
45
|
-
end
|
46
|
-
puts " links: "
|
47
|
-
if service['links']
|
48
|
-
service['links'].each do |l|
|
49
|
-
puts " - #{l['alias']}"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
puts " containers:"
|
53
|
-
result = client(token).get("services/#{parse_service_id(service_id)}/containers")
|
54
|
-
result['containers'].each do |container|
|
55
|
-
puts " #{container['name']}:"
|
56
|
-
puts " rev: #{container['deploy_rev']}"
|
57
|
-
puts " node: #{container['node']['name']}"
|
58
|
-
puts " dns: #{container['name']}.kontena.local"
|
59
|
-
puts " ip: #{container['network_settings']['ip_address']}"
|
60
|
-
puts " public ip: #{container['node']['public_ip']}"
|
61
|
-
if container['status'] == 'unknown'
|
62
|
-
puts " status: #{container['status'].colorize(:yellow)}"
|
63
|
-
else
|
64
|
-
puts " status: #{container['status']}"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def scale(service_id, count, options)
|
70
|
-
client(require_token).put("services/#{parse_service_id(service_id)}", {container_count: count})
|
71
|
-
self.deploy(service_id, options)
|
72
|
-
end
|
73
|
-
|
74
|
-
def deploy(service_id, options)
|
75
|
-
require_api_url
|
76
|
-
token = require_token
|
77
|
-
data = {}
|
78
|
-
data[:strategy] = options.strategy if options.strategy
|
79
|
-
data[:wait_for_port] = options.wait_for_port if options.wait_for_port
|
80
|
-
deploy_service(token, service_id, data)
|
81
|
-
self.show(service_id)
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
def restart(service_id)
|
86
|
-
require_api_url
|
87
|
-
token = require_token
|
88
|
-
result = client(token).post("services/#{parse_service_id(service_id)}/restart", {})
|
89
|
-
end
|
90
|
-
|
91
|
-
def stop(service_id)
|
92
|
-
require_api_url
|
93
|
-
token = require_token
|
94
|
-
result = client(token).post("services/#{parse_service_id(service_id)}/stop", {})
|
95
|
-
end
|
96
|
-
|
97
|
-
def start(service_id)
|
98
|
-
require_api_url
|
99
|
-
token = require_token
|
100
|
-
|
101
|
-
result = client(token).post("services/#{parse_service_id(service_id)}/start", {})
|
102
|
-
end
|
103
|
-
|
104
|
-
def create(name, image, options)
|
105
|
-
require_api_url
|
106
|
-
token = require_token
|
107
|
-
data = {
|
108
|
-
name: name,
|
109
|
-
image: image,
|
110
|
-
stateful: !!options.stateful
|
111
|
-
}
|
112
|
-
data.merge!(parse_data_from_options(options))
|
113
|
-
create_service(token, current_grid, data)
|
114
|
-
end
|
115
|
-
|
116
|
-
|
117
|
-
def update(service_id, options)
|
118
|
-
require_api_url
|
119
|
-
token = require_token
|
120
|
-
|
121
|
-
data = parse_data_from_options(options)
|
122
|
-
update_service(token, service_id, data)
|
123
|
-
end
|
124
|
-
|
125
|
-
def destroy(service_id)
|
126
|
-
require_api_url
|
127
|
-
token = require_token
|
128
|
-
|
129
|
-
result = client(token).delete("services/#{parse_service_id(service_id)}")
|
130
|
-
end
|
131
|
-
|
132
|
-
private
|
133
|
-
|
134
|
-
##
|
135
|
-
# parse given options to hash
|
136
|
-
# @return [Hash]
|
137
|
-
def parse_data_from_options(options)
|
138
|
-
data = {}
|
139
|
-
data[:ports] = parse_ports(options.ports) if options.ports
|
140
|
-
data[:links] = parse_links(options.link) if options.link
|
141
|
-
data[:volumes] = options.volume if options.volume
|
142
|
-
data[:volumes_from] = options.volumes_from if options.volumes_from
|
143
|
-
data[:memory] = parse_memory(options.memory) if options.memory
|
144
|
-
data[:memory_swap] = parse_memory(options.memory_swap) if options.memory_swap
|
145
|
-
data[:cpu_shares] = options.cpu_shares if options.cpu_shares
|
146
|
-
data[:affinity] = options.affinity if options.affinity
|
147
|
-
data[:env] = parse_env_options(options.env) if options.env
|
148
|
-
data[:container_count] = options.instances if options.instances
|
149
|
-
data[:cmd] = options.cmd.split(" ") if options.cmd
|
150
|
-
data[:user] = options.user if options.user
|
151
|
-
data[:image] = options.image if options.image
|
152
|
-
data[:cap_add] = options.cap_add if options.cap_add
|
153
|
-
data[:cap_drop] = options.cap_drop if options.cap_drop
|
154
|
-
data
|
155
|
-
end
|
156
|
-
|
157
|
-
##
|
158
|
-
# @param [Array<String>] values
|
159
|
-
# @return [Array<String>]
|
160
|
-
def parse_env_options(values)
|
161
|
-
copy = values.dup
|
162
|
-
copy.each_index do |i|
|
163
|
-
key, value = copy[i].split("=", 2)
|
164
|
-
if value.nil?
|
165
|
-
copy[i] = "#{values[i - 1]},#{values[i]}"
|
166
|
-
elsif key != key.upcase
|
167
|
-
copy[i - 1] = "#{values[i - 1]},#{values[i]}"
|
168
|
-
copy.delete_at(i)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
copy
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module Kontena::Cli::Stacks; end;
|
2
|
-
require_relative 'stacks'
|
3
|
-
|
4
|
-
command 'deploy' do |c|
|
5
|
-
c.syntax = 'kontena deploy'
|
6
|
-
c.description = 'Create and deploy multiple services from YAML file'
|
7
|
-
c.option '-f', '--file String', 'path to kontena.yml file, default: current directory'
|
8
|
-
c.option '-p', '--prefix String', 'prefix of service names, default: name of the current directory'
|
9
|
-
c.option '-s', '--service Array', Array, 'Services to deploy'
|
10
|
-
c.action do |args, options|
|
11
|
-
Kontena::Cli::Stacks::Stacks.new.deploy(options)
|
12
|
-
end
|
13
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require_relative "../../../spec_helper"
|
2
|
-
require "kontena/cli/server/user"
|
3
|
-
|
4
|
-
module Kontena::Cli::Server
|
5
|
-
describe User do
|
6
|
-
describe '#register' do
|
7
|
-
|
8
|
-
let(:auth_client) do
|
9
|
-
double(Kontena::Client)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'asks email' do
|
13
|
-
expect(subject).to receive(:ask).once.and_return('john.doe@acme.io')
|
14
|
-
allow(subject).to receive(:password).and_return('secret')
|
15
|
-
allow(Kontena::Client).to receive(:new).and_return(auth_client)
|
16
|
-
allow(auth_client).to receive(:post)
|
17
|
-
subject.register(nil, {})
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'asks password twice' do
|
21
|
-
allow(subject).to receive(:ask).once.and_return('john.doe@acme.io')
|
22
|
-
expect(subject).to receive(:password).twice.and_return('secret')
|
23
|
-
allow(Kontena::Client).to receive(:new).and_return(auth_client)
|
24
|
-
allow(auth_client).to receive(:post)
|
25
|
-
subject.register(nil, {})
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'validates given passwords' do
|
29
|
-
allow(subject).to receive(:ask).once.and_return('john.doe@acme.io')
|
30
|
-
expect(subject).to receive(:password).twice.and_return('secret', 'secret2')
|
31
|
-
expect{subject.register(nil, {})}.to raise_error(ArgumentError)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'uses https://auth.kontena.io as default auth provider' do
|
35
|
-
allow(subject).to receive(:ask).and_return('john.doe@acme.io')
|
36
|
-
allow(subject).to receive(:password).and_return('secret')
|
37
|
-
expect(Kontena::Client).to receive(:new).with('https://auth.kontena.io').and_return(auth_client)
|
38
|
-
allow(auth_client).to receive(:post)
|
39
|
-
subject.register(nil, {})
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'uses given auth provider' do
|
43
|
-
allow(subject).to receive(:ask).and_return('john.doe@acme.io')
|
44
|
-
allow(subject).to receive(:password).and_return('secret')
|
45
|
-
expect(Kontena::Client).to receive(:new).with('http://custom.auth-provider.io').and_return(auth_client)
|
46
|
-
allow(auth_client).to receive(:post)
|
47
|
-
subject.register('http://custom.auth-provider.io', {})
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'sends register request to auth provider' do
|
51
|
-
allow(subject).to receive(:ask).and_return('john.doe@acme.io')
|
52
|
-
allow(subject).to receive(:password).and_return('secret')
|
53
|
-
allow(Kontena::Client).to receive(:new).with('https://auth.kontena.io').and_return(auth_client)
|
54
|
-
expect(auth_client).to receive(:post).with('users', {email: 'john.doe@acme.io', password: 'secret'})
|
55
|
-
subject.register(nil, {})
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,212 +0,0 @@
|
|
1
|
-
require_relative "../../../spec_helper"
|
2
|
-
require "kontena/cli/stacks/stacks"
|
3
|
-
|
4
|
-
module Kontena::Cli::Stacks
|
5
|
-
describe Stacks do
|
6
|
-
let(:settings) do
|
7
|
-
{'server' => {'url' => 'http://kontena.test', 'token' => token}}
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:token) do
|
11
|
-
'1234567'
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:yml) do
|
15
|
-
content = <<content
|
16
|
-
wordpress:
|
17
|
-
image: wordpress:4.1
|
18
|
-
stateful: true
|
19
|
-
ports:
|
20
|
-
- 80:80
|
21
|
-
links:
|
22
|
-
- mysql:mysql
|
23
|
-
environment:
|
24
|
-
- WORDPRESS_DB_PASSWORD=%{prefix}_secret
|
25
|
-
instances: 2
|
26
|
-
deploy:
|
27
|
-
strategy: ha
|
28
|
-
mysql:
|
29
|
-
image: mysql:5.6
|
30
|
-
stateful: true
|
31
|
-
environment:
|
32
|
-
- MYSQL_ROOT_PASSWORD=%{prefix}_secret
|
33
|
-
content
|
34
|
-
content
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:services) do
|
38
|
-
{
|
39
|
-
'wordpress' => {
|
40
|
-
'image' => 'wordpress:latest',
|
41
|
-
'links' => ['mysql:db'],
|
42
|
-
'ports' => ['80:80'],
|
43
|
-
'instances' => 2,
|
44
|
-
'deploy' => {
|
45
|
-
'strategy' => 'ha'
|
46
|
-
}
|
47
|
-
},
|
48
|
-
'mysql' => {
|
49
|
-
'image' => 'mysql:5.6',
|
50
|
-
'stateful' => true
|
51
|
-
}
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
let(:client) do
|
56
|
-
double
|
57
|
-
end
|
58
|
-
|
59
|
-
let(:options) do
|
60
|
-
options = double({prefix: false, file: false, service: nil})
|
61
|
-
end
|
62
|
-
|
63
|
-
let(:env_vars) do
|
64
|
-
["#comment line", "TEST_ENV_VAR=test", "MYSQL_ADMIN_PASSWORD=abcdef"]
|
65
|
-
end
|
66
|
-
|
67
|
-
let(:dot_env) do
|
68
|
-
["TEST_ENV_VAR=test2","", "TEST_ENV_VAR2=test3"]
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#deploy' do
|
72
|
-
context 'when api_url is nil' do
|
73
|
-
it 'raises error' do
|
74
|
-
allow(subject).to receive(:settings).and_return({'server' => {}})
|
75
|
-
expect{subject.deploy({})}.to raise_error(ArgumentError)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'when token is nil' do
|
80
|
-
it 'raises error' do
|
81
|
-
allow(subject).to receive(:settings).and_return({'server' => {'url' => 'http://kontena.test'}})
|
82
|
-
expect{subject.deploy({})}.to raise_error(ArgumentError)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when api url and token are valid' do
|
87
|
-
before(:each) do
|
88
|
-
allow(subject).to receive(:settings).and_return(settings)
|
89
|
-
allow(File).to receive(:read).and_return(yml)
|
90
|
-
allow(subject).to receive(:get_service).and_raise(Kontena::Errors::StandardError.new(404, 'Not Found'))
|
91
|
-
allow(subject).to receive(:create_service).and_return({'id' => 'kontena-test-mysql'},{'id' => 'kontena-test-wordpress'})
|
92
|
-
allow(subject).to receive(:current_grid).and_return('1')
|
93
|
-
allow(subject).to receive(:deploy_service).and_return(nil)
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'reads ./kontena.yml file by default' do
|
97
|
-
allow(subject).to receive(:settings).and_return(settings)
|
98
|
-
expect(File).to receive(:read).with('./kontena.yml').and_return(yml)
|
99
|
-
expect(options).to receive(:file).once.and_return(false)
|
100
|
-
subject.deploy(options)
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'reads given yml file' do
|
104
|
-
expect(options).to receive(:file).once.and_return('custom.yml')
|
105
|
-
expect(File).to receive(:read).with('custom.yml').and_return(yml)
|
106
|
-
subject.deploy(options)
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'uses current directory as service name prefix by default' do
|
110
|
-
current_dir = '/kontena/tests/stacks'
|
111
|
-
allow(Dir).to receive(:getwd).and_return(current_dir)
|
112
|
-
expect(File).to receive(:basename).with(current_dir).and_return('stacks')
|
113
|
-
subject.deploy(options)
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'when yml file has multiple env files' do
|
117
|
-
it 'merges environment variables correctly' do
|
118
|
-
allow(subject).to receive(:current_dir).and_return("kontena-test")
|
119
|
-
allow(YAML).to receive(:load).and_return(services)
|
120
|
-
services['wordpress']['environment'] = ['MYSQL_ADMIN_PASSWORD=password']
|
121
|
-
services['wordpress']['env_file'] = %w(/path/to/env_file .env)
|
122
|
-
|
123
|
-
expect(File).to receive(:readlines).with('/path/to/env_file').and_return(env_vars)
|
124
|
-
expect(File).to receive(:readlines).with('.env').and_return(dot_env)
|
125
|
-
|
126
|
-
data = {
|
127
|
-
:name =>"kontena-test-wordpress",
|
128
|
-
:image=>"wordpress:latest",
|
129
|
-
:env=>["MYSQL_ADMIN_PASSWORD=password", "TEST_ENV_VAR=test", "TEST_ENV_VAR2=test3"],
|
130
|
-
:container_count=>2,
|
131
|
-
:stateful=>false,
|
132
|
-
:links=>[{:name=>"kontena-test-mysql", :alias=>"db"}],
|
133
|
-
:ports=>[{:container_port=>"80", :node_port=>"80", :protocol=>"tcp"}]
|
134
|
-
}
|
135
|
-
|
136
|
-
expect(subject).to receive(:create_service).with('1234567', '1', data)
|
137
|
-
subject.deploy(options)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context 'when yml file has one env file' do
|
142
|
-
it 'merges environment variables correctly' do
|
143
|
-
allow(subject).to receive(:current_dir).and_return("kontena-test")
|
144
|
-
allow(YAML).to receive(:load).and_return(services)
|
145
|
-
services['wordpress']['environment'] = ['MYSQL_ADMIN_PASSWORD=password']
|
146
|
-
services['wordpress']['env_file'] = '/path/to/env_file'
|
147
|
-
|
148
|
-
expect(File).to receive(:readlines).with('/path/to/env_file').and_return(env_vars)
|
149
|
-
|
150
|
-
data = {
|
151
|
-
:name =>"kontena-test-wordpress",
|
152
|
-
:image=>"wordpress:latest",
|
153
|
-
:env=>["MYSQL_ADMIN_PASSWORD=password", "TEST_ENV_VAR=test"],
|
154
|
-
:container_count=>2,
|
155
|
-
:stateful=>false,
|
156
|
-
:links=>[{:name=>"kontena-test-mysql", :alias=>"db"}],
|
157
|
-
:ports=>[{:container_port=>"80", :node_port=>"80", :protocol=>"tcp"}]
|
158
|
-
}
|
159
|
-
|
160
|
-
expect(subject).to receive(:create_service).with('1234567', '1', data)
|
161
|
-
subject.deploy(options)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'creates mysql service before wordpress' do
|
166
|
-
allow(subject).to receive(:current_dir).and_return("kontena-test")
|
167
|
-
data = {:name =>"kontena-test-mysql", :image=>'mysql:5.6', :env=>["MYSQL_ROOT_PASSWORD=kontena-test_secret"], :container_count=>nil, :stateful=>true}
|
168
|
-
expect(subject).to receive(:create_service).with('1234567', '1', data)
|
169
|
-
|
170
|
-
subject.deploy(options)
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'creates wordpress service' do
|
174
|
-
allow(subject).to receive(:current_dir).and_return("kontena-test")
|
175
|
-
|
176
|
-
data = {
|
177
|
-
:name =>"kontena-test-wordpress",
|
178
|
-
:image=>"wordpress:4.1",
|
179
|
-
:env=>["WORDPRESS_DB_PASSWORD=kontena-test_secret"],
|
180
|
-
:container_count=>2,
|
181
|
-
:stateful=>true,
|
182
|
-
:links=>[{:name=>"kontena-test-mysql", :alias=>"mysql"}],
|
183
|
-
:ports=>[{:container_port=>"80", :node_port=>"80", :protocol=>"tcp"}]
|
184
|
-
}
|
185
|
-
expect(subject).to receive(:create_service).with('1234567', '1', data)
|
186
|
-
|
187
|
-
subject.deploy(options)
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'deploys services' do
|
191
|
-
allow(subject).to receive(:current_dir).and_return("kontena-test")
|
192
|
-
expect(subject).to receive(:deploy_service).with('1234567', 'kontena-test-mysql', {})
|
193
|
-
expect(subject).to receive(:deploy_service).with('1234567', 'kontena-test-wordpress', {:strategy => 'ha'})
|
194
|
-
subject.deploy(options)
|
195
|
-
end
|
196
|
-
|
197
|
-
context 'when giving service option' do
|
198
|
-
it 'deploys only given services' do
|
199
|
-
allow(subject).to receive(:current_dir).and_return("kontena-test")
|
200
|
-
allow(options).to receive(:service).and_return(['wordpress'])
|
201
|
-
allow(subject).to receive(:deploy_services).and_return({})
|
202
|
-
expect(subject).to receive(:create).once.with('wordpress', anything).and_return({})
|
203
|
-
expect(subject).not_to receive(:create).with('mysql', services['mysql'])
|
204
|
-
|
205
|
-
subject.deploy(options)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|