kontena-cli 0.9.1 → 0.9.2

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: 2c2841422fbf5d03c51d4d49abdd57bb99abb737
4
- data.tar.gz: 619c1ef499ebd0e59ba480771631b08d7656c063
3
+ metadata.gz: f6f13af1e4ef1baba9a25c485fcdf2eed975896e
4
+ data.tar.gz: 379ce85400a3c12551fba0d4308b1a58c0b9e6cb
5
5
  SHA512:
6
- metadata.gz: 12861ef60ea0076e51ec577927d3ef157d8d112ecf2649bc7bbd2cfac803ce2c2846bef9f194c9dabbc59b4a523d2370751811dfbaedb86fd67bc6e7d3110123
7
- data.tar.gz: d2e105c2d20fbb5acac25907d2851e30d909a280282b3554906c24faad2fd4f9b1ec3311df9a89eb1f1350aebea3595846ed79975ba74009c247b28d79052330
6
+ metadata.gz: 17b1db66fd0e64336ed40bac883691760ccfd96a336ba904626cc5973dcff8154aa231899d44335376a4e427620024e32b4a56b9f76ec1818d67ce992bf1818c
7
+ data.tar.gz: b272375202893d439b306367bef26372aa26433fa1e947daa3cf0f6470a05671f03fd1735dbc5397fb38daa7c7a960c7cffae7ccb34ed2a09477bf62aea6f763
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.9.2
data/bin/kontena CHANGED
@@ -37,7 +37,6 @@ require 'kontena/cli/version_command'
37
37
 
38
38
  class MainCommand < Clamp::Command
39
39
 
40
- subcommand "app", "Grid specific commands", Kontena::Cli::AppCommand
41
40
  subcommand "grid", "Grid specific commands", Kontena::Cli::GridCommand
42
41
  subcommand "app", "App specific commands", Kontena::Cli::AppCommand
43
42
  subcommand "service", "Service specific commands", Kontena::Cli::ServiceCommand
@@ -17,10 +17,8 @@ module Kontena::Cli::Apps
17
17
  def execute
18
18
  require_config_file(filename)
19
19
  @service_prefix = project_name || current_dir
20
- dir = Dir.getwd
21
20
  @services = load_services(filename, service_list, service_prefix)
22
- Dir.chdir(dir)
23
- process_docker_images(services, true) if dockerfile_exist?
21
+ process_docker_images(services, true)
24
22
  end
25
23
  end
26
- end
24
+ end
@@ -34,14 +34,15 @@ module Kontena::Cli::Apps
34
34
 
35
35
  def parse_services(file, name = nil, prefix='')
36
36
  services = YAML.load(File.read(File.expand_path(file)) % {project: prefix})
37
- Dir.chdir(File.dirname(File.expand_path(file)))
38
- services.each do |name, options|
39
- normalize_env_vars(options)
40
- if options.has_key?('extends')
41
- extension_file = options['extends']['file']
42
- service_name = options['extends']['service']
43
- options.delete('extends')
44
- services[name] = extend_options(options, extension_file , service_name, prefix)
37
+ Dir.chdir(File.dirname(File.expand_path(file))) do
38
+ services.each do |name, options|
39
+ normalize_env_vars(options)
40
+ if options.has_key?('extends')
41
+ extension_file = options['extends']['file']
42
+ service_name = options['extends']['service']
43
+ options.delete('extends')
44
+ services[name] = extend_options(options, extension_file , service_name, prefix)
45
+ end
45
46
  end
46
47
  end
47
48
  if name.nil?
@@ -73,14 +74,6 @@ module Kontena::Cli::Apps
73
74
  env_vars
74
75
  end
75
76
 
76
- def dockerfile_exist?
77
- !dockerfile.nil?
78
- end
79
-
80
- def dockerfile
81
- @dockerfile ||= File.new('Dockerfile') rescue nil
82
- end
83
-
84
77
  def create_yml(services, file='kontena.yml')
85
78
  yml = File.new(file, 'w')
86
79
  yml.puts services.to_yaml
@@ -90,6 +83,8 @@ module Kontena::Cli::Apps
90
83
  def app_json
91
84
  if !@app_json && File.exist?('app.json')
92
85
  @app_json = JSON.parse(File.read('app.json'))
86
+ else
87
+ @app_json = {}
93
88
  end
94
89
  @app_json
95
90
  end
@@ -20,12 +20,10 @@ module Kontena::Cli::Apps
20
20
  require_api_url
21
21
  require_token
22
22
  require_config_file(filename)
23
- dir = Dir.getwd
24
23
  @deploy_queue = []
25
24
  @service_prefix = project_name || current_dir
26
25
  @services = load_services(filename, service_list, service_prefix)
27
- Dir.chdir(dir)
28
- process_docker_images(services) if !no_build? && dockerfile_exist?
26
+ process_docker_images(services) if !no_build?
29
27
  create_or_update_services(services)
30
28
  deploy_services(deploy_queue)
31
29
  end
@@ -17,7 +17,10 @@ module Kontena::Cli::Apps
17
17
  docker_compose = {}
18
18
  procfile.keys.each do |service|
19
19
  docker_compose[service] = {'build' => '.' }
20
- docker_compose[service]['environment'] = ['PORT=5000'] if app_json && service == 'web' # Heroku generates PORT env variable so should we do too
20
+ if app_json && service == 'web' # Heroku generates PORT env variable so should we do too
21
+ docker_compose[service]['environment'] = ['PORT=5000']
22
+ docker_compose[service]['ports'] = ['5000:5000']
23
+ end
21
24
  docker_compose[service]['command'] = "/start #{service}" if service != 'web'
22
25
  docker_compose[service]['env_file'] = env_file if env_file
23
26
 
@@ -5,6 +5,7 @@ module Kontena::Cli::Apps
5
5
  services.each do |name, service|
6
6
  if service['build'] && (!image_exist?(service['image']) || force_build)
7
7
  abort("'#{service['image']}' is not valid Docker image name") unless validate_image_name(service['image'])
8
+ abort("'#{service['build']}' does not have Dockerfile") unless dockerfile_exist?(service['build'])
8
9
  puts "Building image #{service['image'].colorize(:cyan)}"
9
10
  build_docker_image(service['image'], service['build'])
10
11
 
@@ -20,15 +21,24 @@ module Kontena::Cli::Apps
20
21
 
21
22
 
22
23
  def build_docker_image(name, path)
23
- system("docker build -t #{name} #{path}")
24
+ ret = system("docker build -t #{name} #{path}")
25
+ abort("Failed to build image #{name.colorize(:cyan)}") unless ret
26
+ ret
24
27
  end
25
28
 
26
29
  def push_docker_image(image)
27
- system("docker push #{image}")
30
+ ret = system("docker push #{image}")
31
+ abort("Failed to push image #{image.colorize(:cyan)}") unless ret
32
+ ret
28
33
  end
29
34
 
30
35
  def image_exist?(image)
31
36
  `docker history #{image} 2>&1` ; $?.success?
32
37
  end
38
+
39
+ def dockerfile_exist?(path)
40
+ file = File.join(File.expand_path(path), 'Dockerfile')
41
+ File.exist?(file)
42
+ end
33
43
  end
34
- end
44
+ end
@@ -5,11 +5,10 @@ module Kontena::Cli::Apps
5
5
  class DockerfileGenerator
6
6
  include Common
7
7
 
8
- def generate(base_image, maintainer)
8
+ def generate(base_image)
9
9
 
10
10
  dockerfile = File.new('Dockerfile', 'w')
11
11
  dockerfile.puts "FROM #{base_image}"
12
- dockerfile.puts "MAINTAINER #{maintainer}"
13
12
  dockerfile.puts 'CMD ["/start", "web"]'
14
13
  dockerfile.close
15
14
  end
@@ -27,7 +27,7 @@ module Kontena::Cli::Apps
27
27
  puts 'Found Dockerfile'
28
28
  elsif create_dockerfile?
29
29
  puts "Creating #{'Dockerfile'.colorize(:cyan)}"
30
- DockerfileGenerator.new.generate(base_image, current_user['email'])
30
+ DockerfileGenerator.new.generate(base_image)
31
31
  end
32
32
 
33
33
  if File.exist?('Procfile')
@@ -88,11 +88,6 @@ module Kontena::Cli::Apps
88
88
  nil
89
89
  end
90
90
 
91
- def current_user
92
- token = require_token
93
- client(token).get('user') rescue ''
94
- end
95
-
96
91
  def create_docker_compose_yml?
97
92
  ['', 'y', 'yes'].include? ask("#{docker_compose_file} not found. Do you want to create it? [Yn]: ").downcase
98
93
  end
@@ -5,9 +5,9 @@ module Kontena::Cli::Master::Vagrant
5
5
  def execute
6
6
  require 'kontena/machine/vagrant'
7
7
  vagrant_path = "#{Dir.home}/.kontena/vagrant_master"
8
- abort("Cannot find Vagrant node #{name}".colorize(:red)) unless Dir.exist?(vagrant_path)
8
+ abort("Cannot find Vagrant node kontena-master".colorize(:red)) unless Dir.exist?(vagrant_path)
9
9
  Dir.chdir(vagrant_path) do
10
- ShellSpinner "Starting Vagrant machine #{name.colorize(:cyan)} " do
10
+ ShellSpinner "Starting Vagrant machine kontena-master " do
11
11
  Open3.popen2('vagrant up') do |stdin, output, wait|
12
12
  while o = output.gets
13
13
  print o if ENV['DEBUG']
@@ -3,10 +3,22 @@ module Kontena::Cli::Vpn
3
3
  include Kontena::Cli::Common
4
4
 
5
5
  def execute
6
+ require 'rbconfig'
6
7
  require_api_url
7
8
  payload = {cmd: ['/usr/local/bin/ovpn_getclient', 'KONTENA_VPN_CLIENT']}
8
9
  stdout, stderr = client(require_token).post("containers/#{current_grid}/vpn/vpn-1/exec", payload)
10
+ if linux?
11
+ stdout << "\n"
12
+ stdout << "up /etc/openvpn/update-resolv-conf\n"
13
+ stdout << "down /etc/openvpn/update-resolv-conf\n"
14
+ end
9
15
  puts stdout
10
16
  end
17
+
18
+ # @return [Boolean]
19
+ def linux?
20
+ host_os = RbConfig::CONFIG['host_os']
21
+ host_os.include?('linux')
22
+ end
11
23
  end
12
24
  end
@@ -22,8 +22,7 @@ module Kontena::Cli::Vpn
22
22
  abort('Node not found') if node.nil?
23
23
  end
24
24
 
25
- public_ip = ip || node['public_ip']
26
-
25
+ vpn_ip = node_vpn_ip(node)
27
26
  data = {
28
27
  name: 'vpn',
29
28
  stateful: true,
@@ -36,7 +35,7 @@ module Kontena::Cli::Vpn
36
35
  }
37
36
  ],
38
37
  cap_add: ['NET_ADMIN'],
39
- env: ["OVPN_SERVER_URL=udp://#{public_ip}:1194"],
38
+ env: ["OVPN_SERVER_URL=udp://#{vpn_ip}:1194"],
40
39
  affinity: ["node==#{node['name']}"]
41
40
  }
42
41
  client(token).post("grids/#{current_grid}/services", data)
@@ -47,8 +46,21 @@ module Kontena::Cli::Vpn
47
46
  sleep 1
48
47
  end
49
48
  puts ' done'
50
- puts "OpenVPN service is now started (udp://#{public_ip}:1194)."
49
+ puts "OpenVPN service is now started (udp://#{vpn_ip}:1194)."
51
50
  puts "Use 'kontena vpn config' to fetch OpenVPN client config to your machine (it takes a while until config is ready)."
52
51
  end
52
+
53
+ # @param [Hash] node
54
+ # @return [String]
55
+ def node_vpn_ip(node)
56
+ ip unless ip.nil?
57
+
58
+ # vagrant
59
+ if api_url == 'http://192.168.66.100:8080'
60
+ node['private_ip']
61
+ else
62
+ node['public_ip']
63
+ end
64
+ end
53
65
  end
54
66
  end
@@ -12,7 +12,7 @@ write_files:
12
12
  - path: /etc/systemd/system/docker.service.d/50-kontena.conf
13
13
  content: |
14
14
  [Service]
15
- Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/19" --bip="172.17.42.1/16"'
15
+ Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/19" --bip="172.17.43.1/16"'
16
16
  coreos:
17
17
  units:
18
18
  - name: 00-eth.network
@@ -22,7 +22,7 @@ coreos:
22
22
  Name=eth*
23
23
  [Network]
24
24
  DHCP=yes
25
- DNS=172.17.42.1
25
+ DNS=172.17.43.1
26
26
  DNS=<%= dns_server %>
27
27
  DOMAINS=kontena.local
28
28
  [DHCP]
@@ -11,12 +11,12 @@ 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/19" --bip="172.17.42.1/16"'
14
+ Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/19" --bip="172.17.43.1/16"'
15
15
  - path: /etc/resolv.conf
16
16
  permissions: 0644
17
17
  owner: root
18
18
  content: |
19
- nameserver 172.17.42.1
19
+ nameserver 172.17.43.1
20
20
  nameserver 8.8.8.8
21
21
  nameserver 8.8.4.4
22
22
  coreos:
@@ -11,12 +11,12 @@ 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/19" --bip="172.17.42.1/16"'
14
+ Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/19" --bip="172.17.43.1/16"'
15
15
  - path: /etc/resolv.conf
16
16
  permissions: 0644
17
17
  owner: root
18
18
  content: |
19
- nameserver 172.17.42.1
19
+ nameserver 172.17.43.1
20
20
  nameserver 8.8.8.8
21
21
  nameserver 8.8.4.4
22
22
  coreos:
@@ -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/19" --bip="172.17.42.1/16"'
14
+ Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/19" --bip="172.17.43.1/16"'
15
15
  coreos:
16
16
  units:
17
17
  - name: 00-eth.network
@@ -21,7 +21,7 @@ coreos:
21
21
  Name=eth*
22
22
  [Network]
23
23
  DHCP=yes
24
- DNS=172.17.42.1
24
+ DNS=172.17.43.1
25
25
  DNS=172.28.128.1
26
26
  DNS=8.8.8.8
27
27
  DOMAINS=kontena.local
@@ -126,7 +126,6 @@ yml
126
126
 
127
127
  it 'uses current directory as service name prefix by default' do
128
128
  current_dir = '/kontena/tests/stacks'
129
- allow(Dir).to receive(:chdir).and_return(true)
130
129
  allow(Dir).to receive(:getwd).and_return(current_dir)
131
130
  expect(File).to receive(:basename).with(current_dir).and_return('stacks')
132
131
  subject.run([])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-25 00:00:00.000000000 Z
11
+ date: 2015-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler