limepie-docker-host 1.0.3 → 1.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18db3a48956733893ddac3d6a8fd7cc5eb13b1da
4
- data.tar.gz: 1b72f167e282769574d2070abf20672ac13c0924
3
+ metadata.gz: fd651ba91458e3e5c87c8790bf1924eba38bf642
4
+ data.tar.gz: 928750d8e4f142077fba12252f2f0c39c5557f02
5
5
  SHA512:
6
- metadata.gz: 68d72dd707080daafc3971a1f93c24055a851f330da0e0718f47a0b30d33eea5230abc6041ffc68910cfa3526d88280c27d73f856a4e13f4b2ebdf7fed5c6a58
7
- data.tar.gz: 26a35d64f7821d1b34ca60ae1f5c7a22246fb21b4d20e24f2f3f855263f69de30c66940bac8a878569a6e171a36cc1642907137b82a381e4ee36b04fdf86ddcf
6
+ metadata.gz: bcee30959cedefcc51032631564578408a2db02fde1e4ec4cd07a7f88c0be13765eb3fd437cc435c12f0f03f7d77693293fe430761439f6e821f6c398cef38e1
7
+ data.tar.gz: c394d55c14bc129ff74dac523371213a0b650274c651dbe63c97838cfa7884d94152f96827858a2adae8f4c67a118aa32fdb378cfa4427ffcd4a4d296950d32b
@@ -21,6 +21,7 @@ module VagrantPlugins
21
21
  end
22
22
  end
23
23
 
24
+ comm.sudo("rm -rf #{@config.install_path}")
24
25
  comm.sudo("curl -L https://github.com/docker/compose/releases/download/#{@config.compose_version}/docker-compose-`uname -s`-`uname -m` > #{@config.install_path}")
25
26
  comm.sudo("chmod +x #{@config.install_path}")
26
27
 
@@ -6,7 +6,7 @@ module VagrantPlugins
6
6
  up: "-d"
7
7
  }
8
8
 
9
- attr_accessor :timeout, :yml, :rebuild, :project_name, :install_path, :compose_version, :options, :command_options
9
+ attr_accessor :project_name, :timeout, :yml, :project_name, :install_path, :compose_version, :options, :command_options, :subnet, :prefix, :command
10
10
 
11
11
  def yml=(yml)
12
12
  files = yml.is_a?(Array) ? yml : [yml]
@@ -18,21 +18,28 @@ module VagrantPlugins
18
18
 
19
19
  def initialize
20
20
  @project_name = UNSET_VALUE
21
+ @timeout = UNSET_VALUE
21
22
  @compose_version = UNSET_VALUE
22
23
  @install_path = UNSET_VALUE
23
24
  @options = UNSET_VALUE
24
25
  @command_options = UNSET_VALUE
25
- @timeout = UNSET_VALUE
26
+ @subnet = UNSET_VALUE
26
27
  end
27
28
 
28
29
  def finalize!
29
- if @timeout == UNSET_VALUE
30
- @timeout = nil
31
- else
32
- @timeout = "COMPOSE_HTTP_TIMEOUT=" + @timeout.to_s + " "
30
+
31
+ @project_name = 'project' if @project_name == UNSET_VALUE
32
+ @prefix = Array.new
33
+ if @timeout
34
+ @prefix.push("COMPOSE_HTTP_TIMEOUT=" + @timeout.to_s)
35
+ end
36
+ if @project_name
37
+ @prefix.push("COMPOSE_PROJECT_NAME=" + @project_name)
33
38
  end
39
+ @prefix = @prefix.join(" ")
34
40
 
35
- @project_name = nil if @project_name == UNSET_VALUE
41
+ @command = ARGV[0]
42
+ @subnet = nil if @subnet == UNSET_VALUE
36
43
  @compose_version = 'latest' if @compose_version == UNSET_VALUE
37
44
  @install_path = nil if @install_path == UNSET_VALUE
38
45
  @options = nil if @options == UNSET_VALUE
@@ -8,11 +8,30 @@ module VagrantPlugins
8
8
  @config = config
9
9
  end
10
10
 
11
+ def docker_compose
12
+
13
+ @prefix = Array.new
14
+
15
+ if @config.prefix
16
+ @prefix.push("#{@config.prefix}")
17
+ end
18
+
19
+ if @config.install_path
20
+ @prefix.push("#{@config.install_path}")
21
+ end
22
+ if @config.options
23
+ @prefix.push("#{@config.options}")
24
+ end
25
+
26
+ @prefix.join(" ")
27
+ end
28
+
11
29
  def build
12
30
  @machine.ui.detail(I18n.t(:docker_compose_build))
13
31
  @machine.communicate.tap do |comm|
14
- command = "#{@config.timeout} #{@config.install_path} #{@config.options} #{cli_options_for_yml_file} build #{@config.command_options[:build]}";
32
+ command = "#{docker_compose} #{cli_options_for_yml_file} build #{@config.command_options[:build]}";
15
33
 
34
+ @machine.ui.detail command
16
35
  comm.sudo(command) do |type, data|
17
36
  handle_comm(type, data)
18
37
  end
@@ -22,8 +41,21 @@ module VagrantPlugins
22
41
  def rm
23
42
  @machine.ui.detail(I18n.t(:docker_compose_rm))
24
43
  @machine.communicate.tap do |comm|
25
- command = "#{@config.timeout} #{@config.install_path} #{@config.options} #{cli_options_for_yml_file} rm #{@config.command_options[:rm]}"
44
+ command = "#{docker_compose} #{cli_options_for_yml_file} rm #{@config.command_options[:rm]}"
26
45
 
46
+ @machine.ui.detail command
47
+ comm.sudo(command) do |type, data|
48
+ handle_comm(type, data)
49
+ end
50
+ end
51
+ end
52
+
53
+ def down
54
+ @machine.ui.detail(I18n.t(:docker_compose_down))
55
+ @machine.communicate.tap do |comm|
56
+ command = "#{docker_compose} #{cli_options_for_yml_file} down #{@config.command_options[:down]}"
57
+
58
+ @machine.ui.detail command
27
59
  comm.sudo(command) do |type, data|
28
60
  handle_comm(type, data)
29
61
  end
@@ -33,8 +65,8 @@ module VagrantPlugins
33
65
  def up
34
66
  @machine.ui.detail(I18n.t(:docker_compose_up))
35
67
  @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
-
68
+ command = "#{docker_compose} #{cli_options_for_yml_file} up #{@config.command_options[:up]}"
69
+ @machine.ui.detail command
38
70
  comm.sudo(command) do |type, data|
39
71
  handle_comm(type, data)
40
72
  end
@@ -1,5 +1,4 @@
1
- require 'yaml'
2
- require_relative 'libraries/deep_merge'
1
+
3
2
  module VagrantPlugins
4
3
  module DockerHostProvisioner
5
4
  class DockerHost
@@ -10,38 +9,6 @@ module VagrantPlugins
10
9
  @config = config
11
10
  @@hosts_path = Vagrant::Util::Platform.windows? ? File.expand_path('system32/drivers/etc/hosts', ENV['windir']) : '/etc/hosts'
12
11
 
13
- setEnv
14
- end
15
-
16
- def setEnv
17
- thing = YAML.load_file('env.yml')
18
-
19
- services = thing['services']
20
- yaml = {
21
- "version" => "2",
22
- "networks" => {
23
- "default" => {
24
- "ipam" => {
25
- "config" => [
26
- {"subnet" => "172.101.0.0/16"}
27
- ]
28
- }
29
- }
30
- },
31
- "services" => services
32
- }
33
-
34
- stages = thing['stages'];
35
-
36
- stages.each do |stage_name, stage|
37
- tmp = yaml
38
- stage['services'].each do |service_name, service|
39
- tmp['services'][service_name] = tmp['services'][service_name].deep_merge(service)
40
- end
41
-
42
- @machine.ui.detail('create file docker-compose.%s.yml' % [stage_name])
43
- File.open('docker-compose.%s.yml' % [stage_name], 'w') {|f| f.write tmp.to_yaml }
44
- end
45
12
  end
46
13
 
47
14
  def execute
@@ -61,7 +28,7 @@ module VagrantPlugins
61
28
  uuid = @machine.id || @machine.config.hostsupdater.id
62
29
 
63
30
  components = []
64
- components << "docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}/{{json .Config.Env}}' \$(docker ps -aq)"
31
+ components << "docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}/{{json .Config.Env}}/{{.State.Status}}/{{index .Config.Labels \"com.docker.compose.project\"}}' \$(docker ps -q) | grep DOMAIN= | grep running | grep " + @config.project_name
65
32
  command = components.join(" ")
66
33
 
67
34
  @machine.communicate.sudo(command) do |type, data|
@@ -70,11 +37,16 @@ module VagrantPlugins
70
37
  lists.each do |list|
71
38
 
72
39
  tmp = list.split("/", 2)
73
- matches = tmp[1].match(/DOMAIN=([^"]+)"/)
40
+ if tmp[1]
41
+
42
+ matches = tmp[1].match(/DOMAIN=([^"]+)"/)
74
43
 
75
- if !matches.nil?
76
- if matches[1]
77
- host << tmp[0].ljust(20) + matches[1].ljust(60) + "#" + uuid
44
+ if !matches.nil?
45
+ if tmp[0].length > 1
46
+ if matches[1].length > 1
47
+ host << tmp[0].ljust(20) + matches[1].ljust(60) + "#" + uuid
48
+ end
49
+ end
78
50
  end
79
51
  end
80
52
  end
@@ -102,7 +74,7 @@ module VagrantPlugins
102
74
 
103
75
  def addRoute
104
76
  components = []
105
- components << "docker network inspect --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' share_default"
77
+ components << "docker network inspect --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' " + @config.project_name + "_default"
106
78
  command = components.join(" ")
107
79
 
108
80
  @machine.communicate.sudo(command) do |type, data|
@@ -124,7 +96,7 @@ module VagrantPlugins
124
96
 
125
97
  def removeHost
126
98
  components = []
127
- components << "docker network inspect --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' share_default"
99
+ components << "docker network inspect --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' " + @config.project_name + "_default"
128
100
  command = components.join(" ")
129
101
 
130
102
  @machine.communicate.sudo(command) do |type, data|
@@ -178,7 +150,7 @@ module VagrantPlugins
178
150
 
179
151
  def removeRoute
180
152
  components = []
181
- components << "docker network inspect --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' share_default"
153
+ components << "docker network inspect --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' " + @config.project_name + "_default"
182
154
  command = components.join(" ")
183
155
 
184
156
  @machine.communicate.sudo(command) do |type, data|
@@ -18,7 +18,6 @@ module VagrantPlugins
18
18
  end
19
19
  end
20
20
 
21
- @machine.guest.capability(:docker_compose_set_project_name, @config)
22
21
  end
23
22
  end
24
23
  end
@@ -7,5 +7,6 @@ en:
7
7
  installing: Installing Docker Compose %{version}
8
8
  symlinking: Symlinking Docker Compose %{version}
9
9
  docker_compose_up: Running docker-compose up...
10
+ docker_compose_down: Running docker-compose down...
10
11
  docker_compose_rm: Running docker-compose rm...
11
12
  docker_compose_build: Running docker-compose build...
@@ -39,11 +39,6 @@ module VagrantPlugins
39
39
  Cap::Linux::DockerComposeInstall
40
40
  end
41
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
42
  provisioner(:docker_host) do
48
43
  require_relative "provisioner"
49
44
  Provisioner
@@ -3,45 +3,117 @@ require_relative "installer"
3
3
  require_relative "docker_compose"
4
4
  require_relative "docker_host"
5
5
 
6
+ require 'yaml'
7
+ require_relative 'libraries/deep_merge'
8
+
6
9
  module VagrantPlugins
7
10
  module DockerHostProvisioner
8
11
  class Provisioner < Vagrant.plugin("2", :provisioner)
9
- def initialize(machine, config, installer = nil, docker_compose = nil)
10
- super(machine, config)
12
+ def initialize(machine, config, installer = nil, docker_compose = nil)
13
+ super(machine, config)
11
14
 
12
- @installer = installer || Installer.new(@machine, @config)
13
- @docker_compose = docker_compose || DockerCompose.new(@machine, @config)
14
- end
15
+ @installer = installer || Installer.new(@machine, @config)
16
+ @docker_compose = docker_compose || DockerCompose.new(@machine, @config)
17
+ end
15
18
 
16
- def provision
17
- @installer.ensure_installed
19
+ def setEnv
18
20
 
19
- return unless @config.yml
21
+ if File.exist?('docker-compose.local.yml') && @config.command == "up"
20
22
 
23
+ else
24
+ conf = YAML.load_file('env.yml')
25
+ if conf['stages']
26
+ stages = conf['stages'];
27
+ else
28
+ stages = {
29
+ "local" => {
30
+ "services" => {}
31
+ }
32
+ }
33
+ end
21
34
 
22
- if @config.rebuild
23
- @docker_compose.rm
24
- @docker_compose.build
25
- end
35
+ stages.each do |stage_name, stage|
36
+ services = conf['services']
37
+ yaml = {
38
+ "version" => "2",
39
+ "services" => services
40
+ }
26
41
 
27
- @docker_compose.up
42
+ if @config.subnet[:"#{stage_name}"]
43
+ yaml['networks'] = {
44
+ "default" => {
45
+ "ipam" => {
46
+ "config" => [
47
+ {"subnet" => @config.subnet[:"#{stage_name}"]}
48
+ ]
49
+ }
50
+ }
51
+ }
52
+ else
53
+ if conf['networks']
54
+ yaml['networks'] = conf['networks']
55
+ end
56
+ end
28
57
 
29
- a = DockerHost.new(@machine, @config)
30
- a.execute
58
+ tmp = yaml
59
+ tmp['services'] = tmp['services'].deep_merge(stage['services'])
31
60
 
61
+ tmp['services'].each do |service_name, service|
62
+ if service['environment_from']
63
+ service['environment_from'].each do |from_name, from|
32
64
 
65
+ from.each do |env_name|
66
+ env_alias = env_name.split(':')
67
+ if env_alias[1]
68
+ tmp['services'][service_name]['environment'][env_alias[1]] = tmp['services'][from_name]['environment'][env_alias[0]];
69
+ else
70
+ tmp['services'][service_name]['environment'][name] = tmp['services'][env_alias[0]]['environment'][env_alias[0]];
71
+ end
72
+ end
33
73
 
34
- end
35
- def xinitialize(machine, config, docker_host = nil)
36
- super(machine, config)
74
+ end
75
+ service.delete('environment_from')
76
+ end
77
+ end
37
78
 
38
- #@docker_host = docker_host || DockerHost.new(@machine, @config)
79
+ @machine.ui.detail('create file docker-compose.%s.yml' % [stage_name])
80
+ File.open('docker-compose.%s.yml' % [stage_name], 'w') {|f| f.write tmp.to_yaml }
81
+ end
39
82
  end
83
+ end
84
+
85
+ def provision
86
+
87
+
88
+ setEnv
89
+
90
+ @installer.ensure_installed
91
+
92
+ return unless @config.yml
40
93
 
41
- def xprovision
42
- #@docker_host.execute
94
+ case @config.command
95
+ when "reload"
96
+ # if prev_project_name = project_name
97
+ #prev_project down
98
+ #network end
99
+ # else
100
+
101
+ # end
102
+ @docker_compose.down
103
+ @docker_compose.build
104
+ else
105
+ # do nothing
43
106
  end
107
+
108
+
109
+ @docker_compose.up
110
+
111
+ a = DockerHost.new(@machine, @config)
112
+ a.execute
113
+
114
+ end
115
+
116
+
44
117
  end
45
118
  end
46
119
  end
47
-
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module DockerHostProvisioner
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: limepie-docker-host
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yejune
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Vagrant provisioner for logging into docker.
14
14
  email:
@@ -28,7 +28,6 @@ files:
28
28
  - lib/limepie-docker-host/action/remove_host.rb
29
29
  - lib/limepie-docker-host/cap/linux/docker_compose_install.rb
30
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
31
  - lib/limepie-docker-host/config.rb
33
32
  - lib/limepie-docker-host/docker_compose.rb
34
33
  - lib/limepie-docker-host/docker_host.rb
@@ -1,27 +0,0 @@
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