kontena-cli 0.14.7 → 0.15.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/VERSION +1 -1
  4. data/bin/kontena +3 -50
  5. data/examples/kontena-plugin-hello/.gitignore +9 -0
  6. data/examples/kontena-plugin-hello/Gemfile +4 -0
  7. data/examples/kontena-plugin-hello/README.md +3 -0
  8. data/examples/kontena-plugin-hello/bin/console +14 -0
  9. data/examples/kontena-plugin-hello/bin/setup +8 -0
  10. data/examples/kontena-plugin-hello/kontena-plugin-hello.gemspec +22 -0
  11. data/examples/kontena-plugin-hello/lib/kontena/plugin/hello.rb +7 -0
  12. data/examples/kontena-plugin-hello/lib/kontena/plugin/hello/world_command.rb +6 -0
  13. data/examples/kontena-plugin-hello/lib/kontena/plugin/hello_command.rb +9 -0
  14. data/examples/kontena-plugin-hello/lib/kontena_cli_plugin.rb +5 -0
  15. data/kontena-cli.gemspec +1 -3
  16. data/lib/kontena/cli/apps/build_command.rb +3 -0
  17. data/lib/kontena/cli/apps/common.rb +6 -1
  18. data/lib/kontena/cli/apps/deploy_command.rb +1 -1
  19. data/lib/kontena/cli/apps/docker_helper.rb +13 -14
  20. data/lib/kontena/cli/apps/service_generator.rb +19 -11
  21. data/lib/kontena/cli/apps/service_generator_v2.rb +1 -0
  22. data/lib/kontena/cli/apps/yaml/reader.rb +15 -0
  23. data/lib/kontena/cli/apps/yaml/service_extender.rb +28 -0
  24. data/lib/kontena/cli/apps/yaml/validations.rb +38 -24
  25. data/lib/kontena/cli/apps/yaml/validator.rb +7 -7
  26. data/lib/kontena/cli/apps/yaml/validator_v2.rb +7 -6
  27. data/lib/kontena/cli/certificate/authorize_command.rb +23 -0
  28. data/lib/kontena/cli/certificate/get_command.rb +25 -0
  29. data/lib/kontena/cli/certificate/register_command.rb +19 -0
  30. data/lib/kontena/cli/certificate_command.rb +14 -0
  31. data/lib/kontena/cli/containers/containers_helper.rb +22 -0
  32. data/lib/kontena/cli/containers/exec_command.rb +9 -2
  33. data/lib/kontena/cli/grids/logs_command.rb +14 -3
  34. data/lib/kontena/cli/master_command.rb +1 -12
  35. data/lib/kontena/cli/node_command.rb +0 -16
  36. data/lib/kontena/cli/plugin_command.rb +15 -0
  37. data/lib/kontena/cli/plugins/install_command.rb +28 -0
  38. data/lib/kontena/cli/plugins/list_command.rb +13 -0
  39. data/lib/kontena/cli/plugins/search_command.rb +29 -0
  40. data/lib/kontena/cli/plugins/uninstall_command.rb +30 -0
  41. data/lib/kontena/cli/registry/create_command.rb +1 -1
  42. data/lib/kontena/cli/services/create_command.rb +16 -0
  43. data/lib/kontena/cli/services/list_command.rb +17 -3
  44. data/lib/kontena/cli/services/logs_command.rb +63 -18
  45. data/lib/kontena/cli/services/services_helper.rb +47 -4
  46. data/lib/kontena/cli/services/update_command.rb +16 -0
  47. data/lib/kontena/cli/stack_command.rb +20 -0
  48. data/lib/kontena/cli/stacks/common.rb +39 -0
  49. data/lib/kontena/cli/stacks/create_command.rb +27 -0
  50. data/lib/kontena/cli/stacks/deploy_command.rb +26 -0
  51. data/lib/kontena/cli/stacks/list_command.rb +38 -0
  52. data/lib/kontena/cli/stacks/remove_command.rb +26 -0
  53. data/lib/kontena/cli/stacks/show_command.rb +38 -0
  54. data/lib/kontena/cli/stacks/update_command.rb +27 -0
  55. data/lib/kontena/client.rb +11 -4
  56. data/lib/kontena/command.rb +4 -0
  57. data/lib/kontena/main_command.rb +61 -0
  58. data/lib/kontena/plugin_manager.rb +38 -0
  59. data/lib/kontena/util.rb +17 -0
  60. data/lib/kontena_cli.rb +6 -0
  61. data/spec/fixtures/health.yml +26 -0
  62. data/spec/fixtures/kontena-build.yml +16 -0
  63. data/spec/fixtures/kontena_build_v2.yaml +26 -0
  64. data/spec/kontena/cli/app/build_command_spec.rb +13 -1
  65. data/spec/kontena/cli/app/common_spec.rb +11 -0
  66. data/spec/kontena/cli/app/deploy_command_spec.rb +1 -1
  67. data/spec/kontena/cli/app/docker_helper_spec.rb +45 -0
  68. data/spec/kontena/cli/app/service_generator_spec.rb +52 -1
  69. data/spec/kontena/cli/app/yaml/service_extender_spec.rb +24 -0
  70. data/spec/kontena/cli/app/yaml/validator_spec.rb +97 -14
  71. data/spec/kontena/cli/common_spec.rb +0 -5
  72. data/spec/kontena/cli/containers/containers_helper_spec.rb +16 -0
  73. data/spec/kontena/cli/services/services_helper_spec.rb +50 -1
  74. data/spec/kontena/cli/version_command_spec.rb +1 -1
  75. data/spec/kontena/client_spec.rb +156 -0
  76. data/spec/kontena/plugin_manager_spec.rb +22 -0
  77. data/spec/spec_helper.rb +1 -0
  78. metadata +54 -125
  79. data/lib/kontena/cli/master/aws/create_command.rb +0 -48
  80. data/lib/kontena/cli/master/aws_command.rb +0 -8
  81. data/lib/kontena/cli/master/azure/create_command.rb +0 -37
  82. data/lib/kontena/cli/master/azure_command.rb +0 -13
  83. data/lib/kontena/cli/master/digital_ocean/create_command.rb +0 -38
  84. data/lib/kontena/cli/master/digital_ocean_command.rb +0 -13
  85. data/lib/kontena/cli/master/packet/create_command.rb +0 -42
  86. data/lib/kontena/cli/master/packet_command.rb +0 -14
  87. data/lib/kontena/cli/master/upcloud/create_command.rb +0 -39
  88. data/lib/kontena/cli/master/upcloud_command.rb +0 -13
  89. data/lib/kontena/cli/master/vagrant/create_command.rb +0 -25
  90. data/lib/kontena/cli/master/vagrant/restart_command.rb +0 -20
  91. data/lib/kontena/cli/master/vagrant/ssh_command.rb +0 -15
  92. data/lib/kontena/cli/master/vagrant/start_command.rb +0 -20
  93. data/lib/kontena/cli/master/vagrant/stop_command.rb +0 -20
  94. data/lib/kontena/cli/master/vagrant/terminate_command.rb +0 -13
  95. data/lib/kontena/cli/master/vagrant_command.rb +0 -23
  96. data/lib/kontena/cli/nodes/aws/create_command.rb +0 -44
  97. data/lib/kontena/cli/nodes/aws/restart_command.rb +0 -29
  98. data/lib/kontena/cli/nodes/aws/terminate_command.rb +0 -21
  99. data/lib/kontena/cli/nodes/aws_command.rb +0 -15
  100. data/lib/kontena/cli/nodes/azure/create_command.rb +0 -38
  101. data/lib/kontena/cli/nodes/azure/restart_command.rb +0 -32
  102. data/lib/kontena/cli/nodes/azure/terminate_command.rb +0 -21
  103. data/lib/kontena/cli/nodes/azure_command.rb +0 -15
  104. data/lib/kontena/cli/nodes/digital_ocean/create_command.rb +0 -32
  105. data/lib/kontena/cli/nodes/digital_ocean/restart_command.rb +0 -27
  106. data/lib/kontena/cli/nodes/digital_ocean/terminate_command.rb +0 -19
  107. data/lib/kontena/cli/nodes/digital_ocean_command.rb +0 -15
  108. data/lib/kontena/cli/nodes/packet/create_command.rb +0 -35
  109. data/lib/kontena/cli/nodes/packet/restart_command.rb +0 -17
  110. data/lib/kontena/cli/nodes/packet/terminate_command.rb +0 -20
  111. data/lib/kontena/cli/nodes/packet_command.rb +0 -15
  112. data/lib/kontena/cli/nodes/upcloud/create_command.rb +0 -33
  113. data/lib/kontena/cli/nodes/upcloud/restart_command.rb +0 -20
  114. data/lib/kontena/cli/nodes/upcloud/terminate_command.rb +0 -20
  115. data/lib/kontena/cli/nodes/upcloud_command.rb +0 -15
  116. data/lib/kontena/cli/nodes/vagrant/create_command.rb +0 -27
  117. data/lib/kontena/cli/nodes/vagrant/restart_command.rb +0 -26
  118. data/lib/kontena/cli/nodes/vagrant/ssh_command.rb +0 -21
  119. data/lib/kontena/cli/nodes/vagrant/start_command.rb +0 -26
  120. data/lib/kontena/cli/nodes/vagrant/stop_command.rb +0 -26
  121. data/lib/kontena/cli/nodes/vagrant/terminate_command.rb +0 -17
  122. data/lib/kontena/cli/nodes/vagrant_command.rb +0 -21
  123. data/lib/kontena/machine/aws.rb +0 -13
  124. data/lib/kontena/machine/aws/cloudinit.yml +0 -71
  125. data/lib/kontena/machine/aws/cloudinit_master.yml +0 -118
  126. data/lib/kontena/machine/aws/common.rb +0 -58
  127. data/lib/kontena/machine/aws/master_provisioner.rb +0 -187
  128. data/lib/kontena/machine/aws/node_destroyer.rb +0 -51
  129. data/lib/kontena/machine/aws/node_provisioner.rb +0 -204
  130. data/lib/kontena/machine/azure.rb +0 -13
  131. data/lib/kontena/machine/azure/cloudinit.yml +0 -64
  132. data/lib/kontena/machine/azure/cloudinit_master.yml +0 -106
  133. data/lib/kontena/machine/azure/logger.rb +0 -27
  134. data/lib/kontena/machine/azure/master_provisioner.rb +0 -128
  135. data/lib/kontena/machine/azure/node_destroyer.rb +0 -53
  136. data/lib/kontena/machine/azure/node_provisioner.rb +0 -132
  137. data/lib/kontena/machine/digital_ocean.rb +0 -13
  138. data/lib/kontena/machine/digital_ocean/cloudinit.yml +0 -64
  139. data/lib/kontena/machine/digital_ocean/cloudinit_master.yml +0 -118
  140. data/lib/kontena/machine/digital_ocean/master_provisioner.rb +0 -99
  141. data/lib/kontena/machine/digital_ocean/node_destroyer.rb +0 -40
  142. data/lib/kontena/machine/digital_ocean/node_provisioner.rb +0 -88
  143. data/lib/kontena/machine/packet.rb +0 -17
  144. data/lib/kontena/machine/packet/cloudinit.yml +0 -66
  145. data/lib/kontena/machine/packet/cloudinit_master.yml +0 -118
  146. data/lib/kontena/machine/packet/master_provisioner.rb +0 -93
  147. data/lib/kontena/machine/packet/node_destroyer.rb +0 -42
  148. data/lib/kontena/machine/packet/node_provisioner.rb +0 -77
  149. data/lib/kontena/machine/packet/node_restarter.rb +0 -41
  150. data/lib/kontena/machine/packet/packet_common.rb +0 -89
  151. data/lib/kontena/machine/upcloud.rb +0 -9
  152. data/lib/kontena/machine/upcloud/cloudinit.yml +0 -64
  153. data/lib/kontena/machine/upcloud/cloudinit_master.yml +0 -118
  154. data/lib/kontena/machine/upcloud/master_provisioner.rb +0 -138
  155. data/lib/kontena/machine/upcloud/node_destroyer.rb +0 -85
  156. data/lib/kontena/machine/upcloud/node_provisioner.rb +0 -121
  157. data/lib/kontena/machine/upcloud/node_restarter.rb +0 -49
  158. data/lib/kontena/machine/upcloud/upcloud_common.rb +0 -74
  159. data/lib/kontena/machine/vagrant.rb +0 -12
  160. data/lib/kontena/machine/vagrant/Vagrantfile.master.rb.erb +0 -104
  161. data/lib/kontena/machine/vagrant/Vagrantfile.node.rb.erb +0 -32
  162. data/lib/kontena/machine/vagrant/cloudinit.yml +0 -73
  163. data/lib/kontena/machine/vagrant/master_destroyer.rb +0 -37
  164. data/lib/kontena/machine/vagrant/master_provisioner.rb +0 -79
  165. data/lib/kontena/machine/vagrant/node_destroyer.rb +0 -40
  166. data/lib/kontena/machine/vagrant/node_provisioner.rb +0 -68
@@ -1,12 +0,0 @@
1
- require_relative 'common'
2
- include Kontena::Machine::Common
3
-
4
- unless which('vagrant')
5
- abort('Vagrant is not installed. See https://www.vagrantup.com/ for instructions.')
6
- end
7
-
8
- require_relative 'random_name'
9
- require_relative 'vagrant/master_provisioner'
10
- require_relative 'vagrant/master_destroyer'
11
- require_relative 'vagrant/node_provisioner'
12
- require_relative 'vagrant/node_destroyer'
@@ -1,104 +0,0 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
- VAGRANTFILE_API_VERSION = "2"
6
-
7
- cloud_init = <<INIT
8
- #cloud-config
9
- write_files:
10
- - path: /etc/kontena-server.env
11
- permissions: 0600
12
- owner: root
13
- content: |
14
- KONTENA_VERSION=<%= version %>
15
- KONTENA_VAULT_KEY=<%= vault_secret %>
16
- KONTENA_VAULT_IV=<%= vault_iv %>
17
- coreos:
18
- update:
19
- reboot-strategy: off
20
- units:
21
- - name: kontena-server-mongo.service
22
- command: start
23
- enable: true
24
- content: |
25
- [Unit]
26
- Description=kontena-server-mongo
27
- After=network-online.target
28
- After=docker.service
29
- Description=Kontena Server MongoDB
30
- Documentation=http://www.mongodb.org/
31
- Requires=network-online.target
32
- Requires=docker.service
33
-
34
- [Service]
35
- Restart=always
36
- RestartSec=5
37
- ExecStartPre=/usr/bin/docker pull mongo:3.0
38
- ExecStartPre=-/usr/bin/docker create --name=kontena-server-mongo-data mongo:3.0
39
- ExecStartPre=-/usr/bin/docker stop kontena-server-mongo
40
- ExecStartPre=-/usr/bin/docker rm kontena-server-mongo
41
- ExecStart=/usr/bin/docker run --name=kontena-server-mongo \
42
- --volumes-from=kontena-server-mongo-data \
43
- mongo:3.0 mongod --smallfiles
44
-
45
- - name: kontena-server-api.service
46
- command: start
47
- enable: true
48
- content: |
49
- [Unit]
50
- Description=kontena-server-api
51
- After=network-online.target
52
- After=docker.service
53
- After=kontena-server-mongo.service
54
- Description=Kontena Master
55
- Documentation=http://www.kontena.io/
56
- Requires=network-online.target
57
- Requires=docker.service
58
- Requires=kontena-server-mongo.service
59
-
60
- [Service]
61
- Restart=always
62
- RestartSec=5
63
- EnvironmentFile=/etc/kontena-server.env
64
- ExecStartPre=-/usr/bin/docker stop kontena-server-api
65
- ExecStartPre=-/usr/bin/docker rm kontena-server-api
66
- ExecStartPre=/usr/bin/docker pull kontena/server:${KONTENA_VERSION}
67
- ExecStart=/usr/bin/docker run --name kontena-server-api \
68
- --link kontena-server-mongo:mongodb \
69
- -e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
70
- -e VAULT_KEY=${KONTENA_VAULT_KEY} -e VAULT_IV=${KONTENA_VAULT_IV} \
71
- <% if auth_server %>-e AUTH_API_URL=<%= auth_server %><% end %> \
72
- -p 8080:9292 \
73
- kontena/server:${KONTENA_VERSION}
74
- INIT
75
-
76
- cloud_init_file = Tempfile.new('kontena-master')
77
- File.write(cloud_init_file.path, cloud_init)
78
-
79
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
80
- config.vm.provider :virtualbox do |v|
81
- v.check_guest_additions = false
82
- v.functional_vboxsf = false
83
- end
84
-
85
- if Vagrant.has_plugin?("vagrant-vbguest") then
86
- config.vbguest.auto_update = false
87
- end
88
-
89
- config.vm.define "<%= name %>" do |docker|
90
- docker.vm.box = "coreos-stable"
91
- docker.vm.box_url = "http://stable.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json"
92
- docker.vm.network "private_network", ip: "192.168.66.100"
93
- docker.vm.hostname = "<%= name %>"
94
- docker.vm.provider "virtualbox" do |vb|
95
- vb.gui = false
96
- vb.customize ["modifyvm", :id, "--memory", "512"]
97
- vb.auto_nat_dns_proxy = false
98
- vb.customize ["modifyvm", :id, "--natdnsproxy1", "off" ]
99
- vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off" ]
100
- end
101
- docker.vm.provision :file, :source => cloud_init_file.path, :destination => "/tmp/vagrantfile-user-data"
102
- docker.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
103
- end
104
- end
@@ -1,32 +0,0 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
- VAGRANTFILE_API_VERSION = "2"
6
-
7
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
- config.vm.provider :virtualbox do |v|
9
- v.check_guest_additions = false
10
- v.functional_vboxsf = false
11
- end
12
-
13
- if Vagrant.has_plugin?("vagrant-vbguest") then
14
- config.vbguest.auto_update = false
15
- end
16
-
17
- config.vm.define "<%= name %>" do |docker|
18
- docker.vm.box = "coreos-stable"
19
- docker.vm.box_url = "http://stable.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json"
20
- docker.vm.network "private_network", type: "dhcp"
21
- docker.vm.hostname = "<%= name %>"
22
- docker.vm.provider "virtualbox" do |vb|
23
- vb.gui = false
24
- vb.customize ["modifyvm", :id, "--memory", "<%= memory %>"]
25
- vb.auto_nat_dns_proxy = false
26
- vb.customize ["modifyvm", :id, "--natdnsproxy1", "off" ]
27
- vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off" ]
28
- end
29
- docker.vm.provision :file, :source => "<%= cloudinit %>", :destination => "/tmp/vagrantfile-user-data"
30
- docker.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
31
- end
32
- end
@@ -1,73 +0,0 @@
1
- #cloud-config
2
- write_files:
3
- - path: /etc/kontena-agent.env
4
- permissions: 0600
5
- owner: root
6
- content: |
7
- KONTENA_URI="<%= master_uri %>"
8
- KONTENA_TOKEN="<%= grid_token %>"
9
- KONTENA_PEER_INTERFACE=eth1
10
- KONTENA_VERSION=<%= version %>
11
- - path: /etc/systemd/system/docker.service.d/50-kontena.conf
12
- content: |
13
- [Service]
14
- Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/19" --bip="172.17.43.1/16"'
15
- - path: /etc/sysctl.d/99-inotify.conf
16
- owner: root
17
- permissions: 0644
18
- content: |
19
- fs.inotify.max_user_instances = 8192
20
- coreos:
21
- update:
22
- reboot-strategy: off
23
- units:
24
- - name: 00-eth.network
25
- runtime: true
26
- content: |
27
- [Match]
28
- Name=eth*
29
- [Network]
30
- DHCP=yes
31
- DNS=172.17.43.1
32
- DNS=172.28.128.1
33
- DNS=8.8.8.8
34
- DOMAINS=kontena.local
35
- [DHCP]
36
- UseDNS=false
37
-
38
- - name: 10-weave.network
39
- runtime: false
40
- content: |
41
- [Match]
42
- Type=bridge
43
- Name=weave*
44
-
45
- [Network]
46
- - name: kontena-agent.service
47
- command: start
48
- enable: true
49
- content: |
50
- [Unit]
51
- Description=kontena-agent
52
- After=network-online.target
53
- After=docker.service
54
- Description=Kontena Agent
55
- Documentation=http://www.kontena.io/
56
- Requires=network-online.target
57
- Requires=docker.service
58
-
59
- [Service]
60
- Restart=always
61
- RestartSec=5
62
- EnvironmentFile=/etc/kontena-agent.env
63
- ExecStartPre=-/usr/bin/docker stop kontena-agent
64
- ExecStartPre=-/usr/bin/docker rm kontena-agent
65
- ExecStartPre=/usr/bin/docker pull kontena/agent:${KONTENA_VERSION}
66
- ExecStart=/usr/bin/docker run --name kontena-agent \
67
- -e KONTENA_URI=${KONTENA_URI} \
68
- -e KONTENA_TOKEN=${KONTENA_TOKEN} \
69
- -e KONTENA_PEER_INTERFACE=${KONTENA_PEER_INTERFACE} \
70
- -v=/var/run/docker.sock:/var/run/docker.sock \
71
- -v=/etc/kontena-agent.env:/etc/kontena.env \
72
- --net=host \
73
- kontena/agent:${KONTENA_VERSION}
@@ -1,37 +0,0 @@
1
- require 'fileutils'
2
-
3
- module Kontena
4
- module Machine
5
- module Vagrant
6
- class MasterDestroyer
7
-
8
- attr_reader :client, :api_client
9
-
10
- # @param [Kontena::Client] api_client Kontena api client
11
- def initialize(api_client)
12
- @api_client = api_client
13
- end
14
-
15
- def run!
16
- if api_client.get("grids")['grids'].size > 0
17
- abort("Cannot remove kontena-master because it has grids".colorize(:red))
18
- end
19
-
20
- vagrant_path = "#{Dir.home}/.kontena/vagrant_master"
21
- Dir.chdir(vagrant_path) do
22
- ShellSpinner "Terminating Vagrant kontena-master " do
23
- Open3.popen2('vagrant destroy -f') do |stdin, output, wait|
24
- while o = output.gets
25
- puts o if ENV['DEBUG']
26
- end
27
- if wait.value == 0
28
- FileUtils.remove_entry_secure(vagrant_path)
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,79 +0,0 @@
1
- require 'fileutils'
2
- require 'erb'
3
- require 'open3'
4
- require 'shell-spinner'
5
-
6
- module Kontena
7
- module Machine
8
- module Vagrant
9
- class MasterProvisioner
10
- include RandomName
11
-
12
- API_URL = 'http://192.168.66.100:8080'
13
- attr_reader :client
14
-
15
- def initialize
16
- @client = Excon.new(API_URL)
17
- end
18
-
19
- def run!(opts)
20
- name = generate_name
21
- version = opts[:version]
22
- memory = opts[:memory] || 1024
23
- auth_server = opts[:auth_server]
24
- vault_secret = opts[:vault_secret]
25
- vault_iv = opts[:vault_iv]
26
- vagrant_path = "#{Dir.home}/.kontena/vagrant_master/"
27
- if Dir.exist?(vagrant_path)
28
- abort("Oops... cannot create Kontena Master! You can run only one Kontena Master with Vagrant".colorize(:red))
29
- end
30
- FileUtils.mkdir_p(vagrant_path)
31
-
32
- template = File.join(__dir__ , '/Vagrantfile.master.rb.erb')
33
- cloudinit_template = File.join(__dir__ , '/cloudinit.yml')
34
- vars = {
35
- name: name,
36
- version: version,
37
- memory: memory,
38
- auth_server: auth_server,
39
- vault_secret: vault_secret,
40
- vault_iv: vault_iv,
41
- cloudinit: "#{vagrant_path}/cloudinit.yml"
42
- }
43
- vagrant_data = erb(File.read(template), vars)
44
- cloudinit = erb(File.read(cloudinit_template), vars)
45
- File.write("#{vagrant_path}/Vagrantfile", vagrant_data)
46
- File.write("#{vagrant_path}/cloudinit.yml", cloudinit)
47
- Dir.chdir(vagrant_path) do
48
- ShellSpinner "Creating Vagrant machine #{name.colorize(:cyan)} " do
49
- Open3.popen2('vagrant box update && vagrant up') do |stdin, output, wait|
50
- while o = output.gets
51
- print o if ENV['DEBUG']
52
- end
53
- end
54
- end
55
- ShellSpinner "Waiting for #{name.colorize(:cyan)} to start " do
56
- sleep 1 until master_running?
57
- end
58
- puts "Kontena Master is now running at #{API_URL}"
59
- puts "Use #{"kontena login #{API_URL}".colorize(:light_black)} to complete Kontena Master setup"
60
- end
61
- end
62
-
63
- def erb(template, vars)
64
- ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
65
- end
66
-
67
- def master_running?
68
- client.get(path: '/').status == 200
69
- rescue
70
- false
71
- end
72
-
73
- def generate_name
74
- "kontena-master-#{super}-#{rand(1..99)}"
75
- end
76
- end
77
- end
78
- end
79
- end
@@ -1,40 +0,0 @@
1
- require 'fileutils'
2
-
3
- module Kontena
4
- module Machine
5
- module Vagrant
6
- class NodeDestroyer
7
- include RandomName
8
-
9
- attr_reader :client, :api_client
10
-
11
- # @param [Kontena::Client] api_client Kontena api client
12
- def initialize(api_client)
13
- @api_client = api_client
14
- end
15
-
16
- def run!(grid, name)
17
- vagrant_path = "#{Dir.home}/.kontena/#{grid}/#{name}"
18
- Dir.chdir(vagrant_path) do
19
- ShellSpinner "Terminating Vagrant machine #{name.colorize(:cyan)} " do
20
- Open3.popen2('vagrant destroy -f') do |stdin, output, wait|
21
- while o = output.gets
22
- puts o if ENV['DEBUG']
23
- end
24
- if wait.value == 0
25
- FileUtils.remove_entry_secure(vagrant_path)
26
- end
27
- end
28
- end
29
- end
30
- node = api_client.get("grids/#{grid}/nodes")['nodes'].find{|n| n['name'] == name}
31
- if node
32
- ShellSpinner "Removing node #{name.colorize(:cyan)} from grid #{grid.colorize(:cyan)} " do
33
- api_client.delete("grids/#{grid}/nodes/#{name}")
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,68 +0,0 @@
1
- require 'fileutils'
2
- require 'erb'
3
- require 'open3'
4
- require 'shell-spinner'
5
-
6
- module Kontena
7
- module Machine
8
- module Vagrant
9
- class NodeProvisioner
10
- include RandomName
11
-
12
- attr_reader :client, :api_client
13
-
14
- # @param [Kontena::Client] api_client Kontena api client
15
- def initialize(api_client)
16
- @api_client = api_client
17
- end
18
-
19
- def run!(opts)
20
- grid = opts[:grid]
21
- name = opts[:name] || generate_name
22
- version = opts[:version]
23
- vagrant_path = "#{Dir.home}/.kontena/#{grid}/#{name}"
24
- FileUtils.mkdir_p(vagrant_path)
25
-
26
- template = File.join(__dir__ , '/Vagrantfile.node.rb.erb')
27
- cloudinit_template = File.join(__dir__ , '/cloudinit.yml')
28
- vars = {
29
- name: name,
30
- version: version,
31
- memory: opts[:memory] || 1024,
32
- master_uri: opts[:master_uri],
33
- grid_token: opts[:grid_token],
34
- cloudinit: "#{vagrant_path}/cloudinit.yml"
35
- }
36
- vagrant_data = erb(File.read(template), vars)
37
- cloudinit = erb(File.read(cloudinit_template), vars)
38
- File.write("#{vagrant_path}/Vagrantfile", vagrant_data)
39
- File.write("#{vagrant_path}/cloudinit.yml", cloudinit)
40
- Dir.chdir(vagrant_path) do
41
- ShellSpinner "Creating Vagrant machine #{name.colorize(:cyan)} " do
42
- Open3.popen2('vagrant box update && vagrant up') do |stdin, output, wait|
43
- while o = output.gets
44
- print o if ENV['DEBUG']
45
- end
46
- end
47
- end
48
- ShellSpinner "Waiting for node #{name.colorize(:cyan)} join to grid #{grid.colorize(:cyan)} " do
49
- sleep 1 until node_exists_in_grid?(grid, name)
50
- end
51
- end
52
- end
53
-
54
- def generate_name
55
- "#{super}-#{rand(1..99)}"
56
- end
57
-
58
- def erb(template, vars)
59
- ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
60
- end
61
-
62
- def node_exists_in_grid?(grid, name)
63
- api_client.get("grids/#{grid}/nodes")['nodes'].find{|n| n['name'] == name}
64
- end
65
- end
66
- end
67
- end
68
- end