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,99 +0,0 @@
1
- require 'fileutils'
2
- require 'erb'
3
- require 'open3'
4
- require 'shell-spinner'
5
-
6
- module Kontena
7
- module Machine
8
- module DigitalOcean
9
- class MasterProvisioner
10
- include RandomName
11
- include Machine::CertHelper
12
-
13
- attr_reader :client, :http_client
14
-
15
- # @param [String] token Digital Ocean token
16
- def initialize(token)
17
- @client = DropletKit::Client.new(access_token: token)
18
- end
19
-
20
- def run!(opts)
21
- abort('Invalid ssh key') unless File.exists?(File.expand_path(opts[:ssh_key]))
22
-
23
- ssh_key = ssh_key(File.read(File.expand_path(opts[:ssh_key])).strip)
24
- abort('Ssh key does not exist in Digital Ocean') unless ssh_key
25
-
26
- if opts[:ssl_cert]
27
- abort('Invalid ssl cert') unless File.exists?(File.expand_path(opts[:ssl_cert]))
28
- ssl_cert = File.read(File.expand_path(opts[:ssl_cert]))
29
- else
30
- ShellSpinner "Generating self-signed SSL certificate" do
31
- ssl_cert = generate_self_signed_cert
32
- end
33
- end
34
-
35
- userdata_vars = {
36
- ssl_cert: ssl_cert,
37
- auth_server: opts[:auth_server],
38
- version: opts[:version],
39
- vault_secret: opts[:vault_secret],
40
- vault_iv: opts[:vault_iv],
41
- mongodb_uri: opts[:mongodb_uri]
42
- }
43
-
44
- droplet = DropletKit::Droplet.new(
45
- name: generate_name,
46
- region: opts[:region],
47
- image: 'coreos-stable',
48
- size: opts[:size],
49
- private_networking: true,
50
- user_data: user_data(userdata_vars),
51
- ssh_keys: [ssh_key.id]
52
- )
53
-
54
- ShellSpinner "Creating DigitalOcean droplet #{droplet.name.colorize(:cyan)} " do
55
- droplet = client.droplets.create(droplet)
56
- until droplet.status == 'active'
57
- droplet = client.droplets.find(id: droplet.id)
58
- sleep 5
59
- end
60
- end
61
-
62
- master_url = "https://#{droplet.public_ip}"
63
- Excon.defaults[:ssl_verify_peer] = false
64
- @http_client = Excon.new("#{master_url}", :connect_timeout => 10)
65
-
66
- ShellSpinner "Waiting for #{droplet.name.colorize(:cyan)} to start" do
67
- sleep 5 until master_running?
68
- end
69
-
70
- puts "Kontena Master is now running at #{master_url}"
71
- puts "Use #{"kontena login --name=#{droplet.name.sub('kontena-master-', '')} #{master_url}".colorize(:light_black)} to complete Kontena Master setup"
72
- end
73
-
74
- def user_data(vars)
75
- cloudinit_template = File.join(__dir__ , '/cloudinit_master.yml')
76
- erb(File.read(cloudinit_template), vars)
77
- end
78
-
79
- def generate_name
80
- "kontena-master-#{super}-#{rand(1..9)}"
81
- end
82
-
83
- def ssh_key(public_key)
84
- client.ssh_keys.all.find{|key| key.public_key == public_key}
85
- end
86
-
87
- def master_running?
88
- http_client.get(path: '/').status == 200
89
- rescue
90
- false
91
- end
92
-
93
- def erb(template, vars)
94
- ERB.new(template, nil, '%<>-').result(OpenStruct.new(vars).instance_eval { binding })
95
- end
96
- end
97
- end
98
- end
99
- end
@@ -1,40 +0,0 @@
1
- require 'shell-spinner'
2
-
3
- module Kontena
4
- module Machine
5
- module DigitalOcean
6
- class NodeDestroyer
7
- include RandomName
8
-
9
- attr_reader :client, :api_client
10
-
11
- # @param [Kontena::Client] api_client Kontena api client
12
- # @param [String] token Digital Ocean token
13
- def initialize(api_client, token)
14
- @api_client = api_client
15
- @client = DropletKit::Client.new(access_token: token)
16
- end
17
-
18
- def run!(grid, name)
19
- droplet = client.droplets.all.find{|d| d.name == name}
20
- if droplet
21
- ShellSpinner "Terminating DigitalOcean droplet #{name.colorize(:cyan)} " do
22
- result = client.droplets.delete(id: droplet.id)
23
- if result.is_a?(String)
24
- abort "Cannot delete droplet #{name.colorize(:cyan)} in DigitalOcean"
25
- end
26
- end
27
- else
28
- abort "Cannot find droplet #{name.colorize(:cyan)} in DigitalOcean"
29
- end
30
- node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name}
31
- if node
32
- ShellSpinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do
33
- api_client.delete("grids/#{grid['id']}/nodes/#{name}")
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,88 +0,0 @@
1
- require 'fileutils'
2
- require 'erb'
3
- require 'open3'
4
- require 'shell-spinner'
5
-
6
- module Kontena
7
- module Machine
8
- module DigitalOcean
9
- class NodeProvisioner
10
- include RandomName
11
-
12
- attr_reader :client, :api_client
13
-
14
- # @param [Kontena::Client] api_client Kontena api client
15
- # @param [String] token Digital Ocean token
16
- def initialize(api_client, token)
17
- @api_client = api_client
18
- @client = DropletKit::Client.new(access_token: token)
19
- end
20
-
21
- def run!(opts)
22
- abort('Invalid ssh key') unless File.exists?(File.expand_path(opts[:ssh_key]))
23
-
24
- ssh_key = ssh_key(File.read(File.expand_path(opts[:ssh_key])).strip)
25
- abort('Ssh key does not exist in Digital Ocean') unless ssh_key
26
-
27
- userdata_vars = {
28
- version: opts[:version],
29
- master_uri: opts[:master_uri],
30
- grid_token: opts[:grid_token],
31
- }
32
-
33
- droplet = DropletKit::Droplet.new(
34
- name: opts[:name] || generate_name,
35
- region: opts[:region],
36
- image: 'coreos-stable',
37
- size: opts[:size],
38
- private_networking: true,
39
- user_data: user_data(userdata_vars),
40
- ssh_keys: [ssh_key.id]
41
- )
42
- created = client.droplets.create(droplet)
43
- ShellSpinner "Creating DigitalOcean droplet #{droplet.name.colorize(:cyan)} " do
44
- sleep 5 until client.droplets.find(id: created.id).status == 'active'
45
- end
46
- node = nil
47
- ShellSpinner "Waiting for node #{droplet.name.colorize(:cyan)} join to grid #{opts[:grid].colorize(:cyan)} " do
48
- sleep 2 until node = droplet_exists_in_grid?(opts[:grid], droplet)
49
- end
50
- set_labels(
51
- node,
52
- [
53
- "region=#{opts[:region]}",
54
- "az=#{opts[:region]}",
55
- "provider=digitalocean"
56
- ]
57
- )
58
- end
59
-
60
- def user_data(vars)
61
- cloudinit_template = File.join(__dir__ , '/cloudinit.yml')
62
- erb(File.read(cloudinit_template), vars)
63
- end
64
-
65
- def generate_name
66
- "#{super}-#{rand(1..99)}"
67
- end
68
-
69
- def ssh_key(public_key)
70
- ssh_key = client.ssh_keys.all.find{|key| key.public_key == public_key}
71
- end
72
-
73
- def droplet_exists_in_grid?(grid, droplet)
74
- api_client.get("grids/#{grid}/nodes")['nodes'].find{|n| n['name'] == droplet.name}
75
- end
76
-
77
- def erb(template, vars)
78
- ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
79
- end
80
-
81
- def set_labels(node, labels)
82
- data = {labels: labels}
83
- api_client.put("nodes/#{node['id']}", data, {}, {'Kontena-Grid-Token' => node['grid']['token']})
84
- end
85
- end
86
- end
87
- end
88
- end
@@ -1,17 +0,0 @@
1
- begin
2
- gem 'packethost', '>= 0.0.6'
3
- require 'packethost'
4
- rescue LoadError
5
- puts "It seems that you don't have Packet API installed."
6
- puts "Install it using: gem install packethost"
7
- exit 1
8
- end
9
-
10
- require_relative 'random_name'
11
- require_relative 'cert_helper'
12
- require_relative 'packet/packet_common'
13
- require_relative 'packet/node_provisioner'
14
- require_relative 'packet/node_destroyer'
15
- require_relative 'packet/node_restarter'
16
- require_relative 'packet/master_provisioner'
17
-
@@ -1,66 +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
- KONTENA_PRIVATE_IP=$private_ipv4
12
- - path: /etc/systemd/system/docker.service.d/50-kontena.conf
13
- content: |
14
- [Service]
15
- Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/19" --bip="172.17.43.1/16"'
16
- - path: /etc/sysctl.d/99-inotify.conf
17
- owner: root
18
- permissions: 0644
19
- content: |
20
- fs.inotify.max_user_instances = 8192
21
- - path: /etc/resolv.conf
22
- permissions: 0644
23
- owner: root
24
- content: |
25
- nameserver 172.17.43.1
26
- nameserver 8.8.8.8
27
- nameserver 8.8.4.4
28
- coreos:
29
- units:
30
- - name: 10-weave.network
31
- runtime: false
32
- content: |
33
- [Match]
34
- Type=bridge
35
- Name=weave*
36
-
37
- [Network]
38
- - name: kontena-agent.service
39
- command: start
40
- enable: true
41
- content: |
42
- [Unit]
43
- Description=kontena-agent
44
- After=network-online.target
45
- After=docker.service
46
- Description=Kontena Agent
47
- Documentation=http://www.kontena.io/
48
- Requires=network-online.target
49
- Requires=docker.service
50
-
51
- [Service]
52
- Restart=always
53
- RestartSec=5
54
- EnvironmentFile=/etc/kontena-agent.env
55
- ExecStartPre=-/usr/bin/docker stop kontena-agent
56
- ExecStartPre=-/usr/bin/docker rm kontena-agent
57
- ExecStartPre=/usr/bin/docker pull kontena/agent:${KONTENA_VERSION}
58
- ExecStart=/usr/bin/docker run --name kontena-agent \
59
- -e KONTENA_URI=${KONTENA_URI} \
60
- -e KONTENA_TOKEN=${KONTENA_TOKEN} \
61
- -e KONTENA_PEER_INTERFACE=${KONTENA_PEER_INTERFACE} \
62
- -e KONTENA_PRIVATE_IP=${KONTENA_PRIVATE_IP} \
63
- -v=/var/run/docker.sock:/var/run/docker.sock \
64
- -v=/etc/kontena-agent.env:/etc/kontena.env \
65
- --net=host \
66
- kontena/agent:${KONTENA_VERSION}
@@ -1,118 +0,0 @@
1
- #cloud-config
2
- write_files:
3
- - path: /etc/kontena-server.env
4
- permissions: 0600
5
- owner: root
6
- content: |
7
- KONTENA_VERSION=<%= version %>
8
- KONTENA_VAULT_KEY=<%= vault_secret %>
9
- KONTENA_VAULT_IV=<%= vault_iv %>
10
- <% if ssl_cert %>SSL_CERT="/etc/kontena-server.pem"
11
-
12
- - path: /etc/kontena-server.pem
13
- permissions: 0600
14
- owner: root
15
- content: | <% ssl_cert.split(/\n/).each do |row| %>
16
- <%= row %><% end %><% end %>
17
- - path: /opt/bin/kontena-haproxy.sh
18
- permissions: 0755
19
- owner: root
20
- content: |
21
- #!/bin/sh
22
- if [ -n "$SSL_CERT" ]; then
23
- SSL_CERT=$(awk 1 ORS='\\n' $SSL_CERT)
24
- else
25
- SSL_CERT="**None**"
26
- fi
27
- /usr/bin/docker run --name=kontena-server-haproxy \
28
- --link kontena-server-api:kontena-server-api \
29
- -e SSL_CERT="$SSL_CERT" \
30
- -p 80:80 -p 443:443 kontena/haproxy:latest
31
- coreos:
32
- units:
33
- <% unless mongodb_uri -%>
34
- - name: kontena-server-mongo.service
35
- command: start
36
- enable: true
37
- content: |
38
- [Unit]
39
- Description=kontena-server-mongo
40
- After=network-online.target
41
- After=docker.service
42
- Description=Kontena Server MongoDB
43
- Documentation=http://www.mongodb.org/
44
- Requires=network-online.target
45
- Requires=docker.service
46
-
47
- [Service]
48
- Restart=always
49
- RestartSec=5
50
- ExecStartPre=/usr/bin/docker pull mongo:3.0
51
- ExecStartPre=-/usr/bin/docker create --name=kontena-server-mongo-data mongo:3.0
52
- ExecStartPre=-/usr/bin/docker stop kontena-server-mongo
53
- ExecStartPre=-/usr/bin/docker rm kontena-server-mongo
54
- ExecStart=/usr/bin/docker run --name=kontena-server-mongo \
55
- --volumes-from=kontena-server-mongo-data \
56
- mongo:3.0 mongod --smallfiles
57
- <% end -%>
58
- - name: kontena-server-api.service
59
- command: start
60
- enable: true
61
- content: |
62
- [Unit]
63
- Description=kontena-server-api
64
- After=network-online.target
65
- After=docker.service
66
- After=kontena-server-mongo.service
67
- Description=Kontena Master
68
- Documentation=http://www.kontena.io/
69
- Before=kontena-server-haproxy.service
70
- Wants=kontena-server-haproxy.service
71
- Requires=network-online.target
72
- Requires=docker.service
73
- <% unless mongodb_uri -%>
74
- Requires=kontena-server-mongo.service
75
- <% end %>
76
-
77
- [Service]
78
- Restart=always
79
- RestartSec=5
80
- EnvironmentFile=/etc/kontena-server.env
81
- ExecStartPre=-/usr/bin/docker stop kontena-server-api
82
- ExecStartPre=-/usr/bin/docker rm kontena-server-api
83
- ExecStartPre=/usr/bin/docker pull kontena/server:${KONTENA_VERSION}
84
- ExecStart=/usr/bin/docker run --name kontena-server-api \
85
- <% if mongodb_uri -%>
86
- -e MONGODB_URI=<%= mongodb_uri %> \
87
- <% else -%>
88
- --link kontena-server-mongo:mongodb \
89
- -e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
90
- <% end -%>
91
- <% if auth_server %>
92
- -e AUTH_API_URL=<%= auth_server %> \
93
- <% end -%>
94
- -e VAULT_KEY=${KONTENA_VAULT_KEY} -e VAULT_IV=${KONTENA_VAULT_IV} \
95
- kontena/server:${KONTENA_VERSION}
96
-
97
- - name: kontena-server-haproxy.service
98
- command: start
99
- enable: true
100
- content: |
101
- [Unit]
102
- Description=kontena-server-haproxy
103
- After=network-online.target
104
- After=docker.service
105
- Description=Kontena Server HAProxy
106
- Documentation=http://www.kontena.io/
107
- Requires=network-online.target
108
- Requires=docker.service
109
- Requires=kontena-server-api.service
110
-
111
- [Service]
112
- Restart=always
113
- RestartSec=5
114
- EnvironmentFile=/etc/kontena-server.env
115
- ExecStartPre=-/usr/bin/docker stop kontena-server-haproxy
116
- ExecStartPre=-/usr/bin/docker rm kontena-server-haproxy
117
- ExecStartPre=/usr/bin/docker pull kontena/haproxy:latest
118
- ExecStart=/opt/bin/kontena-haproxy.sh
@@ -1,93 +0,0 @@
1
- require 'shell-spinner'
2
-
3
- module Kontena
4
- module Machine
5
- module Packet
6
- class MasterProvisioner
7
- include RandomName
8
- include Machine::CertHelper
9
- include PacketCommon
10
-
11
- attr_reader :client, :http_client
12
-
13
- # @param [String] token Packet token
14
- def initialize(token)
15
- @client = login(token)
16
- end
17
-
18
- def run!(opts)
19
- abort('Project does not exist in Packet') unless project = find_project(opts[:project])
20
- abort('Facility does not exist in Packet') unless facility = find_facility(opts[:facility])
21
- abort('Operating system coreos_stable does not exist in Packet') unless os = find_os('coreos_stable')
22
- abort('Device type does not exist in Packet') unless plan = find_plan(opts[:plan])
23
-
24
- check_or_create_ssh_key(File.expand_path(opts[:ssh_key])) if opts[:ssh_key]
25
-
26
- if opts[:ssl_cert]
27
- abort('Invalid ssl cert') unless File.exists?(File.expand_path(opts[:ssl_cert]))
28
- ssl_cert = File.read(File.expand_path(opts[:ssl_cert]))
29
- else
30
- ShellSpinner "Generating self-signed SSL certificate" do
31
- ssl_cert = generate_self_signed_cert
32
- end
33
- end
34
-
35
- userdata_vars = {
36
- ssl_cert: ssl_cert,
37
- auth_server: opts[:auth_server],
38
- version: opts[:version],
39
- vault_secret: opts[:vault_secret],
40
- vault_iv: opts[:vault_iv],
41
- mongodb_uri: opts[:mongodb_uri]
42
- }
43
-
44
- device = project.new_device(
45
- hostname: generate_name,
46
- facility: facility.to_hash,
47
- operating_system: os.to_hash,
48
- plan: plan.to_hash,
49
- billing_cycle: opts[:billing],
50
- locked: true,
51
- userdata: user_data(userdata_vars, 'cloudinit_master.yml')
52
- )
53
-
54
- ShellSpinner "Creating Packet device #{device.hostname.colorize(:cyan)} " do
55
- api_retry "Packet API reported an error, please try again" do
56
- response = client.create_device(device)
57
- raise response.body unless response.success?
58
- end
59
-
60
- until device && [:active, :provisioning, :powering_on].include?(device.state)
61
- device = find_device(project.id, device.hostname) rescue nil
62
- sleep 5
63
- end
64
- end
65
-
66
- public_ip = device_public_ip(device)
67
- master_url = "https://#{public_ip['address']}"
68
-
69
- Excon.defaults[:ssl_verify_peer] = false
70
- @http_client = Excon.new("#{master_url}", :connect_timeout => 10)
71
-
72
- ShellSpinner "Waiting for #{device.hostname.colorize(:cyan)} to start (estimate 4 minutes)" do
73
- sleep 5 until master_running?
74
- end
75
-
76
- puts "Kontena Master is now running at #{master_url}"
77
- puts "Use #{"kontena login --name=#{device.hostname.sub('kontena-master-', '')} #{master_url}".colorize(:light_black)} to complete Kontena Master setup"
78
- end
79
-
80
- def generate_name
81
- "kontena-master-#{super}-#{rand(1..9)}"
82
- end
83
-
84
- def master_running?
85
- http_client.get(path: '/').status == 200
86
- rescue
87
- false
88
- end
89
-
90
- end
91
- end
92
- end
93
- end