|
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, |
| 11 | + Enum[present,absent] $ensure = present, |
| 12 | + Optional[String] $version = $docker::params::compose_version, |
44 | 13 | ) inherits docker::params {
|
45 | 14 |
|
46 |
| - if $facts['kernel'] == 'Linux' { |
| 15 | + if $docker::manage_package { |
| 16 | + if $version and $ensure != 'absent' { |
| 17 | + $package_ensure = $version |
| 18 | + } else { |
| 19 | + $package_ensure = $ensure |
| 20 | + } |
| 21 | + |
47 | 22 | case $facts['os']['family'] {
|
48 | 23 | 'Debian': {
|
49 |
| - 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 |
| 24 | + 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 |
50 | 25 | }
|
51 | 26 | 'RedHat': {
|
52 |
| - 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 |
| 27 | + 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 |
53 | 28 | }
|
54 |
| - default: {} |
55 |
| - } |
56 |
| - } else { |
57 |
| - # mac & Windows OS |
58 |
| - if $facts['os']['family'] == 'windows' { |
59 |
| - $file_extension = '.exe' |
60 |
| - $file_owner = 'Administrator' |
61 |
| - } else { |
62 |
| - $file_extension = '' |
63 |
| - $file_owner = 'root' |
64 |
| - } |
65 |
| - |
66 |
| - $docker_compose_location = "${install_path}/${symlink_name}${file_extension}" |
67 |
| - |
68 |
| - if $version == 'latest' { |
69 |
| - $version = "2.20.2" |
70 |
| - } |
71 |
| - |
72 |
| - $docker_compose_location_versioned = "${install_path}/docker-compose-${version}${file_extension}" |
73 |
| - |
74 |
| - if $ensure == 'present' { |
75 |
| - if $raw_url != undef { |
76 |
| - $docker_compose_url = $raw_url |
77 |
| - } else { |
78 |
| - if $version =~ /2[.]\d+[.]\d+$/ { |
79 |
| - $version_prepath = 'v' |
80 |
| - } |
81 |
| - |
82 |
| - $docker_compose_url = "${base_url}/${version_prepath}${version}/docker-compose-${facts['kernel']}-${facts['os']['hardware']}${file_extension}" |
83 |
| - } |
84 |
| - |
85 |
| - if $proxy != undef { |
86 |
| - $proxy_opt = "--proxy ${proxy}" |
87 |
| - } else { |
88 |
| - $proxy_opt = '' |
| 29 | + 'Windows': { |
| 30 | + fail('Docker compose is installed with docker machine on Windows') |
89 | 31 | }
|
90 |
| - |
91 |
| - if $facts['os']['family'] == 'windows' { |
92 |
| - $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 |
93 |
| - |
94 |
| - $parameters = { |
95 |
| - 'proxy' => $proxy, |
96 |
| - 'docker_compose_url' => $docker_compose_url, |
97 |
| - 'docker_compose_location_versioned' => $docker_compose_location_versioned, |
98 |
| - } |
99 |
| - |
100 |
| - exec { "Install Docker Compose ${version}": |
101 |
| - command => epp('docker/windows/download_docker_compose.ps1.epp', $parameters), |
102 |
| - provider => powershell, |
103 |
| - creates => $docker_compose_location_versioned, |
104 |
| - } |
105 |
| - |
106 |
| - file { $docker_compose_location: |
107 |
| - ensure => 'link', |
108 |
| - target => $docker_compose_location_versioned, |
109 |
| - require => Exec["Install Docker Compose ${version}"], |
110 |
| - } |
111 |
| - } else { |
112 |
| - if $curl_ensure { |
113 |
| - stdlib::ensure_packages(['curl']) |
114 |
| - } |
115 |
| - |
116 |
| - exec { "Install Docker Compose ${version}": |
117 |
| - path => '/usr/bin/', |
118 |
| - cwd => '/tmp', |
119 |
| - command => "curl -s -S -L ${proxy_opt} ${docker_compose_url} -o ${docker_compose_location_versioned}", |
120 |
| - creates => $docker_compose_location_versioned, |
121 |
| - require => Package['curl'], |
122 |
| - } |
123 |
| - |
124 |
| - file { $docker_compose_location_versioned: |
125 |
| - owner => $file_owner, |
126 |
| - mode => '0755', |
127 |
| - seltype => 'container_runtime_exec_t', |
128 |
| - require => Exec["Install Docker Compose ${version}"], |
129 |
| - } |
130 |
| - |
131 |
| - file { $docker_compose_location: |
132 |
| - ensure => 'link', |
133 |
| - target => $docker_compose_location_versioned, |
134 |
| - require => File[$docker_compose_location_versioned], |
135 |
| - } |
136 |
| - } |
137 |
| - |
138 |
| - } else { |
139 |
| - file { $docker_compose_location_versioned: |
140 |
| - ensure => absent, |
141 |
| - } |
142 |
| - |
143 |
| - file { $docker_compose_location: |
144 |
| - ensure => absent, |
| 32 | + default: { |
| 33 | + fail('This module only works on Debian, RedHat or Windows.') |
145 | 34 | }
|
146 | 35 | }
|
147 | 36 | }
|
|
0 commit comments