Skip to content

Commit

Permalink
add support for ubuntu 14.04
Browse files Browse the repository at this point in the history
  • Loading branch information
garethr committed Aug 16, 2014
1 parent ab504a1 commit bbc8016
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 53 deletions.
18 changes: 9 additions & 9 deletions manifests/image.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
# [*image_tag*]
# If you want a specific tag of the image to be installed
#
#
define docker::image(
$ensure = 'present',
$image = $title,
$image_tag = undef
$image_tag = undef,
) {

include docker::params
$docker_command = $docker::params::docker_command
validate_re($ensure, '^(present|absent|latest)$')
validate_re($image, '^[\S]*$')

if $image_tag {
$image_install = "docker pull -t=\"${image_tag}\" ${image}"
$image_remove = "docker rmi ${image}:${image_tag}"
$image_find = "docker images | grep ^${image} | awk '{ print \$2 }' | grep ${image_tag}"
$image_install = "${docker_command} pull -t=\"${image_tag}\" ${image}"
$image_remove = "${docker_command} rmi ${image}:${image_tag}"
$image_find = "${docker_command} images | grep ^${image} | awk '{ print \$2 }' | grep ${image_tag}"
} else {
$image_install = "docker pull ${image}"
$image_remove = "docker rmi ${image}"
$image_find = "docker images | grep ^${image}"
$image_install = "${docker_command} pull ${image}"
$image_remove = "${docker_command} rmi ${image}"
$image_find = "${docker_command} images | grep ^${image}"
}

if $ensure == 'absent' {
Expand Down
10 changes: 10 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
# Specify custom package name
# Default is set on a per system basis in docker::params
#
# [*service_name*]
# Specify custom service name
# Default is set on a per system basis in docker::params
#
# [*docker_command*]
# Specify a custom docker command name
# Default is set on a per system basis in docker::params
#
class docker(
$version = $docker::params::version,
$ensure = $docker::params::ensure,
Expand All @@ -93,6 +101,8 @@
$execdriver = $docker::params::execdriver,
$manage_package = $docker::params::manage_package,
$package_name = $docker::params::package_name,
$service_name = $docker::params::service_name,
$docker_command = $docker::params::docker_command,
) inherits docker::params {

validate_string($version)
Expand Down
4 changes: 0 additions & 4 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

case $::osfamily {
'Debian': {

ensure_packages($prerequired_packages)
if $docker::manage_package {
Package['apt-transport-https'] -> Package['docker']
Expand All @@ -30,9 +29,7 @@
$dockerpackage = $docker::package_name
}


if ($docker::use_upstream_package_source) {

include apt
apt::source { 'docker':
location => $docker::package_source_location,
Expand Down Expand Up @@ -67,7 +64,6 @@
# on the $::kernelrelease fact
default: { $kernelpackage = "linux-image-extra-${::kernelrelease}" }
}

$manage_kernel = $docker::manage_kernel
} else {
# Debian does not need extra kernel packages
Expand Down
29 changes: 19 additions & 10 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,40 @@
$storage_driver = undef
$manage_package = true
$manage_kernel = true
$package_name_default = 'docker.io'
$package_name_default = 'lxc-docker'
$service_name_default = 'docker'
$docker_command_default = 'docker'
case $::osfamily {
'Debian' : {
case $::operatingsystem {
'Ubuntu' : {
case $::operatingsystemrelease {
'10.04','12.04','13.04','13.10' : { $package_name = 'lxc-docker' }
default: {
$package_name = $package_name_default
}
}
$package_name = $package_name_default
$service_name = $service_name_default
$docker_command = $docker_command_default
}
default: {
$package_name = $package_name_default
$package_name = 'docker.io'
$service_name = 'docker.io'
$docker_command = 'docker.io'
}
}
$package_source_location = 'https://get.docker.io/ubuntu'
}
'RedHat' : {
if (versioncmp($::operatingsystemrelease, '7.0') < 0) {
$package_name = 'docker-io'
} else {
$package_name = 'docker'
}
$package_source_location = ''
$package_name = 'docker-io'
$service_name = $service_name_default
$docker_command = $docker_command_default
}
default: {
$package_source_location = ''
$package_name = $package_name_default
$package_name = $package_name_default
$service_name = $service_name_default
$docker_command = $docker_command_default
}
}
}
6 changes: 6 additions & 0 deletions manifests/run.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
$disable_network = false,
$privileged = false,
) {
include docker::params
$docker_command = $docker::params::docker_command
$service_name = $docker::params::service_name

validate_re($image, '^[\S]*$')
validate_re($title, '^[\S]*$')
validate_re($memory_limit, '^[\d]*$')
validate_string($docker_command)
validate_string($service_name)
if $command {
validate_string($command)
}
Expand Down
2 changes: 2 additions & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# Plain additional parameters to pass to the docker daemon
#
class docker::service (
$service_name = $docker::service_name,
$tcp_bind = $docker::tcp_bind,
$socket_bind = $docker::socket_bind,
$socket_group = $docker::socket_group,
Expand Down Expand Up @@ -74,6 +75,7 @@

service { 'docker':
ensure => $service_state,
name => $service_name,
enable => $service_enable,
hasstatus => $hasstatus,
hasrestart => $hasrestart,
Expand Down
10 changes: 6 additions & 4 deletions spec/acceptance/docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
else
package_name = 'lxc-docker'
end
service_name = 'docker'
command = 'docker'

context 'default parameters' do
it 'should work with no errors' do
Expand All @@ -28,22 +30,22 @@ class { 'docker': }
it { should be_installed }
end

describe service('docker') do
describe service(service_name) do
it { should be_enabled }
it { should be_running }
end

describe command('docker version') do
describe command("#{command} version") do
it { should return_exit_status 0 }
it { should return_stdout(/Client version: /) }
end

describe command('sudo docker images') do
describe command("sudo #{command} images") do
it { should return_exit_status 0 }
it { should return_stdout(/nginx/) }
end

describe command('sudo docker ps -l --no-trunc=true') do
describe command("sudo #{command} ps -l --no-trunc=true") do
it { should return_exit_status 0 }
it { should return_stdout(/nginx\:1/) }
end
Expand Down
37 changes: 27 additions & 10 deletions spec/classes/docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:lsbdistid => 'Ubuntu',
:lsbdistcodename => 'maverick',
:kernelrelease => '3.8.0-29-generic',
:operatingsystemrelease => '10.04',
:operatingsystemrelease => '10.04',
} }
service_config_file = '/etc/default/docker'

Expand All @@ -27,20 +27,19 @@
it { should contain_package('docker').with_name('lxc-docker-0.5.5').with_ensure('present') }
end

context 'with a custom package name' do
context 'with a custom package name' do
let(:params) { {'package_name' => 'docker-custom-pkg-name' } }
it { should contain_package('docker').with_name('docker-custom-pkg-name').with_ensure('present') }
end

context 'with a custom package name and version' do
let(:params) { {
'version' => '0.5.5',
'package_name' => 'docker-custom-pkg-name',
} }
context 'with a custom package name and version' do
let(:params) { {
'version' => '0.5.5',
'package_name' => 'docker-custom-pkg-name',
} }
it { should contain_package('docker').with_name('docker-custom-pkg-name-0.5.5').with_ensure('present') }
end


context 'when not managing the package' do
let(:params) { {'manage_package' => false } }
it { should_not contain_package('docker') }
Expand Down Expand Up @@ -96,6 +95,11 @@
it { should contain_class('docker::service').that_subscribes_to('docker::config') }
it { should contain_class('docker::config') }

context 'with a specific docker command' do
let(:params) {{ 'docker_command' => 'docker.io' }}
it { should contain_file(service_config_file).with_content(/docker.io/) }
end

context 'with proxy param' do
let(:params) { {'proxy' => 'http://127.0.0.1:3128' } }
it { should contain_file(service_config_file).with_content(/export http_proxy=http:\/\/127.0.0.1:3128\nexport https_proxy=http:\/\/127.0.0.1:3128/) }
Expand Down Expand Up @@ -147,6 +151,11 @@
it { should contain_service('docker').with_ensure('stopped') }
end

context 'with a custom service name' do
let(:params) { {'service_name' => 'docker.io'} }
it { should contain_service('docker').with_name('docker.io') }
end

context 'with service_enable set to false' do
let(:params) { {'service_enable' => 'false'} }
it { should contain_service('docker').with_enable('false') }
Expand Down Expand Up @@ -234,6 +243,15 @@
end
end

context 'specific to RedHat 7 or above' do
let(:facts) { {
:osfamily => 'RedHat',
:operatingsystemrelease => '7.0'
} }

it { should contain_package('docker').with_name('docker') }
end

context 'specific to Ubuntu Precise' do
let(:facts) { {
:osfamily => 'Debian',
Expand All @@ -258,7 +276,7 @@
:kernelrelease => '3.8.0-29-generic'
} }
it { should contain_service('docker').with_provider('upstart') }
it { should contain_package('docker').with_name('docker.io').with_ensure('present') }
it { should contain_package('docker').with_name('lxc-docker').with_ensure('present') }
end


Expand All @@ -283,5 +301,4 @@
end
end


end
8 changes: 5 additions & 3 deletions spec/defines/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@

if osfamily == 'Debian'
initscript = '/etc/init/docker-sample.conf'
command = 'docker.io'
else
initscript = '/etc/init.d/docker-sample'
command = 'docker'
end

context 'passing the required params' do
let(:params) { {'command' => 'command', 'image' => 'base'} }
it { should contain_file(initscript).with_content(/docker run/).with_content(/base/) }
it { should contain_file(initscript).with_content(/docker run/).with_content(/command/) }
it { should contain_file(initscript).with_content(/#{command} run/).with_content(/base/) }
it { should contain_file(initscript).with_content(/#{command} run/).with_content(/command/) }
it { should contain_service('docker-sample') }
if (osfamily == 'Debian')
it { should contain_service('docker-sample').with_hasrestart('false') }
it { should contain_service('docker-sample').with_hasrestart('false') }
end

['p', 'dns', 'u', 'v', 'e', 'n', 'volumes-from', 'name'].each do |search|
Expand Down
2 changes: 1 addition & 1 deletion templates/etc/default/docker.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# THIS FILE IS MANAGED BY PUPPET. Changes will be overwritten.

# # Customize location of Docker binary (especially for development testing).
# #DOCKER="/usr/local/bin/docker"
DOCKER="/usr/bin/<%= @docker_command %>"

# # If you need Docker to use an HTTP proxy, it can also be specified here.
<% if @proxy -%>
Expand Down
6 changes: 3 additions & 3 deletions templates/etc/init.d/docker-run.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

. /etc/init.d/functions

docker="/usr/bin/docker"
docker="/usr/bin/<%= docker_command %>"
prog="docker-<%= @title %>"
cidfile="/var/run/$prog.cid"
lockfile="/var/lock/subsys/$prog"
Expand All @@ -35,7 +35,7 @@ start() {
if [ -f $cidfile ]; then
cid="$(cat $cidfile)"
if [ -n "$cid" ]; then
docker ps --no-trunc=true|grep $cid
$docker ps --no-trunc=true|grep $cid
retval=$?
if [ $retval -eq 0 ]; then
failure
Expand Down Expand Up @@ -101,7 +101,7 @@ stop() {
cid="$(cat $cidfile)"
if [ -n $cid ]; then
echo -n $"Stopping $prog: "
docker stop $(cat $cidfile)
$docker stop $(cat $cidfile)
retval=$?
[ $retval -eq 0 ] && rm -f $lockfile $cidfile
return $retval
Expand Down
Loading

0 comments on commit bbc8016

Please sign in to comment.