|
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 | | - if $facts['os']['family'] == 'windows' { |
46 | | - $file_extension = '.exe' |
47 | | - $file_owner = 'Administrator' |
48 | | - } else { |
49 | | - $file_extension = '' |
50 | | - $file_owner = 'root' |
51 | | - } |
52 | | - |
53 | | - $docker_compose_location = "${install_path}/${symlink_name}${file_extension}" |
54 | | - $docker_compose_location_versioned = "${install_path}/docker-compose-${version}${file_extension}" |
55 | | - |
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}" |
61 | | - } |
62 | | - |
63 | | - if $proxy != undef { |
64 | | - $proxy_opt = "--proxy ${proxy}" |
| 14 | + if $docker::manage_package { |
| 15 | + if $version and $ensure != 'absent' { |
| 16 | + $package_ensure = $version |
65 | 17 | } else { |
66 | | - $proxy_opt = '' |
| 18 | + $package_ensure = $ensure |
67 | 19 | } |
68 | 20 |
|
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, |
| 21 | + case $facts['os']['family'] { |
| 22 | + 'Debian': { |
| 23 | + package { 'docker-compose-plugin': |
| 24 | + ensure => $package_ensure, |
| 25 | + require => defined(bool2str($docker::use_upstream_package_source)) ? { |
| 26 | + true => Apt::Source['docker'], |
| 27 | + false => undef, |
| 28 | + }, |
| 29 | + } |
76 | 30 | } |
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, |
82 | | - } |
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'], |
| 31 | + 'RedHat': { |
| 32 | + package { 'docker-compose-plugin': |
| 33 | + ensure => $package_ensure, |
| 34 | + require => defined(bool2str($docker::use_upstream_package_source)) ? { |
| 35 | + true => Yumrepo['docker'], |
| 36 | + false => undef, |
| 37 | + }, |
| 38 | + } |
100 | 39 | } |
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}"], |
| 40 | + 'Windows': { |
| 41 | + fail('Docker compose is installed with docker machine on Windows') |
107 | 42 | } |
108 | | - |
109 | | - file { $docker_compose_location: |
110 | | - ensure => 'link', |
111 | | - target => $docker_compose_location_versioned, |
112 | | - require => File[$docker_compose_location_versioned], |
| 43 | + default: { |
| 44 | + fail('This module only works on Debian, RedHat or Windows.') |
113 | 45 | } |
114 | 46 | } |
115 | | - } else { |
116 | | - file { $docker_compose_location_versioned: |
117 | | - ensure => absent, |
118 | | - } |
119 | | - |
120 | | - file { $docker_compose_location: |
121 | | - ensure => absent, |
122 | | - } |
123 | 47 | } |
124 | 48 | } |
0 commit comments