kontena-plugin-vagrant 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcd348640f57159a47b8b61eaba11b8d1d2af24c
4
- data.tar.gz: 03896a2c82123071a11ca65ade785bafb725929b
3
+ metadata.gz: f0dbdc24762c8928c570ff0545c4ba1ebc8d6690
4
+ data.tar.gz: 51cc5042201b2b9bc3094c79b2837426358c99ac
5
5
  SHA512:
6
- metadata.gz: ecdea869808825ee3292875882196a9152efcfff2b3bf18c653476aac6f162b5f2d67847471b3d90b703958b96abba1e4fb00f742263ec937753631dc5d3cb7d
7
- data.tar.gz: 43d4071b71ca6620213c86b09d436de5e31bc84a156a0fdb1ead7e041d44b675b38dbc2df01b8bfe45d365227055314de16c7089c3c9474b379d3cff2165022f
6
+ metadata.gz: d87836d142bfe4d4f8119cbdc5020db8443931b601a76319fffa2d79ec65cfaf6018fe32965a7fe5425b66cefc6d4921af5299f256aa119716b95788a73a0639
7
+ data.tar.gz: 96407999132af74c0d7c1834deac6a82f5326b6c5c110f5fd49ef4bce0d57ee1a9444c14f806d064f9511d42bd378023bd97d3cd88a5a33c1d0271084b3914ea
data/CHANGELOG.md CHANGED
@@ -1,10 +1,22 @@
1
1
  # Changelog
2
2
 
3
- # 0.1.2 (2016-08-31)
3
+ ## 0.3.0 (2017-07-13)
4
+
5
+ - allow node IPs to be specified (#42)
6
+ - fix & improve cloudinits (#45, #40)
7
+ - remove vagrant from gemfile (#44)
8
+ - improve error handling and output (#41, #7, #25)
9
+
10
+ ## 0.2.7 (2017-05-03)
11
+
12
+ - fix vagrant master create --name (#37)
13
+ - sync travis.yml ruby versions with CLI and only deploy on 2.4.1 (#39)
14
+
15
+ ## 0.1.2 (2016-08-31)
4
16
 
5
17
  - add provider labeling for nodes (#4)
6
18
  - add ExecStop to systemd units (#2)
7
19
 
8
- # 0.1.1 (2016-08-10)
20
+ ## 0.1.1 (2016-08-10)
9
21
 
10
22
  - first release as a plugin
data/Gemfile CHANGED
@@ -4,7 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development do
7
- gem "listen", "~> 3.0.8"
8
7
  gem "rspec"
9
- gem "vagrant", git: "https://github.com/mitchellh/vagrant.git", tag: "v1.8.4"
10
8
  end
@@ -34,13 +34,16 @@ coreos:
34
34
  [Service]
35
35
  Restart=always
36
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
37
+ TimeoutStartSec=0
38
+ ExecStartPre=/usr/bin/docker pull mongo:3.2
39
+ ExecStartPre=-/usr/bin/docker network create kontena
40
+ ExecStartPre=-/usr/bin/docker volume create kontena-server-mongo
39
41
  ExecStartPre=-/usr/bin/docker stop kontena-server-mongo
40
42
  ExecStartPre=-/usr/bin/docker rm kontena-server-mongo
41
43
  ExecStart=/usr/bin/docker run --name=kontena-server-mongo \
42
- --volumes-from=kontena-server-mongo-data \
43
- mongo:3.0 mongod --smallfiles
44
+ -v kontena-server-mongo:/data/db \
45
+ --network kontena \
46
+ mongo:3.2
44
47
  ExecStop=/usr/bin/docker stop kontena-server-mongo
45
48
 
46
49
  - name: kontena-server-api.service
@@ -61,16 +64,18 @@ coreos:
61
64
  [Service]
62
65
  Restart=always
63
66
  RestartSec=5
67
+ TimeoutStartSec=0
64
68
  EnvironmentFile=/etc/kontena-server.env
65
69
  ExecStartPre=-/usr/bin/docker stop kontena-server-api
66
70
  ExecStartPre=-/usr/bin/docker rm kontena-server-api
71
+ ExecStartPre=-/usr/bin/docker network create kontena
67
72
  ExecStartPre=/usr/bin/docker pull kontena/server:${KONTENA_VERSION}
68
73
  ExecStart=/usr/bin/docker run --name kontena-server-api \
69
- --link kontena-server-mongo:mongodb \
70
- -e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
74
+ -e MONGODB_URI=mongodb://kontena-server-mongo:27017/kontena_server \
71
75
  -e VAULT_KEY=${KONTENA_VAULT_KEY} -e VAULT_IV=${KONTENA_VAULT_IV} \
72
76
  <% if server_name %>-e SERVER_NAME=<%= server_name %><% end %> \
73
77
  <% if initial_admin_code %>-e INITIAL_ADMIN_CODE=<%= initial_admin_code %><% end %> \
78
+ --network kontena \
74
79
  -p 8080:9292 \
75
80
  kontena/server:${KONTENA_VERSION}
76
81
  ExecStop=/usr/bin/docker stop kontena-server-api
@@ -17,7 +17,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
17
17
  config.vm.define "<%= name %>" do |docker|
18
18
  docker.vm.box = "coreos-<%= coreos_channel %>"
19
19
  docker.vm.box_url = "http://stable.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json"
20
+ <% if network_address == "dhcp" %>
20
21
  docker.vm.network "private_network", type: "dhcp"
22
+ <% else %>
23
+ docker.vm.network "private_network", ip: "<%= network_address %>"
24
+ <% end %>
21
25
  docker.vm.hostname = "<%= name %>"
22
26
  docker.vm.provider "virtualbox" do |vb|
23
27
  vb.name = "<%= name %>"
@@ -11,7 +11,7 @@ write_files:
11
11
  - path: /etc/systemd/system/docker.service.d/50-kontena.conf
12
12
  content: |
13
13
  [Service]
14
- Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/16" --bip="172.17.43.1/16"'
14
+ Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/16" --bip="172.17.43.1/16" -s overlay2'
15
15
  Environment='DOCKER_CGROUPS=--exec-opt native.cgroupdriver=cgroupfs'
16
16
  - path: /etc/sysctl.d/99-inotify.conf
17
17
  owner: root
@@ -78,6 +78,7 @@ coreos:
78
78
  [Service]
79
79
  Restart=always
80
80
  RestartSec=5
81
+ TimeoutStartSec=0
81
82
  EnvironmentFile=/etc/kontena-agent.env
82
83
  ExecStartPre=-/usr/bin/docker stop kontena-agent
83
84
  ExecStartPre=-/usr/bin/docker rm kontena-agent
@@ -0,0 +1,21 @@
1
+ require 'fileutils'
2
+ require 'erb'
3
+ require 'open3'
4
+ require 'json'
5
+
6
+ module Kontena
7
+ module Machine
8
+ module Vagrant
9
+ module Common
10
+
11
+ def erb(template, vars)
12
+ ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
13
+ end
14
+
15
+ def run_command(cmd)
16
+ exit $?.exitstatus unless system(cmd)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,25 +1,18 @@
1
- require 'fileutils'
1
+ require_relative 'common'
2
2
 
3
3
  module Kontena
4
4
  module Machine
5
5
  module Vagrant
6
6
  class MasterDestroyer
7
-
7
+ include Kontena::Machine::Vagrant::Common
8
8
  include Kontena::Cli::ShellSpinner
9
9
 
10
10
  def run!
11
11
  vagrant_path = "#{Dir.home}/.kontena/vagrant_master"
12
12
  Dir.chdir(vagrant_path) do
13
- spinner "Terminating Kontena Master from Vagrant " do
14
- Open3.popen2('vagrant destroy -f') do |stdin, output, wait|
15
- while o = output.gets
16
- puts o if ENV['DEBUG']
17
- end
18
- if wait.value == 0
19
- FileUtils.remove_entry_secure(vagrant_path)
20
- end
21
- end
22
- end
13
+ spinner "Triggering termination of Kontena Master from Vagrant"
14
+ run_command('vagrant destroy -f')
15
+ FileUtils.remove_entry_secure(vagrant_path)
23
16
  end
24
17
  end
25
18
  end
@@ -1,7 +1,4 @@
1
- require 'fileutils'
2
- require 'erb'
3
- require 'open3'
4
- require 'json'
1
+ require_relative 'common'
5
2
 
6
3
  module Kontena
7
4
  module Machine
@@ -9,6 +6,7 @@ module Kontena
9
6
  class MasterProvisioner
10
7
  include RandomName
11
8
  include Kontena::Machine::Common
9
+ include Kontena::Machine::Vagrant::Common
12
10
  include Kontena::Cli::Common
13
11
  include Kontena::Cli::ShellSpinner
14
12
 
@@ -48,18 +46,19 @@ module Kontena
48
46
  coreos_channel: coreos_channel,
49
47
  cloudinit: "#{vagrant_path}/cloudinit.yml"
50
48
  }
51
- vagrant_data = erb(File.read(template), vars)
52
- cloudinit = erb(File.read(cloudinit_template), vars)
53
- File.write("#{vagrant_path}/Vagrantfile", vagrant_data)
54
- File.write("#{vagrant_path}/cloudinit.yml", cloudinit)
49
+ spinner "Creating Vagrant config " do
50
+ vagrant_data = erb(File.read(template), vars)
51
+ cloudinit = erb(File.read(cloudinit_template), vars)
52
+ File.write("#{vagrant_path}/Vagrantfile", vagrant_data)
53
+ File.write("#{vagrant_path}/cloudinit.yml", cloudinit)
54
+ end
55
+
55
56
  Dir.chdir(vagrant_path) do
56
- spinner "Creating Vagrant machine #{name.colorize(:cyan)} " do
57
- Open3.popen2("vagrant up") do |stdin, output, wait|
58
- while o = output.gets
59
- print o if ENV['DEBUG']
60
- end
61
- end
62
- end
57
+ spinner "Triggering CoreOS Container Linux box update"
58
+ run_command('vagrant box update')
59
+ spinner "Executing 'vagrant up'"
60
+ run_command('vagrant up')
61
+ spinner "'vagrant up' executed successfully"
63
62
  end
64
63
 
65
64
  spinner "Waiting for #{name.colorize(:cyan)} to start " do
@@ -67,7 +66,7 @@ module Kontena
67
66
  end
68
67
 
69
68
  master_version = nil
70
- spinner "Retrieving Kontena Master version" do
69
+ spinner "Retrieving #{name.colorize(:cyan)} version" do
71
70
  master_version = JSON.parse(client.get(path: '/'))["version"] rescue nil
72
71
  end
73
72
 
@@ -82,10 +81,6 @@ module Kontena
82
81
  }
83
82
  end
84
83
 
85
- def erb(template, vars)
86
- ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
87
- end
88
-
89
84
  def master_running?
90
85
  client.get(path: '/').status == 200
91
86
  rescue
@@ -1,10 +1,11 @@
1
- require 'fileutils'
1
+ require_relative 'common'
2
2
 
3
3
  module Kontena
4
4
  module Machine
5
5
  module Vagrant
6
6
  class NodeDestroyer
7
7
  include RandomName
8
+ include Kontena::Machine::Vagrant::Common
8
9
  include Kontena::Cli::ShellSpinner
9
10
 
10
11
  attr_reader :client, :api_client
@@ -17,16 +18,9 @@ module Kontena
17
18
  def run!(grid, name)
18
19
  vagrant_path = "#{Dir.home}/.kontena/#{grid}/#{name}"
19
20
  Dir.chdir(vagrant_path) do
20
- spinner "Terminating Vagrant machine #{name.colorize(:cyan)} " do
21
- Open3.popen2('vagrant destroy -f') do |stdin, output, wait|
22
- while o = output.gets
23
- puts o if ENV['DEBUG']
24
- end
25
- if wait.value == 0
26
- FileUtils.remove_entry_secure(vagrant_path)
27
- end
28
- end
29
- end
21
+ spinner "Triggering termination of Vagrant machine #{name.colorize(:cyan)}"
22
+ run_command('vagrant destroy -f')
23
+ FileUtils.remove_entry_secure(vagrant_path)
30
24
  end
31
25
  node = api_client.get("grids/#{grid}/nodes")['nodes'].find{|n| n['name'] == name}
32
26
  if node
@@ -1,12 +1,10 @@
1
- require 'fileutils'
2
- require 'erb'
3
- require 'open3'
4
-
1
+ require_relative 'common'
5
2
  module Kontena
6
3
  module Machine
7
4
  module Vagrant
8
5
  class NodeProvisioner
9
6
  include RandomName
7
+ include Kontena::Machine::Vagrant::Common
10
8
  include Kontena::Cli::ShellSpinner
11
9
 
12
10
  attr_reader :client, :api_client
@@ -33,24 +31,26 @@ module Kontena
33
31
  name: name,
34
32
  version: version,
35
33
  memory: opts[:memory] || 1024,
34
+ network_address: opts[:network_address],
36
35
  master_uri: opts[:master_uri],
37
36
  grid_token: opts[:grid_token],
38
37
  coreos_channel: opts[:coreos_channel],
39
38
  cloudinit: "#{vagrant_path}/cloudinit.yml"
40
39
  }
41
- vagrant_data = erb(File.read(template), vars)
42
- cloudinit = erb(File.read(cloudinit_template), vars)
43
- File.write("#{vagrant_path}/Vagrantfile", vagrant_data)
44
- File.write("#{vagrant_path}/cloudinit.yml", cloudinit)
40
+ spinner "Generating Vagrant config" do
41
+ vagrant_data = erb(File.read(template), vars)
42
+ cloudinit = erb(File.read(cloudinit_template), vars)
43
+ File.write("#{vagrant_path}/Vagrantfile", vagrant_data)
44
+ File.write("#{vagrant_path}/cloudinit.yml", cloudinit)
45
+ end
46
+
45
47
  node = nil
46
48
  Dir.chdir(vagrant_path) do
47
- spinner "Creating Vagrant machine #{name.colorize(:cyan)} " do
48
- Open3.popen2('vagrant up') do |stdin, output, wait|
49
- while o = output.gets
50
- print o if ENV['DEBUG']
51
- end
52
- end
53
- end
49
+ spinner "Triggering CoreOS Container Linux box update"
50
+ run_command('vagrant box update')
51
+ spinner "Executing 'vagrant up'"
52
+ run_command('vagrant up')
53
+ spinner "'vagrant up' executed successfully"
54
54
  spinner "Waiting for node #{name.colorize(:cyan)} to join grid #{grid.colorize(:cyan)} " do
55
55
  sleep 1 until node = node_exists_in_grid?(grid, name)
56
56
  end
@@ -67,10 +67,6 @@ module Kontena
67
67
  "#{super}-#{rand(1..99)}"
68
68
  end
69
69
 
70
- def erb(template, vars)
71
- ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
72
- end
73
-
74
70
  def node_exists_in_grid?(grid, name)
75
71
  api_client.get("grids/#{grid}/nodes")['nodes'].find{|n| n['name'] == name}
76
72
  end
@@ -4,17 +4,13 @@ module Kontena::Plugin::Vagrant::Master
4
4
 
5
5
  def execute
6
6
  require_relative '../../../machine/vagrant'
7
-
7
+
8
8
  vagrant_path = "#{Dir.home}/.kontena/vagrant_master"
9
9
  abort("Cannot find Vagrant kontena-master".colorize(:red)) unless Dir.exist?(vagrant_path)
10
10
  Dir.chdir(vagrant_path) do
11
- spinner "Restarting Vagrant kontena-master " do
12
- Open3.popen2('vagrant reload') do |stdin, output, wait|
13
- while o = output.gets
14
- print o if ENV['DEBUG']
15
- end
16
- end
17
- end
11
+ spinner "Executing 'vagrant reload' for kontena-master"
12
+ exit $?.exitstatus unless system('vagrant reload')
13
+ spinner "Vagrant machine restarted"
18
14
  end
19
15
  end
20
16
  end
@@ -4,17 +4,12 @@ module Kontena::Plugin::Vagrant::Master
4
4
 
5
5
  def execute
6
6
  require_relative '../../../machine/vagrant'
7
-
7
+
8
8
  vagrant_path = "#{Dir.home}/.kontena/vagrant_master"
9
9
  abort("Cannot find Vagrant node kontena-master".colorize(:red)) unless Dir.exist?(vagrant_path)
10
10
  Dir.chdir(vagrant_path) do
11
- spinner "Starting Vagrant machine kontena-master " do
12
- Open3.popen2('vagrant up') do |stdin, output, wait|
13
- while o = output.gets
14
- print o if ENV['DEBUG']
15
- end
16
- end
17
- end
11
+ spinner "Triggering 'vagrant up' for kontena-master"
12
+ exit $?.exitstatus unless system('vagrant up')
18
13
  end
19
14
  end
20
15
  end
@@ -4,17 +4,12 @@ module Kontena::Plugin::Vagrant::Master
4
4
 
5
5
  def execute
6
6
  require_relative '../../../machine/vagrant'
7
-
7
+
8
8
  vagrant_path = "#{Dir.home}/.kontena/vagrant_master"
9
9
  abort("Cannot find Vagrant kontena-master".colorize(:red)) unless Dir.exist?(vagrant_path)
10
10
  Dir.chdir(vagrant_path) do
11
- spinner "Stopping Vagrant kontena-master " do
12
- Open3.popen2('vagrant halt') do |stdin, output, wait|
13
- while o = output.gets
14
- print o if ENV['DEBUG']
15
- end
16
- end
17
- end
11
+ spinner "Triggering 'vagrant halt' for kontena-master"
12
+ exit $?.exitstatus unless system('vagrant halt')
18
13
  end
19
14
  end
20
15
  end
@@ -6,6 +6,7 @@ module Kontena::Plugin::Vagrant::Nodes
6
6
  parameter "[NAME]", "Node name"
7
7
  option "--instances", "AMOUNT", "How many nodes will be created"
8
8
  option "--memory", "MEMORY", "How much memory node has"
9
+ option "--network-address", "IP", "First IP address for the node(s)", default: 'dhcp'
9
10
  option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
10
11
  option "--coreos-channel", "CHANNEL", "CoreOS release channel", default: 'stable'
11
12
 
@@ -20,6 +21,14 @@ module Kontena::Plugin::Vagrant::Nodes
20
21
 
21
22
  grid = fetch_grid
22
23
  provisioner = provisioner(client(require_token))
24
+
25
+ require 'ipaddr'
26
+ ip_address = if network_address == "dhcp"
27
+ nil
28
+ else
29
+ IPAddr.new network_address
30
+ end
31
+
23
32
  instance_count.to_i.times do |i|
24
33
  provisioner.run!(
25
34
  master_uri: api_url,
@@ -27,10 +36,13 @@ module Kontena::Plugin::Vagrant::Nodes
27
36
  grid: current_grid,
28
37
  name: name,
29
38
  instance_number: i + 1,
39
+ network_address: ip_address ? ip_address.to_s : "dhcp",
30
40
  memory: instance_memory,
31
41
  version: version,
32
42
  coreos_channel: coreos_channel
33
43
  )
44
+
45
+ ip_address = ip_address.succ if ip_address
34
46
  end
35
47
  end
36
48
 
@@ -14,13 +14,8 @@ module Kontena::Plugin::Vagrant::Nodes
14
14
  vagrant_path = "#{Dir.home}/.kontena/#{current_grid}/#{name}"
15
15
  abort("Cannot find Vagrant node #{name}".colorize(:red)) unless Dir.exist?(vagrant_path)
16
16
  Dir.chdir(vagrant_path) do
17
- spinner "Restarting Vagrant machine #{name.colorize(:cyan)} " do
18
- Open3.popen2('vagrant reload') do |stdin, output, wait|
19
- while o = output.gets
20
- print o if ENV['DEBUG']
21
- end
22
- end
23
- end
17
+ spinner "Triggering 'vagrant reload' for #{name.colorize(:cyan)}"
18
+ exit $?.exitstatus unless system('vagrant reload')
24
19
  end
25
20
  end
26
21
  end
@@ -10,17 +10,12 @@ module Kontena::Plugin::Vagrant::Nodes
10
10
  require_current_grid
11
11
 
12
12
  require_relative '../../../machine/vagrant'
13
-
13
+
14
14
  vagrant_path = "#{Dir.home}/.kontena/#{current_grid}/#{name}"
15
15
  abort("Cannot find Vagrant node #{name}".colorize(:red)) unless Dir.exist?(vagrant_path)
16
16
  Dir.chdir(vagrant_path) do
17
- spinner "Starting Vagrant machine #{name.colorize(:cyan)} " do
18
- Open3.popen2('vagrant up') do |stdin, output, wait|
19
- while o = output.gets
20
- print o if ENV['DEBUG']
21
- end
22
- end
23
- end
17
+ spinner "Triggering 'vagrant up' for #{name.colorize(:cyan)}"
18
+ exit $?.exitstatus unless system('vagrant up')
24
19
  end
25
20
  end
26
21
  end
@@ -10,17 +10,12 @@ module Kontena::Plugin::Vagrant::Nodes
10
10
  require_current_grid
11
11
 
12
12
  require_relative '../../../machine/vagrant'
13
-
13
+
14
14
  vagrant_path = "#{Dir.home}/.kontena/#{current_grid}/#{name}"
15
15
  abort("Cannot find Vagrant node #{name}".colorize(:red)) unless Dir.exist?(vagrant_path)
16
16
  Dir.chdir(vagrant_path) do
17
- spinner "Stopping Vagrant machine #{name.colorize(:cyan)} " do
18
- Open3.popen2('vagrant halt') do |stdin, output, wait|
19
- while o = output.gets
20
- print o if ENV['DEBUG']
21
- end
22
- end
23
- end
17
+ spinner "Triggering 'vagrant halt' for #{name.colorize(:cyan)}"
18
+ exit $?.exitstatus unless system('vagrant halt')
24
19
  end
25
20
  end
26
21
  end
@@ -1,7 +1,7 @@
1
1
  module Kontena
2
2
  module Plugin
3
3
  module Vagrant
4
- VERSION = "0.2.7"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-plugin-vagrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-03 00:00:00.000000000 Z
11
+ date: 2017-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kontena-cli
@@ -73,6 +73,7 @@ files:
73
73
  - lib/kontena/machine/vagrant/Vagrantfile.master.rb.erb
74
74
  - lib/kontena/machine/vagrant/Vagrantfile.node.rb.erb
75
75
  - lib/kontena/machine/vagrant/cloudinit.yml
76
+ - lib/kontena/machine/vagrant/common.rb
76
77
  - lib/kontena/machine/vagrant/master_destroyer.rb
77
78
  - lib/kontena/machine/vagrant/master_provisioner.rb
78
79
  - lib/kontena/machine/vagrant/node_destroyer.rb