Skip to content

Commit

Permalink
Merge pull request garethr#740 from kenyon/manage-docker-ce-cli
Browse files Browse the repository at this point in the history
Allow management of the docker-ce-cli package
  • Loading branch information
adrianiurca authored Jun 28, 2021
2 parents cd7ec59 + b85e450 commit cde2715
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 34 deletions.
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ The following parameters are available in the `docker` class:
* [`docker_msft_provider_version`](#docker_msft_provider_version)
* [`docker_ce_start_command`](#docker_ce_start_command)
* [`docker_ce_package_name`](#docker_ce_package_name)
* [`docker_ce_cli_package_name`](#docker_ce_cli_package_name)
* [`docker_ce_source_location`](#docker_ce_source_location)
* [`docker_ce_key_source`](#docker_ce_key_source)
* [`docker_ce_key_id`](#docker_ce_key_id)
Expand Down Expand Up @@ -926,6 +927,14 @@ Data type: `Optional[String]`

Default value: `$docker::params::docker_ce_package_name`

##### <a name="docker_ce_cli_package_name"></a>`docker_ce_cli_package_name`

Data type: `String[1]`



Default value: `$docker::params::docker_ce_cli_package_name`

##### <a name="docker_ce_source_location"></a>`docker_ce_source_location`

Data type: `Optional[String]`
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
#
# @param docker_ce_start_command
# @param docker_ce_package_name
# @param docker_ce_cli_package_name
# @param docker_ce_source_location
# @param docker_ce_key_source
# @param docker_ce_key_id
Expand Down Expand Up @@ -363,6 +364,7 @@
Array $dependent_packages = $docker::params::dependent_packages,
String $docker_ce_start_command = $docker::params::docker_ce_start_command,
Optional[String] $docker_ce_package_name = $docker::params::docker_ce_package_name,
String[1] $docker_ce_cli_package_name = $docker::params::docker_ce_cli_package_name,
Optional[String] $docker_ce_source_location = $docker::params::package_ce_source_location,
Optional[String] $docker_ce_key_source = $docker::params::package_ce_key_source,
Optional[String] $docker_ce_key_id = $docker::params::package_ce_key_id,
Expand Down
38 changes: 17 additions & 21 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,27 @@
}

if $docker::package_source {
case $facts['os']['family'] {
'Debian' : {
$pk_provider = 'dpkg'
}
'RedHat' : {
$pk_provider = 'yum'
}
'windows' : {
fail('Custom package source is currently not implemented on windows.')
}
default : {
$pk_provider = undef
}
if $facts['os']['family'] == 'windows' {
fail('Custom package source is currently not implemented on windows.')
}
case $docker::package_source {
/docker-engine/ : {
ensure_resource('package', 'docker', merge($docker_hash, {
ensure => $ensure,
provider => $pk_provider,
source => $docker::package_source,
name => $docker::docker_engine_package_name,
ensure => $ensure,
source => $docker::package_source,
name => $docker::docker_engine_package_name,
}))
}
/docker-ce/ : {
ensure_resource('package', 'docker', merge($docker_hash, {
ensure => $ensure,
provider => $pk_provider,
source => $docker::package_source,
name => $docker::docker_ce_package_name,
ensure => $ensure,
source => $docker::package_source,
name => $docker::docker_ce_package_name,
}))
ensure_resource('package', 'docker-ce-cli', merge($docker_hash, {
ensure => $ensure,
source => $docker::package_source,
name => $docker::docker_ce_cli_package_name,
}))
}
default : {}
Expand All @@ -88,6 +80,10 @@
ensure => $ensure,
name => $docker::docker_package_name,
}))
ensure_resource('package', 'docker-ce-cli', merge($docker_hash, {
ensure => $ensure,
name => $docker::docker_ce_cli_package_name,
}))

if $ensure == 'absent' {
ensure_resource('package', $dependent_packages, {
Expand Down
3 changes: 2 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$ensure = present
$docker_ce_start_command = 'dockerd'
$docker_ce_package_name = 'docker-ce'
$docker_ce_cli_package_name = 'docker-ce-cli'
$docker_engine_start_command = 'docker daemon'
$docker_engine_package_name = 'docker-engine'
$docker_ce_channel = stable
Expand Down Expand Up @@ -372,7 +373,7 @@
default => [],
}

$dependent_packages = [ 'docker-ce-cli', 'containerd.io', ]
$dependent_packages = [ $docker_ce_cli_package_name, 'containerd.io', ]

if($service_provider == 'systemd') {
# systemd v230 adds new StartLimitIntervalSec, StartLimitBurst
Expand Down
1 change: 1 addition & 0 deletions spec/classes/init_spec.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
'docker_ce_key_id' => defaults['package_ce_key_id'],
'docker_ce_key_source' => defaults['package_ce_key_source'],
'docker_ce_package_name' => defaults['docker_ce_package_name'],
'docker_ce_cli_package_name' => defaults['docker_ce_cli_package_name'],
'docker_ce_release' => defaults['package_ce_release'],
'docker_ce_source_location' => defaults['package_ce_source_location'],
'docker_ce_start_command' => defaults['docker_ce_start_command'],
Expand Down
4 changes: 3 additions & 1 deletion spec/helper/get_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def get_defaults(_facts)
dns_search = :undef
docker_ce_channel = 'stable'
docker_ce_package_name = 'docker-ce'
docker_ce_cli_package_name = 'docker-ce-cli'
docker_ce_start_command = 'dockerd'
docker_command = 'docker'
docker_ee = false
Expand Down Expand Up @@ -343,7 +344,7 @@ def get_defaults(_facts)
apt_source_pin_level = :undef
end

dependent_packages = ['docker-ce-cli', 'containerd.io']
dependent_packages = [docker_ce_cli_package_name, 'containerd.io']

prerequired_packages = case _facts[:os]['family']
when 'Debian'
Expand Down Expand Up @@ -392,6 +393,7 @@ def get_defaults(_facts)
'dns_search' => dns_search,
'docker_ce_channel' => docker_ce_channel,
'docker_ce_package_name' => docker_ce_package_name,
'docker_ce_cli_package_name' => docker_ce_cli_package_name,
'docker_ce_start_command' => docker_ce_start_command,
'docker_command' => docker_command,
'docker_ee' => docker_ee,
Expand Down
26 changes: 15 additions & 11 deletions spec/shared_examples/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,12 @@
is_expected.to contain_class('docker::install')
}

provider_value = case _facts[:os]['family']
when 'Debian'
'dpkg'
when 'RedHat'
'yum'
else
:undef
end

case _params['package_source']
when 'docker-engine'
it {
is_expected.to contain_package('docker').with(
{
'ensure' => ensure_value,
'provider' => provider_value,
'source' => _params['package_source'],
'name' => _params['docker_engine_package_name'],
}.merge(docker_hash),
Expand All @@ -47,12 +37,20 @@
is_expected.to contain_package('docker').with(
{
'ensure' => ensure_value,
'provider' => provider_value,
'source' => _params['package_source'],
'name' => _params['docker_ce_package_name'],
}.merge(docker_hash),
)
}
it {
is_expected.to contain_package('docker-ce-cli').with(
{
'ensure' => ensure_value,
'source' => _params['package_source'],
'name' => _params['docker_ce_cli_package_name'],
}.merge(docker_hash),
)
}
end
elsif _facts[:os]['family'] != 'windows'
it {
Expand All @@ -61,6 +59,12 @@
'name' => values['docker_package_name'],
)
}
it {
is_expected.to contain_package('docker-ce-cli').with(
'ensure' => ensure_value,
'name' => _params['docker_ce_cli_package_name'],
)
}

if ensure_value == 'absent'
_params['dependent_packages'].each do |dependent_package|
Expand Down

0 comments on commit cde2715

Please sign in to comment.