From f5b6f2c6ef81e626b376fee296011f73e34fe8e7 Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Wed, 1 Jan 2014 16:32:37 -0800 Subject: [PATCH 1/6] fix(nit): Spelling fix --- resources/container.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/container.rb b/resources/container.rb index edd23fbadd..de05946fa6 100644 --- a/resources/container.rb +++ b/resources/container.rb @@ -22,7 +22,7 @@ attribute :link, :kind_of => [String] attribute :lxc_conf, :kind_of => [String, Array] attribute :memory, :kind_of => [Fixnum] -# Fixnum kind_of port attribute is DEPRACATED +# Fixnum kind_of port attribute is DEPRECATED attribute :port, :kind_of => [Fixnum, String, Array] attribute :privileged, :kind_of => [TrueClass, FalseClass] # public_port attribute is DEPRECATED From 6ee5e60b6cc22268daa257bcdff4a78e84d5da94 Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Wed, 1 Jan 2014 16:57:42 -0800 Subject: [PATCH 2/6] feature(template): Choose template for init config - This allows a user using the docker_container resource to specify an alternate template for the init configuration. This allows for custom chaining of service dependencies for upstart, as well as environment specific benefits - Also allow a user using docker_container resource and systemd to specify a custom template for the systemd socket unit file --- README.md | 2 ++ providers/container.rb | 28 ++++++++++++++++++++++++---- resources/container.rb | 2 ++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0ccbfe6edd..d6ec096584 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ hostname | Container hostname | String | nil id | Container ID (internally set by LWRP) | String | nil image | Image for container | String | LWRP name init_type | Init type for container service handling | FalseClass, String | `node['docker']['container_init_type']` +init_template | Template to use for init configuration | String | nil link | Add link to another container | String | nil lxc_conf | Custom LXC options | String, Array | nil memory | Set memory limit for container | Fixnum | nil @@ -127,6 +128,7 @@ public_port (*DEPRECATED*) | Map host port to container | Fixnum | nil publish_exposed_ports | Publish all exposed ports to the host interfaces | TrueClass, FalseClass | false remove_automatically | Automatically remove the container when it exits (incompatible with detach) | TrueClass, FalseClass | false running | Container running status (internally set by LWRP) | TrueClass, FalseClass | nil +socket_template | Template to use for configuring socket (relevent for init_type systemd only) | String | nil stdin | Attach container's stdin | TrueClass, FalseClass | nil tty | Allocate a pseudo-tty | TrueClass, FalseClass | nil user | User to run container | String | nil diff --git a/providers/container.rb b/providers/container.rb index 689973020a..9b43cf2546 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -193,7 +193,7 @@ def service_create def service_create_systemd template "/usr/lib/systemd/system/#{service_name}.socket" do - source 'docker-container.socket.erb' + source socket_template cookbook new_resource.cookbook mode '0644' owner 'root' @@ -206,7 +206,7 @@ def service_create_systemd end template "/usr/lib/systemd/system/#{service_name}.service" do - source 'docker-container.service.erb' + source service_template cookbook new_resource.cookbook mode '0644' owner 'root' @@ -222,7 +222,7 @@ def service_create_systemd def service_create_sysv template "/etc/init.d/#{service_name}" do - source 'docker-container.sysv.erb' + source service_template cookbook new_resource.cookbook mode '0755' owner 'root' @@ -238,7 +238,7 @@ def service_create_sysv def service_create_upstart template "/etc/init/#{service_name}.conf" do - source 'docker-container.conf.erb' + source service_template cookbook new_resource.cookbook mode '0600' owner 'root' @@ -305,6 +305,26 @@ def service_stop service_action([:stop]) end +def service_template + return new_resource.init_template unless new_resource.init_template.nil? + case new_resource.init_type + when 'systemd' + return 'docker-container.service.erb' + when 'upstart' + return 'docker-container.conf.erb' + when 'sysv' + return 'docker-container.sysv.erb' + end +end + +def socket_template + if new_resource.socket_template.nil? + return 'docker-container.socket.erb' + else + return new_resource.socket_template + end +end + def sockets return [] if port.empty? [*port].map { |p| p.gsub!(/.*:/, '') } diff --git a/resources/container.rb b/resources/container.rb index de05946fa6..bbef1c5988 100644 --- a/resources/container.rb +++ b/resources/container.rb @@ -19,6 +19,7 @@ attribute :hostname, :kind_of => [String] attribute :id, :kind_of => [String] attribute :init_type, :kind_of => [FalseClass, String], :default => node['docker']['container_init_type'] +attribute :init_template, :kind_of => [String] attribute :link, :kind_of => [String] attribute :lxc_conf, :kind_of => [String, Array] attribute :memory, :kind_of => [Fixnum] @@ -30,6 +31,7 @@ attribute :publish_exposed_ports, :kind_of => [TrueClass, FalseClass], :default => false attribute :remove_automatically, :kind_of => [TrueClass, FalseClass], :default => false attribute :running, :kind_of => [TrueClass, FalseClass] +attribute :socket_template, :kind_of => [String] attribute :stdin, :kind_of => [TrueClass, FalseClass] attribute :tty, :kind_of => [TrueClass, FalseClass] attribute :user, :kind_of => [String] From eba91fad609e3a420ed6eeed725131e2ba05c246 Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Thu, 2 Jan 2014 12:46:45 -0800 Subject: [PATCH 3/6] fix(typo): s/DEPRA/DEPRE/ --- providers/container.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/container.rb b/providers/container.rb index 9b43cf2546..91a5d55706 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -102,7 +102,7 @@ def exists? end def port - # DEPRACATED support for public_port attribute and Fixnum port + # DEPRECATED support for public_port attribute and Fixnum port if new_resource.public_port && new_resource.port.is_a?(Fixnum) "#{new_resource.public_port}:#{new_resource.port}" elsif new_resource.port && new_resource.port.is_a?(Fixnum) From 8d86816b539615c1072ba32d86258958a223129d Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Thu, 2 Jan 2014 13:30:17 -0800 Subject: [PATCH 4/6] fix(container): Remove unneccessary return & method - Remove method socket_template in favor of doing it inline - Remove unneccessary "return" statements. --- providers/container.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/providers/container.rb b/providers/container.rb index 91a5d55706..10f55293d9 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -193,7 +193,11 @@ def service_create def service_create_systemd template "/usr/lib/systemd/system/#{service_name}.socket" do - source socket_template + if new_resource.socket_template.nil? + source 'docker-container.socket.erb' + else + source new_resource.socket_template + end cookbook new_resource.cookbook mode '0644' owner 'root' @@ -306,22 +310,14 @@ def service_stop end def service_template - return new_resource.init_template unless new_resource.init_template.nil? + new_resource.init_template unless new_resource.init_template.nil? case new_resource.init_type when 'systemd' - return 'docker-container.service.erb' + 'docker-container.service.erb' when 'upstart' - return 'docker-container.conf.erb' + 'docker-container.conf.erb' when 'sysv' - return 'docker-container.sysv.erb' - end -end - -def socket_template - if new_resource.socket_template.nil? - return 'docker-container.socket.erb' - else - return new_resource.socket_template + 'docker-container.sysv.erb' end end From bdc093ce8dc809f94578cf63ee2bb7fdbe10d91b Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Thu, 2 Jan 2014 14:04:15 -0800 Subject: [PATCH 5/6] fix(servicetemplate) readd single return statement --- providers/container.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/container.rb b/providers/container.rb index 10f55293d9..d233383ef2 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -310,7 +310,7 @@ def service_stop end def service_template - new_resource.init_template unless new_resource.init_template.nil? + return new_resource.init_template unless new_resource.init_template.nil? case new_resource.init_type when 'systemd' 'docker-container.service.erb' From 1cd71332a262823dad503bed1c9d54e810c0a805 Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Thu, 2 Jan 2014 14:12:05 -0800 Subject: [PATCH 6/6] fix(whitespace): Fix whitespace for rubocop --- providers/container.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/container.rb b/providers/container.rb index d233383ef2..2e05691e25 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -195,7 +195,7 @@ def service_create_systemd template "/usr/lib/systemd/system/#{service_name}.socket" do if new_resource.socket_template.nil? source 'docker-container.socket.erb' - else + else source new_resource.socket_template end cookbook new_resource.cookbook