vagrant-krane 0.0.1.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a1ec8c728889dd853cc2c700000119b0d119030
4
+ data.tar.gz: 3fdf36ff15d813b925da69a79d560359754a21a3
5
+ SHA512:
6
+ metadata.gz: 9a416f712d0636292e82465896777f853bdd3ec32b45d981cbdd8f969cc8c516f2a663d65e50568dc426c9ca78e638a2f0db8227769b419dd553b542e7eec35d
7
+ data.tar.gz: cfc3bdaa93182c826469de3bfdae5e3029760637cf5009ff3e967a14eef30326b9eb4daed27217250086cd75cf8cc4c2699e255ffb61ba524e1ea67e0b7ddc4b
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Roberto Quintanilla
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Vagrant::Krane
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'vagrant-krane'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install vagrant-krane
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/vagrant-krane/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,72 @@
1
+ require "docker"
2
+
3
+ module Vagrant::Krane::Action
4
+ module Common
5
+
6
+ HOSTS_FILE_PATH = if Vagrant::Util::Platform.windows?
7
+ File.expand_path 'system32/drivers/etc/hosts', ENV['windir']
8
+ else
9
+ '/etc/hosts'
10
+ end
11
+
12
+ def hosts_file_path
13
+ Vagrant::Krane::Action::Common::HOSTS_FILE_PATH
14
+ end
15
+
16
+ def hosts_file_contents
17
+ @hosts_file_contents ||= File.read hosts_file_path
18
+ end
19
+
20
+ def clear_mnemoized_hosts_file_contents!
21
+ @hosts_file_contents = nil
22
+ end
23
+
24
+ def initialize(app, env)
25
+ @app = app
26
+ @container = env[:machine]
27
+ @container_id_on_initialize = container_id
28
+ @ui = env[:ui]
29
+ end
30
+
31
+ def container_id
32
+ @container.id || @container.config.krane.id || @container_id_on_initialize
33
+ end
34
+
35
+ def get_container_ip_addresses
36
+ ip_addresses = []
37
+
38
+ # Get the container info of the @container:
39
+ docker_container = Docker::Container.get container_id
40
+ ip_addresses << docker_container.info["NetworkSettings"]["IPAddress"]
41
+
42
+ ip_addresses
43
+ end
44
+
45
+ def get_container_host_names
46
+ host_names = [@container.config.vm.hostname]
47
+ host_names.concat @container.config.krane.aliases
48
+ host_names.compact
49
+ end
50
+
51
+ def get_host_entry(ip_address, host_names, container_name, container_id)
52
+ [
53
+ ip_address,
54
+ host_names.join(' '),
55
+ host_entry_signature(container_name, container_id)
56
+ ].join(' ')
57
+ end
58
+
59
+ def host_entry_signature(container_name, container_id)
60
+ "# vagrant-krane: docker container #{container_id} #{container_name}"
61
+ end
62
+
63
+ def sudo(command)
64
+ return if !command
65
+ if Vagrant::Util::Platform.windows?
66
+ `#{command}`
67
+ else
68
+ `sudo #{command}`
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,42 @@
1
+ require_relative "common"
2
+ module Vagrant::Krane::Action
3
+ class RemoveHosts
4
+ include Common
5
+
6
+ def call(env)
7
+ case env[:machine_action]
8
+ when :destroy, :halt
9
+ if container_id && @container.config.krane.aliases.any?
10
+ @ui.info "Removing aliases from hosts file"
11
+ remove_host_entries
12
+ end
13
+ else
14
+ #
15
+ end
16
+ @app.call(env)
17
+ end
18
+
19
+ protected
20
+
21
+ def remove_host_entries
22
+ remove_from_hosts if hosts_file_contents.match /#{container_id}/
23
+ end
24
+
25
+ def remove_from_hosts(options = {})
26
+ if !File.writable?(hosts_file_path)
27
+ sudo(%Q(sed -i -e '/#{container_id}/ d' #{hosts_file_path}))
28
+ else
29
+ new_hosts_file_contents = ""
30
+ File.open(hosts_file_path).each do |line|
31
+ new_hosts_file_contents << line unless line.include?(container_id)
32
+ end
33
+
34
+ File.open(hosts_file_path, "w") do |file|
35
+ file.write new_hosts_file_contents
36
+ end
37
+ end
38
+ clear_mnemoized_hosts_file_contents!
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,74 @@
1
+ require_relative "common"
2
+ module Vagrant::Krane::Action
3
+ class UpdateHosts
4
+ include Common
5
+
6
+ def call(env)
7
+ @app.call(env)
8
+
9
+ if @container.config.krane.aliases.any?
10
+ @ui.info "Checking for host entries"
11
+ add_host_entries
12
+ end
13
+ end
14
+
15
+ protected
16
+
17
+ def add_host_entries
18
+
19
+ container_ip_addresses = get_container_ip_addresses
20
+ container_host_names = get_container_host_names
21
+
22
+ host_file_entries = container_ip_addresses.inject({}) do |hash, ip_address|
23
+ hash[container_id] = get_host_entry(
24
+ ip_address, container_host_names, @container.name, container_id
25
+ )
26
+ hash
27
+ end.select do |container_id, host_entry| # Seleccionar las que no existan...
28
+ !hosts_file_contents.match(/#{Regexp.quote(host_entry)}/)
29
+ end
30
+
31
+ add_entries_to_hosts_file host_file_entries
32
+ end
33
+
34
+ def add_entries_to_hosts_file(hosts_file_entries)
35
+ hosts_file_entries.each do |docker_container_id, hosts_file_entry|
36
+
37
+ hosts_file_entry_found_in_hosts_file_contents = false
38
+
39
+ new_hosts_file_contents = hosts_file_contents.split("\n").map do |line|
40
+ if line.include?(docker_container_id)
41
+ hosts_file_entry_found_in_hosts_file_contents = true
42
+ hosts_file_entry
43
+ else
44
+ line
45
+ end
46
+ end.uniq
47
+
48
+ if hosts_file_entry_found_in_hosts_file_contents
49
+ # Notify to UI that entries will be added:
50
+ @ui.info "updating (#{hosts_file_path}): #{hosts_file_entry}"
51
+ else
52
+ # Notify to UI that entries will be added:
53
+ new_hosts_file_contents << hosts_file_entry
54
+ @ui.info "adding to (#{hosts_file_path}) : #{hosts_file_entry}"
55
+ end
56
+
57
+ new_hosts_file_contents = new_hosts_file_contents.join "\n"
58
+
59
+ if !File.writable?(hosts_file_path)
60
+ sudo(%Q(sh -c 'echo "#{new_hosts_file_contents}" >> #{hosts_file_path}'))
61
+ else
62
+ content = "\n" + content
63
+
64
+ File.open hosts_file_path, "a" do |hosts_file|
65
+ hosts_file.write new_hosts_file_contents.join("\n")
66
+ end
67
+ end
68
+ clear_mnemoized_hosts_file_contents!
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,30 @@
1
+ module Vagrant
2
+ module Krane
3
+ class Command < Vagrant.plugin('2', :command)
4
+ #include HostsFile
5
+
6
+ def execute
7
+ # options = {}
8
+ # opts = OptionParser.new do |o|
9
+ # o.banner = 'Usage: vagrant hostmanager [vm-name]'
10
+ # o.separator ''
11
+
12
+ # o.on('--provider provider', String,
13
+ # 'Update machines with the specific provider.') do |provider|
14
+ # options[:provider] = provider
15
+ # end
16
+ # end
17
+
18
+ # argv = parse_options(opts)
19
+ # options[:provider] ||= @env.default_provider
20
+
21
+ # generate(@env, options[:provider].to_sym)
22
+
23
+ # with_target_vms(argv, options) do |machine|
24
+ # update(machine)
25
+ # end
26
+ puts "ran command"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ module Vagrant::Krane
2
+ class Config < Vagrant.plugin(2, :config)
3
+
4
+ attr_accessor :id
5
+ # An array of container's aliases for host
6
+ #
7
+ # @return [Array]
8
+ attr_accessor :aliases
9
+
10
+ def initialize
11
+ @id = UNSET_VALUE
12
+ @aliases = UNSET_VALUE
13
+ end
14
+
15
+ def finalize!
16
+ @id = nil if @id == UNSET_VALUE
17
+ @aliases = [] if @aliases == UNSET_VALUE
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,47 @@
1
+ require 'vagrant'
2
+ require "vagrant-krane/action/update_hosts"
3
+ # require 'vagrant-backports/utils'
4
+ # require "vagrant-krane/action/cache_hosts"
5
+ require "vagrant-krane/action/remove_hosts"
6
+
7
+ module Vagrant
8
+ module Krane
9
+ class Plugin < Vagrant.plugin("2")
10
+
11
+ # The Plugin Name:
12
+ name "vagrant-krane"
13
+
14
+ # The Plugin Description:
15
+ description <<-EOF
16
+ The Krane plugin offers domain resolution from host to docker containers.
17
+ EOF
18
+
19
+ config "krane" do
20
+ require_relative "config"
21
+ Config
22
+ end
23
+
24
+ # Hook up to the "vagrant up" event:
25
+ action_hook(:krane, :machine_action_up) do |hook|
26
+ hook.append(Action::UpdateHosts)
27
+ end
28
+
29
+ action_hook(:krane, :machine_action_halt) do |hook|
30
+ hook.append(Action::RemoveHosts)
31
+ end
32
+
33
+ action_hook(:krane, :machine_action_destroy) do |hook|
34
+ hook.append(Action::RemoveHosts)
35
+ end
36
+
37
+ action_hook(:krane, :machine_action_reload) do |hook|
38
+ hook.append(Action::UpdateHosts)
39
+ end
40
+
41
+ command(:krane) do
42
+ require_relative 'command'
43
+ Command
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Krane
3
+ VERSION = "0.0.1.alpha1"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "vagrant-krane/version"
2
+ require "vagrant-krane/plugin"
3
+
4
+ module Vagrant
5
+ module Krane
6
+ def self.source_root
7
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
8
+ end
9
+ end
10
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,63 @@
1
+ en:
2
+ vagrant_krane:
3
+ messages:
4
+ not_created: |-
5
+ The container hasn't been created yet.
6
+ not_running: |-
7
+ The container is not currently running.
8
+ will_not_destroy: |-
9
+ The container '%{name}' will not be destroyed, since the confirmation
10
+ was declined.
11
+ starting: |-
12
+ Starting container...
13
+ force_shutdown: |-
14
+ Forcing shutdown of container...
15
+ warn_networks: |-
16
+ Warning! The LXC provider doesn't support any of the Vagrant public / private
17
+ network configurations (ex: `config.vm.network :private_network, ip: "some-ip"`).
18
+ They will be silently ignored.
19
+ warn_group: |-
20
+ Warning! The LXC provider doesn't support the :group parameter for synced
21
+ folders. It will be silently ignored.
22
+ warn_owner: |-
23
+ Warning! The LXC provider doesn't support the :owner parameter for synced
24
+ folders. It will be silently ignored.
25
+ vagrant:
26
+ commands:
27
+ status:
28
+ stopped: |-
29
+ The container is currently stopped. Run `vagrant up` to bring it up again.
30
+ actions:
31
+ lxc:
32
+ compressing_rootfs: Compressing container's rootfs...
33
+
34
+ share_folders:
35
+ preparing: Setting up mount entries for shared folders...
36
+
37
+ errors:
38
+ lxc_execute_error: |-
39
+ There was an error executing %{command}
40
+ For more information on the failure, enable detailed logging by setting
41
+ the environment variable VAGRANT_LOG to DEBUG.
42
+
43
+ lxc_incompatible_box: |-
44
+ The base box you are trying to use is not compatible with the installed
45
+ vagrant-lxc version. Supported box versions are %{supported} but %{found} was found.
46
+ lxc_template_file_missing: |-
47
+ The template file used for creating the container was not found for %{name}
48
+ box.
49
+ lxc_templates_dir_missing: |-
50
+ Unable to identify lxc templates path.
51
+ Looked up under: %{paths}
52
+
53
+ lxc_not_installed: |-
54
+ The `lxc` package does not seem to be installed or is not accessible on the PATH.
55
+ lxc_redir_not_installed: |-
56
+ `redir` is not installed or is not accessible on the PATH.
57
+ lxc_container_already_exists: |-
58
+ There is container on your system with the same name you've specified
59
+ on your Vagrantfile (%{name}), please choose a different one or
60
+ run `lxc-destroy --name %{name}` and try again.
61
+ lxc_command_not_supported: |-
62
+ Command (lxc-%{command}) not supported in version %{version}.
63
+ This command is available with version %{available_version}.
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-krane/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-krane"
8
+ spec.version = Vagrant::Krane::VERSION
9
+ spec.authors = ["Roberto Quintanilla"]
10
+ spec.email = ["roberto.quintanilla@naranya.com"]
11
+ spec.summary = %q{Vagrant plugin that helps app development with Docker.}
12
+ spec.description = %q{Vagrant plugin that helps app development with Docker. It offers domain resolution, etc}
13
+ spec.homepage = "https://github.com/vovimayhem/vagrant-krane"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").select do |file_path|
17
+ file_path unless [
18
+ '.gitignore',
19
+ 'Gemfile',
20
+ 'Vagrantfile'
21
+ ].include? file_path
22
+ end
23
+
24
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "docker-api", "~> 1.17"
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.7"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-krane
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha1
5
+ platform: ruby
6
+ authors:
7
+ - Roberto Quintanilla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docker-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Vagrant plugin that helps app development with Docker. It offers domain
56
+ resolution, etc
57
+ email:
58
+ - roberto.quintanilla@naranya.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - lib/vagrant-krane.rb
67
+ - lib/vagrant-krane/action/common.rb
68
+ - lib/vagrant-krane/action/remove_hosts.rb
69
+ - lib/vagrant-krane/action/update_hosts.rb
70
+ - lib/vagrant-krane/command.rb
71
+ - lib/vagrant-krane/config.rb
72
+ - lib/vagrant-krane/plugin.rb
73
+ - lib/vagrant-krane/version.rb
74
+ - locales/en.yml
75
+ - vagrant-krane.gemspec
76
+ homepage: https://github.com/vovimayhem/vagrant-krane
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">"
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.1
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Vagrant plugin that helps app development with Docker.
100
+ test_files: []