limepie-docker-host 1.0.0
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 +7 -0
- data/.gitignore +7 -0
- data/Gemfile +12 -0
- data/LICENSE +0 -0
- data/README.md +1 -0
- data/Rakefile +3 -0
- data/example/Vagrantfile +0 -0
- data/lib/limepie-docker-host.rb +10 -0
- data/lib/limepie-docker-host/action/add_host.rb +22 -0
- data/lib/limepie-docker-host/action/cache_host.rb +20 -0
- data/lib/limepie-docker-host/action/remove_host.rb +23 -0
- data/lib/limepie-docker-host/cap/linux/docker_compose_install.rb +33 -0
- data/lib/limepie-docker-host/cap/linux/docker_compose_installed.rb +19 -0
- data/lib/limepie-docker-host/cap/linux/docker_compose_set_project_name.rb +27 -0
- data/lib/limepie-docker-host/config.rb +44 -0
- data/lib/limepie-docker-host/docker_compose.rb +63 -0
- data/lib/limepie-docker-host/docker_host.rb +156 -0
- data/lib/limepie-docker-host/errors/docker_compose_error.rb +7 -0
- data/lib/limepie-docker-host/inner.rb +40 -0
- data/lib/limepie-docker-host/installer.rb +25 -0
- data/lib/limepie-docker-host/locales/en.yml +11 -0
- data/lib/limepie-docker-host/plugin.rb +54 -0
- data/lib/limepie-docker-host/project.rb +40 -0
- data/lib/limepie-docker-host/provisioner.rb +47 -0
- data/lib/limepie-docker-host/version.rb +5 -0
- data/limepie-docker-host.gemspec +20 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48066fb065af9055e46e9e33f8ed106c1ca4551f
|
4
|
+
data.tar.gz: d742d83419304a9a88f9e909505a86cc21ae5d34
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60721b6c024937be075d34919b9692c805b90a2a531955c51c78ae5591d9ed963d1277a4847e700c20517ee24a01ebe493a46972e3885acbbd91c2a3c3d9ab70
|
7
|
+
data.tar.gz: fdea6c12ed6a2fd2885c6f74c8afce17d55c3c10f6c9d292a1c3caab4d07e782e5d28a420846dc522233b93a75effbea4d4d4baec8eca667f591a88732bf8542
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# vagrant-plugin-docker
|
data/Rakefile
ADDED
data/example/Vagrantfile
ADDED
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "../docker_host"
|
2
|
+
module VagrantPlugins
|
3
|
+
module DockerHostProvisioner
|
4
|
+
module Action
|
5
|
+
class UpdateHosts
|
6
|
+
include DockerHost
|
7
|
+
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@machine = env[:machine]
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
@machine.ui.info "[limepie] Checking for host entries"
|
15
|
+
addHostEntries
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DockerHostProvisioner
|
3
|
+
module Action
|
4
|
+
class CacheHosts
|
5
|
+
include DockerHost
|
6
|
+
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@machine = env[:machine]
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
cacheHostEntries
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DockerHostProvisioner
|
3
|
+
module Action
|
4
|
+
class RemoveHosts
|
5
|
+
include DockerHost
|
6
|
+
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@machine = env[:machine]
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
machine_action = env[:machine_action]
|
14
|
+
puts machine_action
|
15
|
+
@machine.ui.info "[limepie] Removing hosts"
|
16
|
+
removeHostEntries
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DockerHostProvisioner
|
3
|
+
module Cap
|
4
|
+
module Linux
|
5
|
+
module DockerComposeInstall
|
6
|
+
def self.docker_compose_install(machine, config)
|
7
|
+
@machine = machine
|
8
|
+
@config = config
|
9
|
+
|
10
|
+
machine.communicate.tap do |comm|
|
11
|
+
if @config.compose_version == 'latest'
|
12
|
+
command = "git ls-remote https://github.com/docker/compose | grep 'refs/tags' | grep -o '[0-9]\\{1,\\}\\.[0-9]\\{1,\\}\\.[0-9]\\{1,\\}$' | tail -1";
|
13
|
+
|
14
|
+
comm.sudo(command) do |type, data|
|
15
|
+
if type == :stdout
|
16
|
+
@config.compose_version = data.strip
|
17
|
+
end
|
18
|
+
if type == :stderr
|
19
|
+
@config.compose_version = '1.6.1'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
comm.sudo("curl -L https://github.com/docker/compose/releases/download/#{@config.compose_version}/docker-compose-`uname -s`-`uname -m` > #{@config.install_path}")
|
25
|
+
comm.sudo("chmod +x #{@config.install_path}")
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DockerHostProvisioner
|
3
|
+
module Cap
|
4
|
+
module Linux
|
5
|
+
module DockerComposeInstalled
|
6
|
+
def self.docker_compose_installed(machine, config)
|
7
|
+
paths = [
|
8
|
+
config.install_path
|
9
|
+
]
|
10
|
+
|
11
|
+
paths.all? do |p|
|
12
|
+
machine.communicate.test("test -f #{p}", sudo: true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DockerHostProvisioner
|
3
|
+
module Cap
|
4
|
+
module Linux
|
5
|
+
module DockerComposeSetProjectName
|
6
|
+
ROOT_PROFILE_FILE_NAME = "~/.profile"
|
7
|
+
PROFILE_FILE_NAME = "~/.profile_limepie-docker-compose_compose-project-name"
|
8
|
+
|
9
|
+
def self.docker_compose_set_project_name(machine, config)
|
10
|
+
return if config.project_name.nil?
|
11
|
+
machine.communicate.tap do |comm|
|
12
|
+
export_command = "export COMPOSE_PROJECT_NAME='#{config.project_name}'"
|
13
|
+
export_injection_command = "echo \"#{export_command}\" > #{PROFILE_FILE_NAME}"
|
14
|
+
comm.execute(export_injection_command)
|
15
|
+
comm.sudo(export_injection_command)
|
16
|
+
|
17
|
+
source_command = "source #{PROFILE_FILE_NAME}"
|
18
|
+
source_injection_command = "if ! grep -q \"#{source_command}\" #{ROOT_PROFILE_FILE_NAME} ; then echo \"#{source_command}\" >> #{ROOT_PROFILE_FILE_NAME} ; fi"
|
19
|
+
comm.execute(source_injection_command)
|
20
|
+
comm.sudo(source_injection_command)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DockerHostProvisioner
|
3
|
+
class Config < Vagrant.plugin("2", :config)
|
4
|
+
DEFAULT_COMMAND_OPTIONS = {
|
5
|
+
rm: "--force",
|
6
|
+
up: "-d"
|
7
|
+
}
|
8
|
+
|
9
|
+
attr_accessor :timeout, :yml, :rebuild, :project_name, :install_path, :compose_version, :options, :command_options
|
10
|
+
|
11
|
+
def yml=(yml)
|
12
|
+
files = yml.is_a?(Array) ? yml : [yml]
|
13
|
+
files.each do |file|
|
14
|
+
raise DockerComposeError, :yml_must_be_absolute if !Pathname.new(file).absolute?
|
15
|
+
end
|
16
|
+
@yml = yml
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@project_name = UNSET_VALUE
|
21
|
+
@compose_version = UNSET_VALUE
|
22
|
+
@install_path = UNSET_VALUE
|
23
|
+
@options = UNSET_VALUE
|
24
|
+
@command_options = UNSET_VALUE
|
25
|
+
@timeout = UNSET_VALUE
|
26
|
+
end
|
27
|
+
|
28
|
+
def finalize!
|
29
|
+
if @timeout == UNSET_VALUE
|
30
|
+
@timeout = nil
|
31
|
+
else
|
32
|
+
@timeout = "COMPOSE_HTTP_TIMEOUT=" + @timeout.to_s + " "
|
33
|
+
end
|
34
|
+
|
35
|
+
@project_name = nil if @project_name == UNSET_VALUE
|
36
|
+
@compose_version = 'latest' if @compose_version == UNSET_VALUE
|
37
|
+
@install_path = nil if @install_path == UNSET_VALUE
|
38
|
+
@options = nil if @options == UNSET_VALUE
|
39
|
+
@command_options = {} if @command_options == UNSET_VALUE
|
40
|
+
@command_options = DEFAULT_COMMAND_OPTIONS.merge(@command_options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module DockerHostProvisioner
|
5
|
+
class DockerCompose
|
6
|
+
def initialize(machine, config)
|
7
|
+
@machine = machine
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def build
|
12
|
+
@machine.ui.detail(I18n.t(:docker_compose_build))
|
13
|
+
@machine.communicate.tap do |comm|
|
14
|
+
command = "#{@config.timeout} #{@config.install_path} #{@config.options} #{cli_options_for_yml_file} build #{@config.command_options[:build]}";
|
15
|
+
|
16
|
+
comm.sudo(command) do |type, data|
|
17
|
+
handle_comm(type, data)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def rm
|
23
|
+
@machine.ui.detail(I18n.t(:docker_compose_rm))
|
24
|
+
@machine.communicate.tap do |comm|
|
25
|
+
command = "#{@config.timeout} #{@config.install_path} #{@config.options} #{cli_options_for_yml_file} rm #{@config.command_options[:rm]}"
|
26
|
+
|
27
|
+
comm.sudo(command) do |type, data|
|
28
|
+
handle_comm(type, data)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def up
|
34
|
+
@machine.ui.detail(I18n.t(:docker_compose_up))
|
35
|
+
@machine.communicate.tap do |comm|
|
36
|
+
command = "#{@config.timeout} #{@config.install_path} #{@config.options} #{cli_options_for_yml_file} up #{@config.command_options[:up]}"
|
37
|
+
|
38
|
+
comm.sudo(command) do |type, data|
|
39
|
+
handle_comm(type, data)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def handle_comm(type, data)
|
47
|
+
data.chomp!
|
48
|
+
return if data.empty?
|
49
|
+
case type
|
50
|
+
when :stdout; @machine.ui.detail(data)
|
51
|
+
when :stderr; @machine.ui.error(data)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def cli_options_for_yml_file
|
58
|
+
files = @config.yml.is_a?(Array) ? @config.yml : [@config.yml]
|
59
|
+
files.map { |file| "-f \"#{file}\"" }.join(" ")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DockerHostProvisioner
|
3
|
+
class DockerHost
|
4
|
+
@@hosts_path = Vagrant::Util::Platform.windows? ? File.expand_path('system32/drivers/etc/hosts', ENV['windir']) : '/etc/hosts'
|
5
|
+
|
6
|
+
def initialize(machine, config)
|
7
|
+
@machine = machine
|
8
|
+
@config = config
|
9
|
+
@@hosts_path = Vagrant::Util::Platform.windows? ? File.expand_path('system32/drivers/etc/hosts', ENV['windir']) : '/etc/hosts'
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
@machine.ui.detail("add entry to host /etc/hosts file when a docker container is started")
|
14
|
+
addHostEntries()
|
15
|
+
@machine.ui.detail("add entry to host /etc/hosts file when a docker container is end")
|
16
|
+
end
|
17
|
+
|
18
|
+
def cacheHostEntries
|
19
|
+
@machine.config.hostsupdater.id = @machine.id
|
20
|
+
end
|
21
|
+
|
22
|
+
def addHostEntries
|
23
|
+
removeHostEntries
|
24
|
+
host = []
|
25
|
+
uuid = @machine.id || @machine.config.hostsupdater.id
|
26
|
+
|
27
|
+
components = []
|
28
|
+
components << "docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}/{{json .Config.Env}}' \$(docker ps -aq)"
|
29
|
+
command = components.join(" ")
|
30
|
+
|
31
|
+
@machine.communicate.sudo(command) do |type, data|
|
32
|
+
#puts data
|
33
|
+
lists = data.split("\n")
|
34
|
+
lists.each do |list|
|
35
|
+
|
36
|
+
tmp = list.split("/", 2)
|
37
|
+
matches = tmp[1].match(/DOMAIN=([^"]+)"/)
|
38
|
+
|
39
|
+
if !matches.nil?
|
40
|
+
if matches[1]
|
41
|
+
host << tmp[0] + " " + matches[1] + " #" + uuid
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
#handle_comm(type, data)
|
46
|
+
end
|
47
|
+
|
48
|
+
content = host.join("\n")
|
49
|
+
|
50
|
+
if !File.writable_real?(@@hosts_path)
|
51
|
+
if !sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path'))
|
52
|
+
@machine.ui.error "[vagrant-docker-host] Failed to add hosts, could not use sudo"
|
53
|
+
adviseOnSudo
|
54
|
+
end
|
55
|
+
else
|
56
|
+
content = "\n" + content
|
57
|
+
hostsFile = File.open(@@hosts_path, "a")
|
58
|
+
hostsFile.write(content)
|
59
|
+
hostsFile.close()
|
60
|
+
end
|
61
|
+
@machine.ui.detail content
|
62
|
+
if Vagrant::Util::Platform.darwin?
|
63
|
+
addRoute
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def addRoute
|
68
|
+
components = []
|
69
|
+
components << "docker network inspect --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' share_default"
|
70
|
+
command = components.join(" ")
|
71
|
+
|
72
|
+
@machine.communicate.sudo(command) do |type, data|
|
73
|
+
|
74
|
+
@@ip = @machine.provider.capability(:public_address) ? @machine.provider.capability(:public_address).strip : ''
|
75
|
+
|
76
|
+
route_add = "route -n add " + data.strip + " " + @@ip
|
77
|
+
|
78
|
+
if !sudo(%Q(#{route_add}))
|
79
|
+
@machine.ui.error "[vagrant-docker-host] Failed to add route, could not use sudo"
|
80
|
+
adviseOnSudo
|
81
|
+
else
|
82
|
+
@machine.ui.detail(route_add)
|
83
|
+
end
|
84
|
+
|
85
|
+
#handle_comm(type, data)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def removeHostEntries(options = {})
|
90
|
+
uuid = @machine.id || @machine.config.hostsupdater.id
|
91
|
+
|
92
|
+
if !File.writable_real?(@@hosts_path)
|
93
|
+
if !sudo(%Q(sed -i -e '/#{uuid}/ d' #@@hosts_path))
|
94
|
+
@ui.error "[vagrant-hostsupdater] Failed to remove hosts, could not use sudo"
|
95
|
+
adviseOnSudo
|
96
|
+
end
|
97
|
+
else
|
98
|
+
hosts = ""
|
99
|
+
File.open(@@hosts_path).each do |line|
|
100
|
+
hosts << line unless line.include?(uuid)
|
101
|
+
end
|
102
|
+
hostsFile = File.open(@@hosts_path, "w")
|
103
|
+
hostsFile.write(hosts)
|
104
|
+
hostsFile.close()
|
105
|
+
end
|
106
|
+
|
107
|
+
if Vagrant::Util::Platform.darwin?
|
108
|
+
removeRoute
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def removeRoute
|
113
|
+
components = []
|
114
|
+
components << "docker network inspect --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' share_default"
|
115
|
+
command = components.join(" ")
|
116
|
+
|
117
|
+
@machine.communicate.sudo(command) do |type, data|
|
118
|
+
route_delete = "route -n delete " + data.strip + " "
|
119
|
+
|
120
|
+
if !sudo(%Q(#{route_delete}))
|
121
|
+
@machine.ui.error "[vagrant-docker-host] Failed to remove route, could not use sudo"
|
122
|
+
adviseOnSudo
|
123
|
+
else
|
124
|
+
@machine.ui.detail(route_delete)
|
125
|
+
end
|
126
|
+
|
127
|
+
#handle_comm(type, data)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def adviseOnSudo
|
132
|
+
@machine.ui.error "[vagrant-docker-host] Consider adding the following to your sudoers file:"
|
133
|
+
@machine.ui.error "[vagrant-docker-host] https://github.com/cogitatio/vagrant-docker-host#passwordless-sudo"
|
134
|
+
end
|
135
|
+
|
136
|
+
def sudo(command)
|
137
|
+
return if !command
|
138
|
+
|
139
|
+
if Vagrant::Util::Platform.windows?
|
140
|
+
`#{command}`
|
141
|
+
else
|
142
|
+
return `sudo #{command}`
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def handle_comm(type, data)
|
147
|
+
data.chomp!
|
148
|
+
return if data.empty?
|
149
|
+
case type
|
150
|
+
when :stdout; @machine.ui.detail(data)
|
151
|
+
when :stderr; @machine.ui.error(data)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
module VagrantPlugins
|
3
|
+
module DockerHostProvisioner
|
4
|
+
class Inner < Vagrant.plugin('2', :command)
|
5
|
+
|
6
|
+
def self.synopsis
|
7
|
+
"Calls an Ansible script to do something."
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(machine, config)
|
11
|
+
@machine = machine
|
12
|
+
@config = config
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
argv = ARGV
|
20
|
+
argv.delete_at(0)
|
21
|
+
|
22
|
+
if argv.nil?
|
23
|
+
puts "You must specify at least one item."
|
24
|
+
return 1
|
25
|
+
end
|
26
|
+
|
27
|
+
if argv.length == 0
|
28
|
+
puts "You must specify at least one item."
|
29
|
+
return 1
|
30
|
+
end
|
31
|
+
items = argv.join(' ')
|
32
|
+
puts ">> " + items
|
33
|
+
exec("vagrant ssh -c '#{items}' ")
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DockerHostProvisioner
|
3
|
+
class Installer
|
4
|
+
def initialize(machine, config)
|
5
|
+
@machine = machine
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
def ensure_installed
|
10
|
+
@machine.ui.detail(I18n.t(:checking_installation))
|
11
|
+
|
12
|
+
if !@machine.guest.capability(:docker_compose_installed, @config)
|
13
|
+
@machine.ui.detail(I18n.t(:installing, version: @config.compose_version))
|
14
|
+
@machine.guest.capability(:docker_compose_install, @config)
|
15
|
+
|
16
|
+
if !@machine.guest.capability(:docker_compose_installed, @config)
|
17
|
+
raise DockerComposeError, :install_failed
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
@machine.guest.capability(:docker_compose_set_project_name, @config)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
en:
|
2
|
+
errors:
|
3
|
+
yml_must_be_absolute: Docker Compose YML path must be absolute!
|
4
|
+
install_failed: Docker Compose installation failed
|
5
|
+
not_supported_on_guest: Not supported on the guest operating system
|
6
|
+
checking_installation: Checking for Docker Compose installation...
|
7
|
+
installing: Installing Docker Compose %{version}
|
8
|
+
symlinking: Symlinking Docker Compose %{version}
|
9
|
+
docker_compose_up: Running docker-compose up...
|
10
|
+
docker_compose_rm: Running docker-compose rm...
|
11
|
+
docker_compose_build: Running docker-compose build...
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative "docker_host"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module DockerHostProvisioner
|
5
|
+
class Plugin < Vagrant.plugin('2')
|
6
|
+
name 'docker_host'
|
7
|
+
description <<-DESC
|
8
|
+
This plugin manages the /etc/hosts file for the host machine. An entry is
|
9
|
+
created for the hostname attribute in the vm.config.
|
10
|
+
DESC
|
11
|
+
|
12
|
+
|
13
|
+
command 'inner' do
|
14
|
+
require_relative 'inner'
|
15
|
+
Inner
|
16
|
+
end
|
17
|
+
|
18
|
+
command 'project' do
|
19
|
+
require_relative 'project'
|
20
|
+
Project
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
I18n.load_path << File.expand_path("../locales/en.yml", __FILE__)
|
25
|
+
I18n.reload!
|
26
|
+
|
27
|
+
config(:docker_host, :provisioner) do
|
28
|
+
require_relative "config"
|
29
|
+
Config
|
30
|
+
end
|
31
|
+
|
32
|
+
guest_capability("linux", "docker_compose_installed") do
|
33
|
+
require_relative "cap/linux/docker_compose_installed"
|
34
|
+
Cap::Linux::DockerComposeInstalled
|
35
|
+
end
|
36
|
+
|
37
|
+
guest_capability("linux", "docker_compose_install") do
|
38
|
+
require_relative "cap/linux/docker_compose_install"
|
39
|
+
Cap::Linux::DockerComposeInstall
|
40
|
+
end
|
41
|
+
|
42
|
+
guest_capability("linux", "docker_compose_set_project_name") do
|
43
|
+
require_relative "cap/linux/docker_compose_set_project_name"
|
44
|
+
Cap::Linux::DockerComposeSetProjectName
|
45
|
+
end
|
46
|
+
|
47
|
+
provisioner(:docker_host) do
|
48
|
+
require_relative "provisioner"
|
49
|
+
Provisioner
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
module VagrantPlugins
|
3
|
+
module DockerHostProvisioner
|
4
|
+
class Project < Vagrant.plugin('2', :command)
|
5
|
+
|
6
|
+
def self.synopsis
|
7
|
+
"Calls an Ansible script to do something."
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(machine, config)
|
11
|
+
@machine = machine
|
12
|
+
@config = config
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
argv = ARGV
|
20
|
+
argv.delete_at(0)
|
21
|
+
|
22
|
+
if argv.nil?
|
23
|
+
puts "You must specify at least one item."
|
24
|
+
return 1
|
25
|
+
end
|
26
|
+
|
27
|
+
if argv.length == 0
|
28
|
+
puts "You must specify at least one item."
|
29
|
+
return 1
|
30
|
+
end
|
31
|
+
items = argv.join(' ')
|
32
|
+
puts ">> " + items
|
33
|
+
exec("vagrant ssh -c '#{items}' ")
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative "errors/docker_compose_error"
|
2
|
+
require_relative "installer"
|
3
|
+
require_relative "docker_compose"
|
4
|
+
require_relative "docker_host"
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module DockerHostProvisioner
|
8
|
+
class Provisioner < Vagrant.plugin("2", :provisioner)
|
9
|
+
def initialize(machine, config, installer = nil, docker_compose = nil)
|
10
|
+
super(machine, config)
|
11
|
+
|
12
|
+
@installer = installer || Installer.new(@machine, @config)
|
13
|
+
@docker_compose = docker_compose || DockerCompose.new(@machine, @config)
|
14
|
+
end
|
15
|
+
|
16
|
+
def provision
|
17
|
+
@installer.ensure_installed
|
18
|
+
|
19
|
+
return unless @config.yml
|
20
|
+
|
21
|
+
|
22
|
+
if @config.rebuild
|
23
|
+
@docker_compose.rm
|
24
|
+
@docker_compose.build
|
25
|
+
end
|
26
|
+
|
27
|
+
@docker_compose.up
|
28
|
+
|
29
|
+
a = DockerHost.new(@machine, @config)
|
30
|
+
a.execute
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
end
|
35
|
+
def xinitialize(machine, config, docker_host = nil)
|
36
|
+
super(machine, config)
|
37
|
+
|
38
|
+
#@docker_host = docker_host || DockerHost.new(@machine, @config)
|
39
|
+
end
|
40
|
+
|
41
|
+
def xprovision
|
42
|
+
#@docker_host.execute
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require "limepie-docker-host/version"
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = "limepie-docker-host"
|
10
|
+
s.version = VagrantPlugins::DockerHostProvisioner::VERSION
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.authors = ["yejune"]
|
13
|
+
s.homepage = "https://github.com/yejune/vagrant-plugin-docker"
|
14
|
+
s.summary = %q{A Vagrant provisioner for logging into docker.}
|
15
|
+
s.description = %q{A Vagrant provisioner for logging into docker.}
|
16
|
+
|
17
|
+
## s.files = `find . -type f`.split($\)
|
18
|
+
s.files = `git ls-files -z`.split("\0")
|
19
|
+
s.require_path = "lib"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: limepie-docker-host
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yejune
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Vagrant provisioner for logging into docker.
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".gitignore"
|
20
|
+
- Gemfile
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- example/Vagrantfile
|
25
|
+
- lib/limepie-docker-host.rb
|
26
|
+
- lib/limepie-docker-host/action/add_host.rb
|
27
|
+
- lib/limepie-docker-host/action/cache_host.rb
|
28
|
+
- lib/limepie-docker-host/action/remove_host.rb
|
29
|
+
- lib/limepie-docker-host/cap/linux/docker_compose_install.rb
|
30
|
+
- lib/limepie-docker-host/cap/linux/docker_compose_installed.rb
|
31
|
+
- lib/limepie-docker-host/cap/linux/docker_compose_set_project_name.rb
|
32
|
+
- lib/limepie-docker-host/config.rb
|
33
|
+
- lib/limepie-docker-host/docker_compose.rb
|
34
|
+
- lib/limepie-docker-host/docker_host.rb
|
35
|
+
- lib/limepie-docker-host/errors/docker_compose_error.rb
|
36
|
+
- lib/limepie-docker-host/inner.rb
|
37
|
+
- lib/limepie-docker-host/installer.rb
|
38
|
+
- lib/limepie-docker-host/locales/en.yml
|
39
|
+
- lib/limepie-docker-host/plugin.rb
|
40
|
+
- lib/limepie-docker-host/project.rb
|
41
|
+
- lib/limepie-docker-host/provisioner.rb
|
42
|
+
- lib/limepie-docker-host/version.rb
|
43
|
+
- limepie-docker-host.gemspec
|
44
|
+
homepage: https://github.com/yejune/vagrant-plugin-docker
|
45
|
+
licenses: []
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.5.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: A Vagrant provisioner for logging into docker.
|
67
|
+
test_files: []
|