kontena-cli 0.8.4 → 0.9.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 +4 -0
- data/lib/kontena/cli/app_command.rb +2 -0
- data/lib/kontena/cli/apps/build_command.rb +26 -0
- data/lib/kontena/cli/apps/common.rb +41 -12
- data/lib/kontena/cli/apps/deploy_command.rb +31 -13
- data/lib/kontena/cli/apps/docker_helper.rb +34 -0
- data/lib/kontena/cli/apps/init_command.rb +130 -10
- data/lib/kontena/cli/apps/list_command.rb +4 -2
- data/lib/kontena/cli/apps/logs_command.rb +4 -2
- data/lib/kontena/cli/apps/remove_command.rb +4 -2
- data/lib/kontena/cli/apps/start_command.rb +4 -2
- data/lib/kontena/cli/apps/stop_command.rb +4 -2
- data/lib/kontena/cli/common.rb +3 -3
- data/lib/kontena/cli/container_command.rb +3 -0
- data/lib/kontena/cli/containers/inspect_command.rb +16 -0
- data/lib/kontena/cli/deploy_command.rb +3 -0
- data/lib/kontena/cli/etcd/get_command.rb +21 -0
- data/lib/kontena/cli/etcd/list_command.rb +26 -0
- data/lib/kontena/cli/etcd/mkdir_command.rb +17 -0
- data/lib/kontena/cli/etcd/remove_command.rb +21 -0
- data/lib/kontena/cli/etcd/set_command.rb +18 -0
- data/lib/kontena/cli/etcd_command.rb +17 -0
- data/lib/kontena/cli/grid_command.rb +2 -0
- data/lib/kontena/cli/grids/logs_command.rb +71 -0
- data/lib/kontena/cli/master/aws/create_command.rb +33 -0
- data/lib/kontena/cli/master/aws_command.rb +8 -0
- data/lib/kontena/cli/master/azure/create_command.rb +33 -0
- data/lib/kontena/cli/master/azure_command.rb +13 -0
- data/lib/kontena/cli/master/digital_ocean/create_command.rb +30 -0
- data/lib/kontena/cli/master/digital_ocean_command.rb +13 -0
- data/lib/kontena/cli/master/vagrant/create_command.rb +19 -0
- data/lib/kontena/cli/master/vagrant/restart_command.rb +20 -0
- data/lib/kontena/cli/master/vagrant/ssh_command.rb +15 -0
- data/lib/kontena/cli/master/vagrant/start_command.rb +20 -0
- data/lib/kontena/cli/master/vagrant/stop_command.rb +20 -0
- data/lib/kontena/cli/master/vagrant/terminate_command.rb +13 -0
- data/lib/kontena/cli/master/vagrant_command.rb +23 -0
- data/lib/kontena/cli/master_command.rb +15 -0
- data/lib/kontena/cli/node_command.rb +4 -0
- data/lib/kontena/cli/nodes/aws/create_command.rb +39 -0
- data/lib/kontena/cli/nodes/aws/restart_command.rb +28 -0
- data/lib/kontena/cli/nodes/aws/terminate_command.rb +20 -0
- data/lib/kontena/cli/nodes/aws_command.rb +15 -0
- data/lib/kontena/cli/nodes/azure/create_command.rb +39 -0
- data/lib/kontena/cli/nodes/azure/restart_command.rb +31 -0
- data/lib/kontena/cli/nodes/azure/terminate_command.rb +20 -0
- data/lib/kontena/cli/nodes/azure_command.rb +15 -0
- data/lib/kontena/cli/nodes/digital_ocean/create_command.rb +1 -1
- data/lib/kontena/cli/nodes/vagrant/create_command.rb +1 -1
- data/lib/kontena/cli/service_command.rb +4 -0
- data/lib/kontena/cli/services/add_env_command.rb +18 -0
- data/lib/kontena/cli/services/create_command.rb +8 -0
- data/lib/kontena/cli/services/remove_env_command.rb +17 -0
- data/lib/kontena/cli/services/services_helper.rb +20 -1
- data/lib/kontena/cli/services/update_command.rb +10 -0
- data/lib/kontena/client.rb +22 -1
- data/lib/kontena/machine/aws.rb +13 -0
- data/lib/kontena/machine/aws/cloudinit.yml +66 -0
- data/lib/kontena/machine/aws/cloudinit_master.yml +105 -0
- data/lib/kontena/machine/aws/master_provisioner.rb +161 -0
- data/lib/kontena/machine/aws/node_destroyer.rb +39 -0
- data/lib/kontena/machine/aws/node_provisioner.rb +168 -0
- data/lib/kontena/machine/azure.rb +13 -0
- data/lib/kontena/machine/azure/cloudinit.yml +59 -0
- data/lib/kontena/machine/azure/cloudinit_master.yml +105 -0
- data/lib/kontena/machine/azure/logger.rb +27 -0
- data/lib/kontena/machine/azure/master_provisioner.rb +126 -0
- data/lib/kontena/machine/azure/node_destroyer.rb +53 -0
- data/lib/kontena/machine/azure/node_provisioner.rb +128 -0
- data/lib/kontena/machine/digital_ocean.rb +1 -0
- data/lib/kontena/machine/digital_ocean/cloudinit.yml +1 -0
- data/lib/kontena/machine/digital_ocean/cloudinit_master.yml +105 -0
- data/lib/kontena/machine/digital_ocean/master_provisioner.rb +94 -0
- data/lib/kontena/machine/digital_ocean/node_provisioner.rb +8 -1
- data/lib/kontena/machine/vagrant.rb +2 -0
- data/lib/kontena/machine/vagrant/Vagrantfile.master.rb.erb +101 -0
- data/lib/kontena/machine/vagrant/{Vagrantfile.coreos.rb.erb → Vagrantfile.node.rb.erb} +0 -0
- data/lib/kontena/machine/vagrant/cloudinit.yml +2 -1
- data/lib/kontena/machine/vagrant/master_destroyer.rb +37 -0
- data/lib/kontena/machine/vagrant/master_provisioner.rb +75 -0
- data/lib/kontena/machine/vagrant/node_destroyer.rb +4 -0
- data/lib/kontena/machine/vagrant/node_provisioner.rb +1 -1
- data/lib/kontena/scripts/completer +29 -3
- data/spec/kontena/cli/app/common_spec.rb +61 -0
- data/spec/kontena/cli/app/deploy_command_spec.rb +25 -6
- data/spec/kontena/cli/app/docker_helper_spec.rb +32 -0
- data/spec/kontena/cli/common_spec.rb +53 -0
- metadata +61 -3
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'shell-spinner'
|
2
|
+
require 'azure/virtual_machine_image_management/virtual_machine_image_management_service'
|
3
|
+
|
4
|
+
module Kontena
|
5
|
+
module Machine
|
6
|
+
module Azure
|
7
|
+
class NodeDestroyer
|
8
|
+
|
9
|
+
attr_reader :client, :api_client
|
10
|
+
|
11
|
+
# @param [Kontena::Client] api_client Kontena api client
|
12
|
+
# @param [String] subscription_id Azure subscription id
|
13
|
+
# @param [String] certificate Path to Azure management certificate
|
14
|
+
def initialize(api_client, subscription_id, certificate)
|
15
|
+
@api_client = api_client
|
16
|
+
abort('Invalid management certificate') unless File.exists?(File.expand_path(certificate))
|
17
|
+
|
18
|
+
@client = ::Azure
|
19
|
+
client.management_certificate = certificate
|
20
|
+
client.subscription_id = subscription_id
|
21
|
+
client.vm_management.initialize_external_logger(Logger.new) # We don't want all the output
|
22
|
+
end
|
23
|
+
|
24
|
+
def run!(grid, name)
|
25
|
+
ShellSpinner "Terminating Azure Virtual Machine #{name.colorize(:cyan)} " do
|
26
|
+
vm = client.vm_management.get_virtual_machine(name, cloud_service_name(name, grid['name']))
|
27
|
+
if vm
|
28
|
+
out = StringIO.new
|
29
|
+
$stdout = out # to avoid debug data (https://github.com/Azure/azure-sdk-for-ruby/issues/200)
|
30
|
+
client.vm_management.delete_virtual_machine(name, cloud_service_name(name, grid['name']))
|
31
|
+
storage_account = client.storage_management.list_storage_accounts.find{|a| a.label == cloud_service_name(name, grid['name'])}
|
32
|
+
client.storage_management.delete_storage_account(storage_account.name) if storage_account
|
33
|
+
$stdout = STDOUT
|
34
|
+
else
|
35
|
+
abort "\nCannot find Virtual Machine #{name.colorize(:cyan)} in Azure"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name}
|
40
|
+
if node
|
41
|
+
ShellSpinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do
|
42
|
+
api_client.delete("grids/#{grid['id']}/nodes/#{name}")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def cloud_service_name(vm_name, grid)
|
48
|
+
"kontena-#{grid}-#{vm_name}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'erb'
|
3
|
+
require 'open3'
|
4
|
+
require 'base64'
|
5
|
+
require 'shell-spinner'
|
6
|
+
|
7
|
+
module Kontena
|
8
|
+
module Machine
|
9
|
+
module Azure
|
10
|
+
class NodeProvisioner
|
11
|
+
include RandomName
|
12
|
+
|
13
|
+
attr_reader :client, :api_client
|
14
|
+
|
15
|
+
# @param [Kontena::Client] api_client Kontena api client
|
16
|
+
# @param [String] subscription_id Azure subscription id
|
17
|
+
# @param [String] certificate Path to Azure management certificate
|
18
|
+
def initialize(api_client, subscription_id, certificate)
|
19
|
+
@api_client = api_client
|
20
|
+
abort('Invalid management certificate') unless File.exists?(File.expand_path(certificate))
|
21
|
+
|
22
|
+
@client = ::Azure
|
23
|
+
client.management_certificate = certificate
|
24
|
+
client.subscription_id = subscription_id
|
25
|
+
client.vm_management.initialize_external_logger(Logger.new) # We don't want all the output
|
26
|
+
end
|
27
|
+
|
28
|
+
def run!(opts)
|
29
|
+
abort('Invalid ssh key') unless File.exists?(File.expand_path(opts[:ssh_key]))
|
30
|
+
node = nil
|
31
|
+
vm_name = opts[:name] || generate_name
|
32
|
+
cloud_service_name = generate_cloud_service_name(vm_name, opts[:grid])
|
33
|
+
|
34
|
+
ShellSpinner "Creating Azure Virtual Machine #{vm_name.colorize(:cyan)}" do
|
35
|
+
if opts[:virtual_network].nil?
|
36
|
+
location = opts[:location].downcase.gsub(' ', '-')
|
37
|
+
default_network_name = "kontena-#{location}"
|
38
|
+
create_virtual_network(default_network_name, opts[:location]) unless virtual_network_exist?(default_network_name)
|
39
|
+
opts[:virtual_network] = default_network_name
|
40
|
+
opts[:subnet] = 'subnet-1'
|
41
|
+
end
|
42
|
+
|
43
|
+
userdata_vars = {
|
44
|
+
version: opts[:version],
|
45
|
+
master_uri: opts[:master_uri],
|
46
|
+
grid_token: opts[:grid_token],
|
47
|
+
}
|
48
|
+
|
49
|
+
params = {
|
50
|
+
vm_name: vm_name,
|
51
|
+
vm_user: 'core',
|
52
|
+
location: opts[:location],
|
53
|
+
image: '2b171e93f07c4903bcad35bda10acf22__CoreOS-Stable-766.3.0',
|
54
|
+
custom_data: Base64.encode64(user_data(userdata_vars)),
|
55
|
+
ssh_key: opts[:ssh_key]
|
56
|
+
}
|
57
|
+
options = {
|
58
|
+
cloud_service_name: cloud_service_name,
|
59
|
+
deployment_name: vm_name,
|
60
|
+
virtual_network_name: opts[:virtual_network],
|
61
|
+
subnet_name: opts[:subnet],
|
62
|
+
tcp_endpoints: '80',
|
63
|
+
private_key_file: opts[:ssh_key],
|
64
|
+
ssh_port: 22,
|
65
|
+
vm_size: opts[:size],
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
client.vm_management.create_virtual_machine(params,options)
|
70
|
+
end
|
71
|
+
ShellSpinner "Waiting for node #{vm_name.colorize(:cyan)} join to grid #{opts[:grid].colorize(:cyan)} " do
|
72
|
+
sleep 2 until node = vm_exists_in_grid?(opts[:grid], vm_name)
|
73
|
+
end
|
74
|
+
if node
|
75
|
+
labels = ["region=#{cloud_service(cloud_service_name).location}"]
|
76
|
+
set_labels(node, labels)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def user_data(vars)
|
81
|
+
cloudinit_template = File.join(__dir__ , '/cloudinit.yml')
|
82
|
+
erb(File.read(cloudinit_template), vars)
|
83
|
+
end
|
84
|
+
|
85
|
+
def generate_name
|
86
|
+
"#{super}-#{rand(1..99)}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def generate_cloud_service_name(name, grid)
|
90
|
+
"kontena-#{grid}-#{name}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def vm_exists_in_grid?(grid, name)
|
94
|
+
api_client.get("grids/#{grid}/nodes")['nodes'].find{|n| n['name'] == name}
|
95
|
+
end
|
96
|
+
|
97
|
+
def erb(template, vars)
|
98
|
+
ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
|
99
|
+
end
|
100
|
+
|
101
|
+
def cloud_service_exist?(name)
|
102
|
+
cloud_service(name)
|
103
|
+
end
|
104
|
+
|
105
|
+
def cloud_service(name)
|
106
|
+
client.cloud_service_management.get_cloud_service(name)
|
107
|
+
end
|
108
|
+
|
109
|
+
def virtual_network_exist?(name)
|
110
|
+
client.network_management.list_virtual_networks.find{|n| n.name == name}
|
111
|
+
end
|
112
|
+
|
113
|
+
def create_virtual_network(name, location)
|
114
|
+
address_space = ['10.0.0.0/20']
|
115
|
+
options = {subnet: [{:name => 'subnet-1', :ip_address=>'10.0.0.0', :cidr=>23}]}
|
116
|
+
client.network_management.set_network_configuration(name, location, address_space, options)
|
117
|
+
end
|
118
|
+
|
119
|
+
def set_labels(node, labels)
|
120
|
+
data = {}
|
121
|
+
data[:labels] = labels
|
122
|
+
api_client.put("nodes/#{node['id']}", data, {}, {'Kontena-Grid-Token' => node['grid']['token']})
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,105 @@
|
|
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
|
+
<% if ssl_cert %>SSL_CERT="/etc/kontena-server.pem"
|
9
|
+
|
10
|
+
- path: /etc/kontena-server.pem
|
11
|
+
permissions: 0600
|
12
|
+
owner: root
|
13
|
+
content: | <% ssl_cert.split(/\n/).each do |row| %>
|
14
|
+
<%= row %><% end %><% end %>
|
15
|
+
- path: /opt/bin/kontena-haproxy.sh
|
16
|
+
permissions: 0755
|
17
|
+
owner: root
|
18
|
+
content: |
|
19
|
+
#!/bin/sh
|
20
|
+
if [ -n "$SSL_CERT" ]; then
|
21
|
+
SSL_CERT=$(awk 1 ORS='\\n' $SSL_CERT)
|
22
|
+
else
|
23
|
+
SSL_CERT="**None**"
|
24
|
+
fi
|
25
|
+
/usr/bin/docker run --name=kontena-server-haproxy \
|
26
|
+
--link kontena-server-api:kontena-server-api \
|
27
|
+
-e SSL_CERT="$SSL_CERT" -e BACKEND_PORT=9292 \
|
28
|
+
-p 80:80 -p 443:443 kontena/haproxy:latest
|
29
|
+
coreos:
|
30
|
+
update:
|
31
|
+
reboot-strategy: off
|
32
|
+
units:
|
33
|
+
- name: kontena-server-mongo.service
|
34
|
+
command: start
|
35
|
+
enable: true
|
36
|
+
content: |
|
37
|
+
[Unit]
|
38
|
+
Description=kontena-server-mongo
|
39
|
+
After=network-online.target
|
40
|
+
After=docker.service
|
41
|
+
Description=Kontena Server MongoDB
|
42
|
+
Documentation=http://www.mongodb.org/
|
43
|
+
Requires=network-online.target
|
44
|
+
Requires=docker.service
|
45
|
+
|
46
|
+
[Service]
|
47
|
+
Restart=always
|
48
|
+
RestartSec=5
|
49
|
+
ExecStartPre=/usr/bin/docker pull mongo:3.0
|
50
|
+
ExecStartPre=-/usr/bin/docker create --name=kontena-server-mongo-data mongo:3.0
|
51
|
+
ExecStartPre=-/usr/bin/docker stop kontena-server-mongo
|
52
|
+
ExecStartPre=-/usr/bin/docker rm kontena-server-mongo
|
53
|
+
ExecStart=/usr/bin/docker run --name=kontena-server-mongo \
|
54
|
+
--volumes-from=kontena-server-mongo-data \
|
55
|
+
mongo:3.0 mongod --smallfiles
|
56
|
+
|
57
|
+
- name: kontena-server-api.service
|
58
|
+
command: start
|
59
|
+
enable: true
|
60
|
+
content: |
|
61
|
+
[Unit]
|
62
|
+
Description=kontena-server-api
|
63
|
+
After=network-online.target
|
64
|
+
After=docker.service
|
65
|
+
After=kontena-server-mongo.service
|
66
|
+
Description=Kontena Master
|
67
|
+
Documentation=http://www.kontena.io/
|
68
|
+
Requires=network-online.target
|
69
|
+
Requires=docker.service
|
70
|
+
Requires=kontena-server-mongo.service
|
71
|
+
|
72
|
+
[Service]
|
73
|
+
Restart=always
|
74
|
+
RestartSec=5
|
75
|
+
EnvironmentFile=/etc/kontena-server.env
|
76
|
+
ExecStartPre=-/usr/bin/docker stop kontena-server-api
|
77
|
+
ExecStartPre=-/usr/bin/docker rm kontena-server-api
|
78
|
+
ExecStartPre=/usr/bin/docker pull kontena/server:${KONTENA_VERSION}
|
79
|
+
ExecStart=/usr/bin/docker run --name kontena-server-api \
|
80
|
+
--link kontena-server-mongo:mongodb \
|
81
|
+
-e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
|
82
|
+
<% if auth_server %>-e AUTH_API_URL=<%= auth_server %><% end %> \
|
83
|
+
kontena/server:${KONTENA_VERSION}
|
84
|
+
|
85
|
+
- name: kontena-server-haproxy.service
|
86
|
+
command: start
|
87
|
+
enable: true
|
88
|
+
content: |
|
89
|
+
[Unit]
|
90
|
+
Description=kontena-server-haproxy
|
91
|
+
After=network-online.target
|
92
|
+
After=docker.service
|
93
|
+
Description=Kontena Server HAProxy
|
94
|
+
Documentation=http://www.kontena.io/
|
95
|
+
Requires=network-online.target
|
96
|
+
Requires=docker.service
|
97
|
+
|
98
|
+
[Service]
|
99
|
+
Restart=always
|
100
|
+
RestartSec=5
|
101
|
+
EnvironmentFile=/etc/kontena-server.env
|
102
|
+
ExecStartPre=-/usr/bin/docker stop kontena-server-haproxy
|
103
|
+
ExecStartPre=-/usr/bin/docker rm kontena-server-haproxy
|
104
|
+
ExecStartPre=/usr/bin/docker pull kontena/haproxy:latest
|
105
|
+
ExecStart=/opt/bin/kontena-haproxy.sh
|
@@ -0,0 +1,94 @@
|
|
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
|
+
|
12
|
+
attr_reader :client, :http_client
|
13
|
+
|
14
|
+
# @param [String] token Digital Ocean token
|
15
|
+
def initialize(token)
|
16
|
+
@client = DropletKit::Client.new(access_token: token)
|
17
|
+
end
|
18
|
+
|
19
|
+
def run!(opts)
|
20
|
+
abort('Invalid ssh key') unless File.exists?(File.expand_path(opts[:ssh_key]))
|
21
|
+
|
22
|
+
ssh_key = ssh_key(File.read(File.expand_path(opts[:ssh_key])).strip)
|
23
|
+
abort('Ssh key does not exist in Digital Ocean') unless ssh_key
|
24
|
+
|
25
|
+
if opts[:ssl_cert]
|
26
|
+
abort('Invalid ssl cert') unless File.exists?(File.expand_path(opts[:ssl_cert]))
|
27
|
+
ssl_cert = File.read(File.expand_path(opts[:ssl_cert]))
|
28
|
+
end
|
29
|
+
|
30
|
+
userdata_vars = {
|
31
|
+
ssl_cert: ssl_cert,
|
32
|
+
auth_server: opts[:auth_server],
|
33
|
+
version: opts[:version]
|
34
|
+
}
|
35
|
+
|
36
|
+
droplet = DropletKit::Droplet.new(
|
37
|
+
name: generate_name,
|
38
|
+
region: opts[:region],
|
39
|
+
image: 'coreos-stable',
|
40
|
+
size: opts[:size],
|
41
|
+
private_networking: true,
|
42
|
+
user_data: user_data(userdata_vars),
|
43
|
+
ssh_keys: [ssh_key.id]
|
44
|
+
)
|
45
|
+
|
46
|
+
ShellSpinner "Creating DigitalOcean droplet #{droplet.name.colorize(:cyan)} " do
|
47
|
+
droplet = client.droplets.create(droplet)
|
48
|
+
until droplet.status == 'active'
|
49
|
+
droplet = client.droplets.find(id: droplet.id)
|
50
|
+
sleep 5
|
51
|
+
end
|
52
|
+
end
|
53
|
+
if opts[:ssl_cert]
|
54
|
+
master_url = "https://#{droplet.public_ip}"
|
55
|
+
else
|
56
|
+
master_url = "http://#{droplet.public_ip}"
|
57
|
+
end
|
58
|
+
Excon.defaults[:ssl_verify_peer] = false
|
59
|
+
@http_client = Excon.new("#{master_url}", :connect_timeout => 10)
|
60
|
+
|
61
|
+
ShellSpinner "Waiting for #{droplet.name.colorize(:cyan)} to start" do
|
62
|
+
sleep 5 until master_running?
|
63
|
+
end
|
64
|
+
|
65
|
+
puts "Kontena Master is now running at #{master_url}"
|
66
|
+
puts "Use #{"kontena login #{master_url}".colorize(:light_black)} to complete Kontena Master setup"
|
67
|
+
end
|
68
|
+
|
69
|
+
def user_data(vars)
|
70
|
+
cloudinit_template = File.join(__dir__ , '/cloudinit_master.yml')
|
71
|
+
erb(File.read(cloudinit_template), vars)
|
72
|
+
end
|
73
|
+
|
74
|
+
def generate_name
|
75
|
+
"kontena-master-#{super}-#{rand(1..99)}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def ssh_key(public_key)
|
79
|
+
ssh_key = client.ssh_keys.all.find{|key| key.public_key == public_key}
|
80
|
+
end
|
81
|
+
|
82
|
+
def master_running?
|
83
|
+
http_client.get(path: '/').status == 200
|
84
|
+
rescue
|
85
|
+
false
|
86
|
+
end
|
87
|
+
|
88
|
+
def erb(template, vars)
|
89
|
+
ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -43,9 +43,11 @@ module Kontena
|
|
43
43
|
ShellSpinner "Creating DigitalOcean droplet #{droplet.name.colorize(:cyan)} " do
|
44
44
|
sleep 5 until client.droplets.find(id: created.id).status == 'active'
|
45
45
|
end
|
46
|
+
node = nil
|
46
47
|
ShellSpinner "Waiting for node #{droplet.name.colorize(:cyan)} join to grid #{opts[:grid].colorize(:cyan)} " do
|
47
|
-
sleep 2 until droplet_exists_in_grid?(opts[:grid], droplet)
|
48
|
+
sleep 2 until node = droplet_exists_in_grid?(opts[:grid], droplet)
|
48
49
|
end
|
50
|
+
set_labels(node, ["region=#{opts[:region]}"])
|
49
51
|
end
|
50
52
|
|
51
53
|
def user_data(vars)
|
@@ -68,6 +70,11 @@ module Kontena
|
|
68
70
|
def erb(template, vars)
|
69
71
|
ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
|
70
72
|
end
|
73
|
+
|
74
|
+
def set_labels(node, labels)
|
75
|
+
data = {labels: labels}
|
76
|
+
api_client.put("nodes/#{node['id']}", data, {}, {'Kontena-Grid-Token' => node['grid']['token']})
|
77
|
+
end
|
71
78
|
end
|
72
79
|
end
|
73
80
|
end
|
@@ -0,0 +1,101 @@
|
|
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
|
+
coreos:
|
16
|
+
update:
|
17
|
+
reboot-strategy: off
|
18
|
+
units:
|
19
|
+
- name: kontena-server-mongo.service
|
20
|
+
command: start
|
21
|
+
enable: true
|
22
|
+
content: |
|
23
|
+
[Unit]
|
24
|
+
Description=kontena-server-mongo
|
25
|
+
After=network-online.target
|
26
|
+
After=docker.service
|
27
|
+
Description=Kontena Server MongoDB
|
28
|
+
Documentation=http://www.mongodb.org/
|
29
|
+
Requires=network-online.target
|
30
|
+
Requires=docker.service
|
31
|
+
|
32
|
+
[Service]
|
33
|
+
Restart=always
|
34
|
+
RestartSec=5
|
35
|
+
ExecStartPre=/usr/bin/docker pull mongo:3.0
|
36
|
+
ExecStartPre=-/usr/bin/docker create --name=kontena-server-mongo-data mongo:3.0
|
37
|
+
ExecStartPre=-/usr/bin/docker stop kontena-server-mongo
|
38
|
+
ExecStartPre=-/usr/bin/docker rm kontena-server-mongo
|
39
|
+
ExecStart=/usr/bin/docker run --name=kontena-server-mongo \
|
40
|
+
--volumes-from=kontena-server-mongo-data \
|
41
|
+
mongo:3.0 mongod --smallfiles
|
42
|
+
|
43
|
+
- name: kontena-server-api.service
|
44
|
+
command: start
|
45
|
+
enable: true
|
46
|
+
content: |
|
47
|
+
[Unit]
|
48
|
+
Description=kontena-server-api
|
49
|
+
After=network-online.target
|
50
|
+
After=docker.service
|
51
|
+
After=kontena-server-mongo.service
|
52
|
+
Description=Kontena Master
|
53
|
+
Documentation=http://www.kontena.io/
|
54
|
+
Requires=network-online.target
|
55
|
+
Requires=docker.service
|
56
|
+
Requires=kontena-server-mongo.service
|
57
|
+
|
58
|
+
[Service]
|
59
|
+
Restart=always
|
60
|
+
RestartSec=5
|
61
|
+
EnvironmentFile=/etc/kontena-server.env
|
62
|
+
ExecStartPre=-/usr/bin/docker stop kontena-server-api
|
63
|
+
ExecStartPre=-/usr/bin/docker rm kontena-server-api
|
64
|
+
ExecStartPre=/usr/bin/docker pull kontena/server:${KONTENA_VERSION}
|
65
|
+
ExecStart=/usr/bin/docker run --name kontena-server-api \
|
66
|
+
--link kontena-server-mongo:mongodb \
|
67
|
+
-e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
|
68
|
+
<% if auth_server %>-e AUTH_API_URL=<%= auth_server %><% end %> \
|
69
|
+
-p 8080:9292 \
|
70
|
+
kontena/server:${KONTENA_VERSION}
|
71
|
+
INIT
|
72
|
+
|
73
|
+
cloud_init_file = Tempfile.new('kontena-master')
|
74
|
+
File.write(cloud_init_file.path, cloud_init)
|
75
|
+
|
76
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
77
|
+
config.vm.provider :virtualbox do |v|
|
78
|
+
v.check_guest_additions = false
|
79
|
+
v.functional_vboxsf = false
|
80
|
+
end
|
81
|
+
|
82
|
+
if Vagrant.has_plugin?("vagrant-vbguest") then
|
83
|
+
config.vbguest.auto_update = false
|
84
|
+
end
|
85
|
+
|
86
|
+
config.vm.define "<%= name %>" do |docker|
|
87
|
+
docker.vm.box = "coreos-stable"
|
88
|
+
docker.vm.box_url = "http://stable.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json"
|
89
|
+
docker.vm.network "private_network", ip: "192.168.66.100"
|
90
|
+
docker.vm.hostname = "<%= name %>"
|
91
|
+
docker.vm.provider "virtualbox" do |vb|
|
92
|
+
vb.gui = false
|
93
|
+
vb.customize ["modifyvm", :id, "--memory", "512"]
|
94
|
+
vb.auto_nat_dns_proxy = false
|
95
|
+
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off" ]
|
96
|
+
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off" ]
|
97
|
+
end
|
98
|
+
docker.vm.provision :file, :source => cloud_init_file.path, :destination => "/tmp/vagrantfile-user-data"
|
99
|
+
docker.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
|
100
|
+
end
|
101
|
+
end
|