Skip to content

Commit 387523b

Browse files
piquet90florindragos
authored andcommitted
Added option to override docker-compose download location (#482)
* 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
1 parent fff84b2 commit 387523b

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

manifests/compose.pp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,24 @@
2020
# [*proxy*]
2121
# Proxy to use for downloading Docker Compose.
2222
#
23+
# [*base_url*]
24+
# The base url for installation
25+
# This allows use of a mirror that follows the same layout as the
26+
# official repository
27+
#
28+
# [*raw_url*]
29+
# Override the raw URL for installation
30+
# The default is to build a URL from baseurl. If rawurl is set, the caller is
31+
# responsible for ensuring the URL points to the correct version and
32+
# architecture.
33+
2334
class docker::compose(
2435
Optional[Pattern[/^present$|^absent$/]] $ensure = 'present',
2536
Optional[String] $version = $docker::params::compose_version,
2637
Optional[String] $install_path = $docker::params::compose_install_path,
27-
Optional[String] $proxy = undef
38+
Optional[String] $proxy = undef,
39+
Optional[String] $base_url = $docker::params::compose_base_url,
40+
Optional[String] $raw_url = undef
2841
) inherits docker::params {
2942

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

4558
if $ensure == 'present' {
46-
$docker_compose_url = "https://github.com/docker/compose/releases/download/${version}/docker-compose-${::kernel}-x86_64${file_extension}"
59+
60+
if $raw_url != undef {
61+
$docker_compose_url = $raw_url
62+
} else {
63+
$docker_compose_url = "${base_url}/${version}/docker-compose-${::kernel}-x86_64${file_extension}"
64+
}
4765

4866
if $proxy != undef {
4967
$proxy_opt = "--proxy ${proxy}"

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
$dns = undef
6969
$dns_search = undef
7070
$proxy = undef
71+
$compose_base_url = 'https://github.com/docker/compose/releases/download'
7172
$no_proxy = undef
7273
$execdriver = undef
7374
$storage_driver = undef

spec/classes/compose_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,32 @@
115115
)
116116
}
117117
end
118+
119+
context 'when base_url is provided' do
120+
let(:params) do
121+
{ base_url: 'http://example.org',
122+
version: '1.7.0' }
123+
end
124+
125+
it { is_expected.to compile }
126+
it {
127+
is_expected.to contain_exec('Install Docker Compose 1.7.0').with_command(
128+
'curl -s -S -L http://example.org/1.7.0/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose-1.7.0',
129+
)
130+
}
131+
end
132+
133+
context 'when raw_url is provided' do
134+
let(:params) do
135+
{ raw_url: 'http://example.org',
136+
version: '1.7.0' }
137+
end
138+
139+
it { is_expected.to compile }
140+
it {
141+
is_expected.to contain_exec('Install Docker Compose 1.7.0').with_command(
142+
'curl -s -S -L http://example.org -o /usr/local/bin/docker-compose-1.7.0',
143+
)
144+
}
145+
end
118146
end

0 commit comments

Comments
 (0)