Skip to content

Commit

Permalink
Merge pull request #38 from jayofdoom/jay/InitTemplate
Browse files Browse the repository at this point in the history
Allow a user to specify a custom template for their container init configuration
  • Loading branch information
bflad committed Jan 2, 2014
2 parents 1f4edff + 1cd7133 commit 3913ca2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,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
Expand All @@ -133,6 +134,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
Expand Down
26 changes: 21 additions & 5 deletions providers/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -193,7 +193,11 @@ def service_create

def service_create_systemd
template "/usr/lib/systemd/system/#{service_name}.socket" do
source 'docker-container.socket.erb'
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'
Expand All @@ -206,7 +210,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'
Expand All @@ -222,7 +226,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'
Expand All @@ -238,7 +242,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'
Expand Down Expand Up @@ -305,6 +309,18 @@ 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'
'docker-container.service.erb'
when 'upstart'
'docker-container.conf.erb'
when 'sysv'
'docker-container.sysv.erb'
end
end

def sockets
return [] if port.empty?
[*port].map { |p| p.gsub!(/.*:/, '') }
Expand Down
4 changes: 3 additions & 1 deletion resources/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@
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]
# 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
attribute :public_port, :kind_of => [Fixnum]
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]
Expand Down

0 comments on commit 3913ca2

Please sign in to comment.