From 35cf47a1183143f0c95d2e621fae8230510b1c3e Mon Sep 17 00:00:00 2001 From: David Phayanouvong Date: Fri, 24 Feb 2023 18:20:39 +0100 Subject: [PATCH 1/5] Update docker compomse url download --- manifests/compose.pp | 22 +++++++++++++++++++++- manifests/params.pp | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/manifests/compose.pp b/manifests/compose.pp index a5e8a9c3..94648739 100644 --- a/manifests/compose.pp +++ b/manifests/compose.pp @@ -56,12 +56,17 @@ $docker_compose_location = "${install_path}/${symlink_name}${file_extension}" $docker_compose_location_versioned = "${install_path}/docker-compose-${version}${file_extension}" + $docker_plugins_path = '/usr/local/lib/docker/cli-plugins' if $ensure == 'present' { if $raw_url != undef { $docker_compose_url = $raw_url } else { - $docker_compose_url = "${base_url}/${version}/docker-compose-${facts['kernel']}-${facts['os']['hardware']}${file_extension}" + if $version =~ /2[.]\d+[.]\d+$/ { + $version_prepath = 'v' + } + + $docker_compose_url = "${base_url}/${version_prepath}${version}/docker-compose-${facts['kernel']}-${facts['os']['hardware']}${file_extension}" } if $proxy != undef { @@ -97,6 +102,15 @@ require => Package['curl'], } + file { '/usr/local/lib/docker': + ensure => directory, + } + + file { $docker_plugins_path: + ensure => directory, + require => File['/usr/local/lib/docker'], + } + file { $docker_compose_location_versioned: owner => $file_owner, mode => '0755', @@ -109,6 +123,12 @@ target => $docker_compose_location_versioned, require => File[$docker_compose_location_versioned], } + + file { "${docker_plugins_path}/docker-compose": + ensure => 'link', + target => $docker_compose_location_versioned, + require => File[$docker_plugins_path], + } } } else { file { $docker_compose_location_versioned: diff --git a/manifests/params.pp b/manifests/params.pp index c7d1e115..b85ce6ca 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -91,7 +91,7 @@ if ($facts['os']['family'] == 'windows') { $compose_install_path = "${facts['docker_program_files_path']}/Docker" - $compose_version = '1.29.2' + $compose_version = '2.16.0' $docker_ee_package_name = 'Docker' $machine_install_path = "${facts['docker_program_files_path']}/Docker" $tls_cacert = "${facts['docker_program_data_path']}/docker/certs.d/ca.pem" @@ -99,7 +99,7 @@ $tls_key = "${facts['docker_program_data_path']}/docker/certs.d/server-key.pem" } else { $compose_install_path = '/usr/local/bin' - $compose_version = '1.29.2' + $compose_version = '2.16.0' $docker_ee_package_name = 'docker-ee' $machine_install_path = '/usr/local/bin' $tls_cacert = '/etc/docker/tls/ca.pem' From eb5d680213d2e07b5e8a23113eebf2cda4a04c99 Mon Sep 17 00:00:00 2001 From: David Phayanouvong Date: Wed, 23 Aug 2023 10:34:41 +0200 Subject: [PATCH 2/5] Install compose as plugin on linux --- lib/puppet/provider/docker_compose/ruby.rb | 30 ++-- manifests/compose.pp | 160 +++++++++++---------- manifests/params.pp | 5 +- spec/shared_examples/compose.rb | 137 ++++++++++-------- 4 files changed, 175 insertions(+), 157 deletions(-) diff --git a/lib/puppet/provider/docker_compose/ruby.rb b/lib/puppet/provider/docker_compose/ruby.rb index 0d196d54..3b6e1808 100644 --- a/lib/puppet/provider/docker_compose/ruby.rb +++ b/lib/puppet/provider/docker_compose/ruby.rb @@ -9,7 +9,7 @@ has_command(:docker, 'docker') - has_command(:dockercompose, 'docker-compose') + has_command(:dockercompose, 'docker') def set_tmpdir return unless resource[:tmpdir] @@ -28,8 +28,8 @@ def exists? set_tmpdir # get merged config using docker-compose config - args = [compose_files, '-p', name, 'config'].insert(3, resource[:options]).compact - compose_output = Puppet::Util::Yaml.safe_load(execute([command(:dockercompose)] + args, combine: false), [Symbol]) + args = ['compose', compose_files, '-p', name, 'config'].insert(3, resource[:options]).compact + compose_output = Puppet::Util::Yaml.safe_load(execute([command(:docker)] + args, combine: false), [Symbol]) containers = docker([ 'ps', @@ -76,32 +76,32 @@ def get_image(service_name, compose_services) def create Puppet.info("Running compose project #{name}") - args = [compose_files, '-p', name, 'up', '-d', '--remove-orphans'].insert(3, resource[:options]).insert(5, resource[:up_args]).compact - dockercompose(args) + args = ['compose', compose_files, '-p', name, 'up', '-d', '--remove-orphans'].insert(3, resource[:options]).insert(5, resource[:up_args]).compact + docker(args) return unless resource[:scale] instructions = resource[:scale].map { |k, v| "#{k}=#{v}" } Puppet.info("Scaling compose project #{name}: #{instructions.join(' ')}") - args = [compose_files, '-p', name, 'scale'].insert(3, resource[:options]).compact + instructions - dockercompose(args) + args = ['compose', compose_files, '-p', name, 'scale'].insert(3, resource[:options]).compact + instructions + docker(args) end def destroy Puppet.info("Removing all containers for compose project #{name}") - kill_args = [compose_files, '-p', name, 'kill'].insert(3, resource[:options]).compact - dockercompose(kill_args) - rm_args = [compose_files, '-p', name, 'rm', '--force', '-v'].insert(3, resource[:options]).compact - dockercompose(rm_args) + kill_args = ['compose', compose_files, '-p', name, 'kill'].insert(3, resource[:options]).compact + docker(kill_args) + rm_args = ['compose', compose_files, '-p', name, 'rm', '--force', '-v'].insert(3, resource[:options]).compact + docker(rm_args) end def restart return unless exists? Puppet.info("Rebuilding and Restarting all containers for compose project #{name}") - kill_args = [compose_files, '-p', name, 'kill'].insert(3, resource[:options]).compact - dockercompose(kill_args) - build_args = [compose_files, '-p', name, 'build'].insert(3, resource[:options]).compact - dockercompose(build_args) + kill_args = ['compose', compose_files, '-p', name, 'kill'].insert(3, resource[:options]).compact + docker(kill_args) + build_args = ['compose', compose_files, '-p', name, 'build'].insert(3, resource[:options]).compact + docker(build_args) create end diff --git a/manifests/compose.pp b/manifests/compose.pp index 0d24c30c..431cff5a 100644 --- a/manifests/compose.pp +++ b/manifests/compose.pp @@ -42,103 +42,107 @@ Optional[String] $raw_url = undef, Optional[Boolean] $curl_ensure = $docker::params::curl_ensure, ) inherits docker::params { - if $facts['os']['family'] == 'windows' { - $file_extension = '.exe' - $file_owner = 'Administrator' - } else { - $file_extension = '' - $file_owner = 'root' - } - $docker_compose_location = "${install_path}/${symlink_name}${file_extension}" - $docker_compose_location_versioned = "${install_path}/docker-compose-${version}${file_extension}" - $docker_plugins_path = '/usr/local/lib/docker/cli-plugins' - - if $ensure == 'present' { - if $raw_url != undef { - $docker_compose_url = $raw_url - } else { - if $version =~ /2[.]\d+[.]\d+$/ { - $version_prepath = 'v' + if $facts['kernel'] == 'Linux' { + case $facts['os']['family'] { + 'Debian': { + ensure_packages('docker-compose-plugin', { ensure => pick($version,$ensure), require => defined(bool2str($docker::use_upstream_package_source)) ? { true => Apt::Source['docker'], false => undef } }) #lint:ignore:140chars } - - $docker_compose_url = "${base_url}/${version_prepath}${version}/docker-compose-${facts['kernel']}-${facts['os']['hardware']}${file_extension}" + 'RedHat': { + ensure_packages('docker-compose-plugin', { ensure => pick($version,$ensure), require => defined(bool2str($docker::use_upstream_package_source)) ? { true => Yumrepo['docker'], false => undef } }) #lint:ignore:140chars lint:ignore:unquoted_string_in_selector + } + default: {} } - - if $proxy != undef { - $proxy_opt = "--proxy ${proxy}" + } else { + # mac & Windows OS + if $facts['os']['family'] == 'windows' { + $file_extension = '.exe' + $file_owner = 'Administrator' } else { - $proxy_opt = '' + $file_extension = '' + $file_owner = 'root' } - if $facts['os']['family'] == 'windows' { - $docker_download_command = "if (Invoke-WebRequest ${docker_compose_url} ${proxy_opt} -UseBasicParsing -OutFile \"${docker_compose_location_versioned}\") { exit 0 } else { exit 1}" # lint:ignore:140chars + $docker_compose_location = "${install_path}/${symlink_name}${file_extension}" - $parameters = { - 'proxy' => $proxy, - 'docker_compose_url' => $docker_compose_url, - 'docker_compose_location_versioned' => $docker_compose_location_versioned, - } + if $version == 'latest' { + $version = "2.20.2" + } - exec { "Install Docker Compose ${version}": - command => epp('docker/windows/download_docker_compose.ps1.epp', $parameters), - provider => powershell, - creates => $docker_compose_location_versioned, - } + $docker_compose_location_versioned = "${install_path}/docker-compose-${version}${file_extension}" - file { $docker_compose_location: - ensure => 'link', - target => $docker_compose_location_versioned, - require => Exec["Install Docker Compose ${version}"], - } - } else { - if $curl_ensure { - stdlib::ensure_packages(['curl']) - } + if $ensure == 'present' { + if $raw_url != undef { + $docker_compose_url = $raw_url + } else { + if $version =~ /2[.]\d+[.]\d+$/ { + $version_prepath = 'v' + } - exec { "Install Docker Compose ${version}": - path => '/usr/bin/', - cwd => '/tmp', - command => "curl -s -S -L ${proxy_opt} ${docker_compose_url} -o ${docker_compose_location_versioned}", - creates => $docker_compose_location_versioned, - require => Package['curl'], + $docker_compose_url = "${base_url}/${version_prepath}${version}/docker-compose-${facts['kernel']}-${facts['os']['hardware']}${file_extension}" } - file { '/usr/local/lib/docker': - ensure => directory, + if $proxy != undef { + $proxy_opt = "--proxy ${proxy}" + } else { + $proxy_opt = '' } - file { $docker_plugins_path: - ensure => directory, - require => File['/usr/local/lib/docker'], - } + if $facts['os']['family'] == 'windows' { + $docker_download_command = "if (Invoke-WebRequest ${docker_compose_url} ${proxy_opt} -UseBasicParsing -OutFile \"${docker_compose_location_versioned}\") { exit 0 } else { exit 1}" # lint:ignore:140chars + $parameters = { + 'proxy' => $proxy, + 'docker_compose_url' => $docker_compose_url, + 'docker_compose_location_versioned' => $docker_compose_location_versioned, + } + + exec { "Install Docker Compose ${version}": + command => epp('docker/windows/download_docker_compose.ps1.epp', $parameters), + provider => powershell, + creates => $docker_compose_location_versioned, + } + + file { $docker_compose_location: + ensure => 'link', + target => $docker_compose_location_versioned, + require => Exec["Install Docker Compose ${version}"], + } + } else { + if $curl_ensure { + stdlib::ensure_packages(['curl']) + } + + exec { "Install Docker Compose ${version}": + path => '/usr/bin/', + cwd => '/tmp', + command => "curl -s -S -L ${proxy_opt} ${docker_compose_url} -o ${docker_compose_location_versioned}", + creates => $docker_compose_location_versioned, + require => Package['curl'], + } + + file { $docker_compose_location_versioned: + owner => $file_owner, + mode => '0755', + seltype => 'container_runtime_exec_t', + require => Exec["Install Docker Compose ${version}"], + } + + file { $docker_compose_location: + ensure => 'link', + target => $docker_compose_location_versioned, + require => File[$docker_compose_location_versioned], + } + } + + } else { file { $docker_compose_location_versioned: - owner => $file_owner, - mode => '0755', - seltype => 'container_runtime_exec_t', - require => Exec["Install Docker Compose ${version}"], + ensure => absent, } - + file { $docker_compose_location: - ensure => 'link', - target => $docker_compose_location_versioned, - require => File[$docker_compose_location_versioned], + ensure => absent, } - - file { "${docker_plugins_path}/docker-compose": - ensure => 'link', - target => $docker_compose_location_versioned, - require => File[$docker_plugins_path], - } - } - } else { - file { $docker_compose_location_versioned: - ensure => absent, - } - - file { $docker_compose_location: - ensure => absent, } } } diff --git a/manifests/params.pp b/manifests/params.pp index 4a4b9f0f..61f888a5 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -49,6 +49,8 @@ $proxy = undef $compose_base_url = 'https://github.com/docker/compose/releases/download' $compose_symlink_name = 'docker-compose' + $compose_version = 'latest' + $compose_install_path = undef $no_proxy = undef $execdriver = undef $storage_driver = undef @@ -91,15 +93,12 @@ if ($facts['os']['family'] == 'windows') { $compose_install_path = "${facts['docker_program_files_path']}/Docker" - $compose_version = '2.16.0' $docker_ee_package_name = 'Docker' $machine_install_path = "${facts['docker_program_files_path']}/Docker" $tls_cacert = "${facts['docker_program_data_path']}/docker/certs.d/ca.pem" $tls_cert = "${facts['docker_program_data_path']}/docker/certs.d/server-cert.pem" $tls_key = "${facts['docker_program_data_path']}/docker/certs.d/server-key.pem" } else { - $compose_install_path = '/usr/local/bin' - $compose_version = '2.16.0' $docker_ee_package_name = 'docker-ee' $machine_install_path = '/usr/local/bin' $tls_cacert = '/etc/docker/tls/ca.pem' diff --git a/spec/shared_examples/compose.rb b/spec/shared_examples/compose.rb index a34790c2..ca58c117 100644 --- a/spec/shared_examples/compose.rb +++ b/spec/shared_examples/compose.rb @@ -10,80 +10,95 @@ raw_url = _params['raw_url'] curl_ensure = _params['curl_ensure'] - if _facts[:os]['family'] == 'windows' - file_extension = '.exe' - file_owner = 'Administrator' + + if _facts[:kernel] == 'Linux' + case _facts['os']['family'] + when 'Debian' + + when 'RedHat' + + end + else - file_extension = '' - file_owner = 'root' - end + if _facts[:os]['family'] == 'windows' + file_owner = 'Administrator' + file_extension = '.exe' + else + file_owner = 'root' + file_extension = '' + end - docker_compose_location = "#{install_path}/#{symlink_name}#{file_extension}" - docker_compose_location_versioned = "#{install_path}/docker-compose-#{version}#{file_extension}" + docker_compose_location = "#{install_path}/#{symlink_name}#{file_extension}" - if ensure_value == 'present' - docker_compose_url = if raw_url == :undef + if version == 'latest' + version = "2.20.2" + end + + if ensure == 'present' + docker_compose_url = if raw_url == :undef "#{base_url}/#{version}/docker-compose-#{_facts[:kernel]}-x86_64#{file_extension}" else raw_url end - - proxy_opt = if proxy == :undef - '' - else - "--proxy #{proxy}" - end - - if _facts[:os]['family'] == 'windows' - docker_download_command = "if (Invoke-WebRequest #{docker_compose_url} #{proxy_opt} -UseBasicParsing -OutFile \"#{docker_compose_location_versioned}\") { exit 0 } else { exit 1 }" - - it { - expect(subject).to contain_exec("Install Docker Compose #{version}").with( - 'provider' => 'powershell', - 'creates' => docker_compose_location_versioned, - ) - - expect(subject).to contain_file(docker_compose_location).with( - 'ensure' => 'link', - 'target' => docker_compose_location_versioned, - ).that_requires( - "Exec[Install Docker Compose #{version}]", - ) - } - else - if curl_ensure + + proxy_opt = if proxy == :undef + '' + else + "--proxy #{proxy}" + end + + if _facts[:os]['family'] == 'windows' + docker_download_command = "if (Invoke-WebRequest #{docker_compose_url} #{proxy_opt} -UseBasicParsing -OutFile \"#{docker_compose_location_versioned}\") { exit 0 } else { exit 1 }" + it { - expect(subject).to contain_package('curl') + expect(subject).to contain_exec("Install Docker Compose #{version}").with( + 'provider' => 'powershell', + 'creates' => docker_compose_location_versioned, + ) + + expect(subject).to contain_file(docker_compose_location).with( + 'ensure' => 'link', + 'target' => docker_compose_location_versioned, + ).that_requires( + "Exec[Install Docker Compose #{version}]", + ) + } + else + if curl_ensure + it { + expect(subject).to contain_package('curl') + } + end + + it { + expect(subject).to contain_exec("Install Docker Compose #{version}").with( + 'path' => '/usr/bin/', + 'cwd' => '/tmp', + 'command' => "curl -s -S -L #{proxy_opt} #{docker_compose_url} -o #{docker_compose_location_versioned}", + 'creates' => docker_compose_location_versioned, + ).that_requires( + 'Package[curl]', + ) + + expect(subject).to contain_file(docker_compose_location_versioned).with( + 'owner' => file_owner, + 'mode' => '0755', + ).that_requires( + "Exec[Install Docker Compose #{version}]", + ) + + expect(subject).to contain_file(docker_compose_location).with( + 'ensure' => 'link', + 'target' => docker_compose_location_versioned, + ).that_requires( + "File[#{docker_compose_location_versioned}]", + ) } end - it { - expect(subject).to contain_exec("Install Docker Compose #{version}").with( - 'path' => '/usr/bin/', - 'cwd' => '/tmp', - 'command' => "curl -s -S -L #{proxy_opt} #{docker_compose_url} -o #{docker_compose_location_versioned}", - 'creates' => docker_compose_location_versioned, - ).that_requires( - 'Package[curl]', - ) - - expect(subject).to contain_file(docker_compose_location_versioned).with( - 'owner' => file_owner, - 'mode' => '0755', - ).that_requires( - "Exec[Install Docker Compose #{version}]", - ) - - expect(subject).to contain_file(docker_compose_location).with( - 'ensure' => 'link', - 'target' => docker_compose_location_versioned, - ).that_requires( - "File[#{docker_compose_location_versioned}]", - ) - } end - else + else it { expect(subject).to contain_file(docker_compose_location_versioned).with( 'ensure' => 'absent', From 7a05746c0f081f364fa1b0553563ef106ca8720f Mon Sep 17 00:00:00 2001 From: David Phayanouvong Date: Wed, 23 Aug 2023 13:45:46 +0200 Subject: [PATCH 3/5] Simplify compose install --- manifests/compose.pp | 141 ++++---------------------------- manifests/params.pp | 6 +- spec/shared_examples/compose.rb | 112 +++---------------------- 3 files changed, 27 insertions(+), 232 deletions(-) diff --git a/manifests/compose.pp b/manifests/compose.pp index 431cff5a..9be1860a 100644 --- a/manifests/compose.pp +++ b/manifests/compose.pp @@ -7,141 +7,30 @@ # @param version # The version of Docker Compose to install. # -# @param install_path -# The path where to install Docker Compose. -# -# @param symlink_name -# The name of the symlink created pointing to the actual docker-compose binary -# This allows use of own docker-compose wrapper scripts for the times it's -# necessary to set certain things before running the docker-compose binary -# -# @param proxy -# Proxy to use for downloading Docker Compose. -# -# @param base_url -# The base url for installation -# This allows use of a mirror that follows the same layout as the -# official repository -# -# @param raw_url -# Override the raw URL for installation -# The default is to build a URL from baseurl. If rawurl is set, the caller is -# responsible for ensuring the URL points to the correct version and -# architecture. -# -# @param curl_ensure -# Whether or not the curl package is ensured by this module. -# class docker::compose ( - Enum[present,absent] $ensure = present, - Optional[String] $version = $docker::params::compose_version, - Optional[String] $install_path = $docker::params::compose_install_path, - Optional[String] $symlink_name = $docker::params::compose_symlink_name, - Optional[Pattern['^((http[s]?)?:\/\/)?([^:^@]+:[^:^@]+@|)([\da-z\.-]+)\.([\da-z\.]{2,6})(:[\d])?([\/\w \.-]*)*\/?$']] $proxy = undef, - Optional[String] $base_url = $docker::params::compose_base_url, - Optional[String] $raw_url = undef, - Optional[Boolean] $curl_ensure = $docker::params::curl_ensure, + Enum[present,absent] $ensure = present, + Optional[String] $version = $docker::params::compose_version, ) inherits docker::params { - if $facts['kernel'] == 'Linux' { + if $docker::manage_package { + if $version and $ensure != 'absent' { + $package_ensure = $version + } else { + $package_ensure = $ensure + } + case $facts['os']['family'] { 'Debian': { - ensure_packages('docker-compose-plugin', { ensure => pick($version,$ensure), require => defined(bool2str($docker::use_upstream_package_source)) ? { true => Apt::Source['docker'], false => undef } }) #lint:ignore:140chars + ensure_packages('docker-compose-plugin', { ensure => $package_ensure, require => defined(bool2str($docker::use_upstream_package_source)) ? { true => Apt::Source['docker'], false => undef } }) #lint:ignore:140chars } 'RedHat': { - ensure_packages('docker-compose-plugin', { ensure => pick($version,$ensure), require => defined(bool2str($docker::use_upstream_package_source)) ? { true => Yumrepo['docker'], false => undef } }) #lint:ignore:140chars lint:ignore:unquoted_string_in_selector + ensure_packages('docker-compose-plugin', { ensure => $package_ensure, require => defined(bool2str($docker::use_upstream_package_source)) ? { true => Yumrepo['docker'], false => undef } }) #lint:ignore:140chars lint:ignore:unquoted_string_in_selector } - default: {} - } - } else { - # mac & Windows OS - if $facts['os']['family'] == 'windows' { - $file_extension = '.exe' - $file_owner = 'Administrator' - } else { - $file_extension = '' - $file_owner = 'root' - } - - $docker_compose_location = "${install_path}/${symlink_name}${file_extension}" - - if $version == 'latest' { - $version = "2.20.2" - } - - $docker_compose_location_versioned = "${install_path}/docker-compose-${version}${file_extension}" - - if $ensure == 'present' { - if $raw_url != undef { - $docker_compose_url = $raw_url - } else { - if $version =~ /2[.]\d+[.]\d+$/ { - $version_prepath = 'v' - } - - $docker_compose_url = "${base_url}/${version_prepath}${version}/docker-compose-${facts['kernel']}-${facts['os']['hardware']}${file_extension}" - } - - if $proxy != undef { - $proxy_opt = "--proxy ${proxy}" - } else { - $proxy_opt = '' + 'Windows': { + fail('Docker compose is installed with docker machine on Windows') } - - if $facts['os']['family'] == 'windows' { - $docker_download_command = "if (Invoke-WebRequest ${docker_compose_url} ${proxy_opt} -UseBasicParsing -OutFile \"${docker_compose_location_versioned}\") { exit 0 } else { exit 1}" # lint:ignore:140chars - - $parameters = { - 'proxy' => $proxy, - 'docker_compose_url' => $docker_compose_url, - 'docker_compose_location_versioned' => $docker_compose_location_versioned, - } - - exec { "Install Docker Compose ${version}": - command => epp('docker/windows/download_docker_compose.ps1.epp', $parameters), - provider => powershell, - creates => $docker_compose_location_versioned, - } - - file { $docker_compose_location: - ensure => 'link', - target => $docker_compose_location_versioned, - require => Exec["Install Docker Compose ${version}"], - } - } else { - if $curl_ensure { - stdlib::ensure_packages(['curl']) - } - - exec { "Install Docker Compose ${version}": - path => '/usr/bin/', - cwd => '/tmp', - command => "curl -s -S -L ${proxy_opt} ${docker_compose_url} -o ${docker_compose_location_versioned}", - creates => $docker_compose_location_versioned, - require => Package['curl'], - } - - file { $docker_compose_location_versioned: - owner => $file_owner, - mode => '0755', - seltype => 'container_runtime_exec_t', - require => Exec["Install Docker Compose ${version}"], - } - - file { $docker_compose_location: - ensure => 'link', - target => $docker_compose_location_versioned, - require => File[$docker_compose_location_versioned], - } - } - - } else { - file { $docker_compose_location_versioned: - ensure => absent, - } - - file { $docker_compose_location: - ensure => absent, + default: { + fail('This module only works on Debian, RedHat or Windows.') } } } diff --git a/manifests/params.pp b/manifests/params.pp index 61f888a5..86984dd9 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -47,10 +47,7 @@ $dns = undef $dns_search = undef $proxy = undef - $compose_base_url = 'https://github.com/docker/compose/releases/download' - $compose_symlink_name = 'docker-compose' - $compose_version = 'latest' - $compose_install_path = undef + $compose_version = undef $no_proxy = undef $execdriver = undef $storage_driver = undef @@ -92,7 +89,6 @@ $docker_command = 'docker' if ($facts['os']['family'] == 'windows') { - $compose_install_path = "${facts['docker_program_files_path']}/Docker" $docker_ee_package_name = 'Docker' $machine_install_path = "${facts['docker_program_files_path']}/Docker" $tls_cacert = "${facts['docker_program_data_path']}/docker/certs.d/ca.pem" diff --git a/spec/shared_examples/compose.rb b/spec/shared_examples/compose.rb index ca58c117..0d72a255 100644 --- a/spec/shared_examples/compose.rb +++ b/spec/shared_examples/compose.rb @@ -3,110 +3,20 @@ shared_examples 'compose' do |_params, _facts| ensure_value = _params['ensure'] version = _params['version'] - install_path = _params['install_path'] - symlink_name = _params['symlink_name'] - proxy = _params['proxy'] - base_url = _params['base_url'] - raw_url = _params['raw_url'] - curl_ensure = _params['curl_ensure'] + if _params['manage_package'] + ensure_value = if _params['version'] != :undef && _params['ensure'] != 'absent' + _params['version'] + else + _params['ensure'] + end - if _facts[:kernel] == 'Linux' case _facts['os']['family'] - when 'Debian' - - when 'RedHat' - - end - - else - if _facts[:os]['family'] == 'windows' - file_owner = 'Administrator' - file_extension = '.exe' - else - file_owner = 'root' - file_extension = '' - end - - docker_compose_location = "#{install_path}/#{symlink_name}#{file_extension}" - - if version == 'latest' - version = "2.20.2" - end - - if ensure == 'present' - docker_compose_url = if raw_url == :undef - "#{base_url}/#{version}/docker-compose-#{_facts[:kernel]}-x86_64#{file_extension}" - else - raw_url - end - - proxy_opt = if proxy == :undef - '' - else - "--proxy #{proxy}" - end - - if _facts[:os]['family'] == 'windows' - docker_download_command = "if (Invoke-WebRequest #{docker_compose_url} #{proxy_opt} -UseBasicParsing -OutFile \"#{docker_compose_location_versioned}\") { exit 0 } else { exit 1 }" - - it { - expect(subject).to contain_exec("Install Docker Compose #{version}").with( - 'provider' => 'powershell', - 'creates' => docker_compose_location_versioned, - ) - - expect(subject).to contain_file(docker_compose_location).with( - 'ensure' => 'link', - 'target' => docker_compose_location_versioned, - ).that_requires( - "Exec[Install Docker Compose #{version}]", + when 'Debian', 'RedHat' + it { + is_expected.to contain_package('docker-compose-plugin').with( + ensure: ensure_value, ) - } - else - if curl_ensure - it { - expect(subject).to contain_package('curl') - } - end - - it { - expect(subject).to contain_exec("Install Docker Compose #{version}").with( - 'path' => '/usr/bin/', - 'cwd' => '/tmp', - 'command' => "curl -s -S -L #{proxy_opt} #{docker_compose_url} -o #{docker_compose_location_versioned}", - 'creates' => docker_compose_location_versioned, - ).that_requires( - 'Package[curl]', - ) - - expect(subject).to contain_file(docker_compose_location_versioned).with( - 'owner' => file_owner, - 'mode' => '0755', - ).that_requires( - "Exec[Install Docker Compose #{version}]", - ) - - expect(subject).to contain_file(docker_compose_location).with( - 'ensure' => 'link', - 'target' => docker_compose_location_versioned, - ).that_requires( - "File[#{docker_compose_location_versioned}]", - ) - } - end - - end - - else - it { - expect(subject).to contain_file(docker_compose_location_versioned).with( - 'ensure' => 'absent', - ) - - expect(subject).to contain_file(docker_compose_location).with( - 'ensure' => 'absent', - ) - } + } end end From e38bede4424050f84b7dddd4549c3790be4b492b Mon Sep 17 00:00:00 2001 From: David Phayanouvong Date: Wed, 23 Aug 2023 13:51:49 +0200 Subject: [PATCH 4/5] clean class compose_spec.rb --- spec/classes/compose_spec.rb | 39 +----------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/spec/classes/compose_spec.rb b/spec/classes/compose_spec.rb index 84835fc2..9927bb45 100644 --- a/spec/classes/compose_spec.rb +++ b/spec/classes/compose_spec.rb @@ -10,29 +10,6 @@ 'with version => 1.7.0' => { 'version' => '1.7.0' }, - 'when proxy is provided' => { - 'version' => '1.7.0', - 'proxy' => 'http://proxy.example.org:3128/' - }, - 'when proxy is not a http proxy' => { - 'proxy' => 'this is not a URL' - }, - 'when proxy contains username and password' => { - 'version' => '1.7.0', - 'proxy' => 'http://user:password@proxy.example.org:3128/' - }, - 'when proxy IP is provided' => { - 'version' => '1.7.0', - 'proxy' => 'http://10.10.10.10:3128/' - }, - 'when base_url is provided' => { - 'version' => '1.7.0', - 'base_url' => 'http://example.org' - }, - 'when raw_url is provided' => { - 'version' => '1.7.0', - 'raw_url' => 'http://example.org' - } } describe 'docker::compose', type: :class do @@ -57,12 +34,6 @@ params = { 'ensure' => 'present', 'version' => defaults['compose_version'], - 'install_path' => defaults['compose_install_path'], - 'symlink_name' => defaults['compose_symlink_name'], - 'proxy' => :undef, - 'base_url' => defaults['compose_base_url'], - 'raw_url' => :undef, - 'curl_ensure' => defaults['curl_ensure'] }.merge(local_params) let(:facts) do @@ -73,15 +44,7 @@ params end - if title == 'when proxy is not a http proxy' - it 'raises an error for invalid proxy URL' do - expect(subject).to compile.and_raise_error( - %r{parameter 'proxy' expects an undef value or a match for Pattern}, - ) - end - else - include_examples 'compose', params, facts - end + include_examples 'compose', params, facts end end end From 6277484f0387f863ab6113190fea644200e305de Mon Sep 17 00:00:00 2001 From: David Phayanouvong Date: Fri, 25 Aug 2023 09:30:45 +0200 Subject: [PATCH 5/5] Fix linting issue --- manifests/compose.pp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manifests/compose.pp b/manifests/compose.pp index 9be1860a..f8e56ca3 100644 --- a/manifests/compose.pp +++ b/manifests/compose.pp @@ -11,14 +11,13 @@ Enum[present,absent] $ensure = present, Optional[String] $version = $docker::params::compose_version, ) inherits docker::params { - if $docker::manage_package { if $version and $ensure != 'absent' { $package_ensure = $version } else { $package_ensure = $ensure } - + case $facts['os']['family'] { 'Debian': { ensure_packages('docker-compose-plugin', { ensure => $package_ensure, require => defined(bool2str($docker::use_upstream_package_source)) ? { true => Apt::Source['docker'], false => undef } }) #lint:ignore:140chars