|
7 | 7 | # @param version
|
8 | 8 | # The version of Docker Compose to install.
|
9 | 9 | #
|
10 |
| -# @param install_path |
11 |
| -# The path where to install Docker Compose. |
12 |
| -# |
13 |
| -# @param symlink_name |
14 |
| -# The name of the symlink created pointing to the actual docker-compose binary |
15 |
| -# This allows use of own docker-compose wrapper scripts for the times it's |
16 |
| -# necessary to set certain things before running the docker-compose binary |
17 |
| -# |
18 |
| -# @param proxy |
19 |
| -# Proxy to use for downloading Docker Compose. |
20 |
| -# |
21 |
| -# @param base_url |
22 |
| -# The base url for installation |
23 |
| -# This allows use of a mirror that follows the same layout as the |
24 |
| -# official repository |
25 |
| -# |
26 |
| -# @param raw_url |
27 |
| -# Override the raw URL for installation |
28 |
| -# The default is to build a URL from baseurl. If rawurl is set, the caller is |
29 |
| -# responsible for ensuring the URL points to the correct version and |
30 |
| -# architecture. |
31 |
| -# |
32 |
| -# @param curl_ensure |
33 |
| -# Whether or not the curl package is ensured by this module. |
34 |
| -# |
35 | 10 | class docker::compose (
|
36 |
| - Enum[present,absent] $ensure = present, |
37 |
| - Optional[String] $version = $docker::params::compose_version, |
38 |
| - Optional[String] $install_path = $docker::params::compose_install_path, |
39 |
| - Optional[String] $symlink_name = $docker::params::compose_symlink_name, |
40 |
| - Optional[Pattern['^((http[s]?)?:\/\/)?([^:^@]+:[^:^@]+@|)([\da-z\.-]+)\.([\da-z\.]{2,6})(:[\d])?([\/\w \.-]*)*\/?$']] $proxy = undef, |
41 |
| - Optional[String] $base_url = $docker::params::compose_base_url, |
42 |
| - Optional[String] $raw_url = undef, |
43 |
| - Optional[Boolean] $curl_ensure = $docker::params::curl_ensure, |
44 |
| -) inherits docker::params { |
45 |
| - if $facts['os']['family'] == 'windows' { |
46 |
| - $file_extension = '.exe' |
47 |
| - $file_owner = 'Administrator' |
48 |
| - } else { |
49 |
| - $file_extension = '' |
50 |
| - $file_owner = 'root' |
51 |
| - } |
| 11 | + Enum[present,absent] $ensure = present, |
| 12 | + Optional[String] $version = undef, |
| 13 | +) { |
| 14 | + include docker |
52 | 15 |
|
53 |
| - $docker_compose_location = "${install_path}/${symlink_name}${file_extension}" |
54 |
| - $docker_compose_location_versioned = "${install_path}/docker-compose-${version}${file_extension}" |
| 16 | + if $docker::manage_package { |
| 17 | + include docker::params |
55 | 18 |
|
56 |
| - if $ensure == 'present' { |
57 |
| - if $raw_url != undef { |
58 |
| - $docker_compose_url = $raw_url |
59 |
| - } else { |
60 |
| - $docker_compose_url = "${base_url}/${version}/docker-compose-${facts['kernel']}-${facts['os']['hardware']}${file_extension}" |
| 19 | + $_version = $version ? { |
| 20 | + undef => $docker::params::compose_version, |
| 21 | + default => $version, |
61 | 22 | }
|
62 |
| - |
63 |
| - if $proxy != undef { |
64 |
| - $proxy_opt = "--proxy ${proxy}" |
| 23 | + if $_version and $ensure != 'absent' { |
| 24 | + $package_ensure = $_version |
65 | 25 | } else {
|
66 |
| - $proxy_opt = '' |
| 26 | + $package_ensure = $ensure |
67 | 27 | }
|
68 | 28 |
|
69 |
| - if $facts['os']['family'] == 'windows' { |
70 |
| - $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 |
71 |
| - |
72 |
| - $parameters = { |
73 |
| - 'proxy' => $proxy, |
74 |
| - 'docker_compose_url' => $docker_compose_url, |
75 |
| - 'docker_compose_location_versioned' => $docker_compose_location_versioned, |
| 29 | + case $facts['os']['family'] { |
| 30 | + 'Debian': { |
| 31 | + $_require = $docker::use_upstream_package_source ? { |
| 32 | + true => [Apt::Source['docker'], Class['apt::update']], |
| 33 | + false => undef, |
| 34 | + } |
76 | 35 | }
|
77 |
| - |
78 |
| - exec { "Install Docker Compose ${version}": |
79 |
| - command => epp('docker/windows/download_docker_compose.ps1.epp', $parameters), |
80 |
| - provider => powershell, |
81 |
| - creates => $docker_compose_location_versioned, |
| 36 | + 'RedHat': { |
| 37 | + $_require = $docker::use_upstream_package_source ? { |
| 38 | + true => Yumrepo['docker'], |
| 39 | + false => undef, |
| 40 | + } |
82 | 41 | }
|
83 |
| - |
84 |
| - file { $docker_compose_location: |
85 |
| - ensure => 'link', |
86 |
| - target => $docker_compose_location_versioned, |
87 |
| - require => Exec["Install Docker Compose ${version}"], |
88 |
| - } |
89 |
| - } else { |
90 |
| - if $curl_ensure { |
91 |
| - stdlib::ensure_packages(['curl']) |
92 |
| - } |
93 |
| - |
94 |
| - exec { "Install Docker Compose ${version}": |
95 |
| - path => '/usr/bin/', |
96 |
| - cwd => '/tmp', |
97 |
| - command => "curl -s -S -L ${proxy_opt} ${docker_compose_url} -o ${docker_compose_location_versioned}", |
98 |
| - creates => $docker_compose_location_versioned, |
99 |
| - require => Package['curl'], |
| 42 | + 'Windows': { |
| 43 | + fail('The docker compose portion of this module is not supported on Windows') |
100 | 44 | }
|
101 |
| - |
102 |
| - file { $docker_compose_location_versioned: |
103 |
| - owner => $file_owner, |
104 |
| - mode => '0755', |
105 |
| - seltype => 'container_runtime_exec_t', |
106 |
| - require => Exec["Install Docker Compose ${version}"], |
107 |
| - } |
108 |
| - |
109 |
| - file { $docker_compose_location: |
110 |
| - ensure => 'link', |
111 |
| - target => $docker_compose_location_versioned, |
112 |
| - require => File[$docker_compose_location_versioned], |
| 45 | + default: { |
| 46 | + fail('The docker compose portion of this module only works on Debian or RedHat') |
113 | 47 | }
|
114 | 48 | }
|
115 |
| - } else { |
116 |
| - file { $docker_compose_location_versioned: |
117 |
| - ensure => absent, |
118 |
| - } |
119 |
| - |
120 |
| - file { $docker_compose_location: |
121 |
| - ensure => absent, |
| 49 | + package { 'docker-compose-plugin': |
| 50 | + ensure => $package_ensure, |
| 51 | + require => $_require, |
122 | 52 | }
|
123 | 53 | }
|
124 | 54 | }
|
0 commit comments