Skip to content

Commit

Permalink
Added option to override docker-compose download location (#482)
Browse files Browse the repository at this point in the history
* Added option to override docker-compose download location

* Allow docker-compose to be downloaded from a complete raw-url

* Added comment for var

* fix trailing slash

* Added tests for base_url and raw_url

* Fix typo in comments

* Updated tests to contain correct amount of spaces

* Syntax-fix
  • Loading branch information
piquet90 authored and florindragos committed Jul 15, 2019
1 parent fff84b2 commit 387523b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
22 changes: 20 additions & 2 deletions manifests/compose.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,24 @@
# [*proxy*]
# Proxy to use for downloading Docker Compose.
#
# [*base_url*]
# The base url for installation
# This allows use of a mirror that follows the same layout as the
# official repository
#
# [*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.

class docker::compose(
Optional[Pattern[/^present$|^absent$/]] $ensure = 'present',
Optional[String] $version = $docker::params::compose_version,
Optional[String] $install_path = $docker::params::compose_install_path,
Optional[String] $proxy = undef
Optional[String] $proxy = undef,
Optional[String] $base_url = $docker::params::compose_base_url,
Optional[String] $raw_url = undef
) inherits docker::params {

if $proxy != undef {
Expand All @@ -43,7 +56,12 @@
$docker_compose_location_versioned = "${install_path}/docker-compose-${version}${file_extension}"

if $ensure == 'present' {
$docker_compose_url = "https://github.com/docker/compose/releases/download/${version}/docker-compose-${::kernel}-x86_64${file_extension}"

if $raw_url != undef {
$docker_compose_url = $raw_url
} else {
$docker_compose_url = "${base_url}/${version}/docker-compose-${::kernel}-x86_64${file_extension}"
}

if $proxy != undef {
$proxy_opt = "--proxy ${proxy}"
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
$dns = undef
$dns_search = undef
$proxy = undef
$compose_base_url = 'https://github.com/docker/compose/releases/download'
$no_proxy = undef
$execdriver = undef
$storage_driver = undef
Expand Down
28 changes: 28 additions & 0 deletions spec/classes/compose_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,32 @@
)
}
end

context 'when base_url is provided' do
let(:params) do
{ base_url: 'http://example.org',
version: '1.7.0' }
end

it { is_expected.to compile }
it {
is_expected.to contain_exec('Install Docker Compose 1.7.0').with_command(
'curl -s -S -L http://example.org/1.7.0/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose-1.7.0',
)
}
end

context 'when raw_url is provided' do
let(:params) do
{ raw_url: 'http://example.org',
version: '1.7.0' }
end

it { is_expected.to compile }
it {
is_expected.to contain_exec('Install Docker Compose 1.7.0').with_command(
'curl -s -S -L http://example.org -o /usr/local/bin/docker-compose-1.7.0',
)
}
end
end

0 comments on commit 387523b

Please sign in to comment.