Skip to content

major adjustments for current code style #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,808 changes: 887 additions & 921 deletions REFERENCE.md

Large diffs are not rendered by default.

79 changes: 34 additions & 45 deletions manifests/compose.pp
Original file line number Diff line number Diff line change
@@ -1,74 +1,63 @@
# == Class: docker::compose
# @summary install Docker Compose using the recommended curl command.
#
# Class to install Docker Compose using the recommended curl command.
#
# === Parameters
#
# [*ensure*]
# @param ensure
# Whether to install or remove Docker Compose
# Valid values are absent present
# Defaults to present
#
# [*version*]
# @param version
# The version of Docker Compose to install.
# Defaults to the value set in $docker::params::compose_version
#
# [*install_path*]
# @param install_path
# The path where to install Docker Compose.
# Defaults to the value set in $docker::params::compose_install_path
#
# [*symlink_name*]
# @param symlink_name
# The name of the symlink created pointing to the actual docker-compose binary
# This allows use of own docker-compose wrapper scripts for the times it's
# necessary to set certain things before running the docker-compose binary
# Defaults to the value set in $docker::params::compose_symlink_name
#
# [*proxy*]
# @param proxy
# Proxy to use for downloading Docker Compose.
#
# [*base_url*]
# @param base_url
# The base url for installation
# This allows use of a mirror that follows the same layout as the
# This allows use of a mirror that follows the same layout as the
# official repository
#
# [*raw_url*]
# @param 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.

# [*curl_ensure*]
#
# @param curl_ensure
# Whether or not the curl package is ensured by this module.
# Defaults to true
#
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] $symlink_name = $docker::params::compose_symlink_name,
Optional[String] $proxy = undef,
Optional[String] $base_url = $docker::params::compose_base_url,
Optional[String] $raw_url = undef,
Optional[Boolean] $curl_ensure = $docker::params::curl_ensure,
Optional[Enum[present,absent]] $ensure = 'present',
Optional[String] $version = $docker::params::compose_version,
Optional[String] $install_path = $docker::params::compose_install_path,
Optional[String] $symlink_name = $docker::params::compose_symlink_name,
Optional[String] $proxy = undef,
Optional[String] $base_url = $docker::params::compose_base_url,
Optional[String] $raw_url = undef,
Optional[Boolean] $curl_ensure = $docker::params::curl_ensure,
) inherits docker::params {

if $proxy != undef {
validate_re($proxy, '^((http[s]?)?:\/\/)?([^:^@]+:[^:^@]+@|)([\da-z\.-]+)\.([\da-z\.]{2,6})(:[\d])?([\/\w \.-]*)*\/?$')
}

if $::osfamily == 'windows' {
if $facts['os']['family'] == 'windows' {
$file_extension = '.exe'
$file_owner = 'Administrator'
$file_owner = 'Administrator'
} else {
$file_extension = ''
$file_owner = 'root'
$file_owner = 'root'
}

$docker_compose_location = "${install_path}/${symlink_name}${file_extension}"
$docker_compose_location = "${install_path}/${symlink_name}${file_extension}"
$docker_compose_location_versioned = "${install_path}/docker-compose-${version}${file_extension}"

if $ensure == 'present' {

if $raw_url != undef {
$docker_compose_url = $raw_url
} else {
Expand All @@ -81,10 +70,8 @@
$proxy_opt = ''
}

if $::osfamily == 'windows' {
# lint:ignore:140chars
$docker_download_command = "if (Invoke-WebRequest ${docker_compose_url} ${proxy_opt} -UseBasicParsing -OutFile \"${docker_compose_location_versioned}\") { exit 0 } else { exit 1}"
# lint:endignore
if $facts['os']['family'] == 'windows' {
$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

exec { "Install Docker Compose ${version}":
command => template('docker/windows/download_docker_compose.ps1.erb'),
Expand All @@ -95,12 +82,13 @@
file { $docker_compose_location:
ensure => 'link',
target => $docker_compose_location_versioned,
require => Exec["Install Docker Compose ${version}"]
require => Exec["Install Docker Compose ${version}"],
}
} else {
if $curl_ensure {
ensure_packages(['curl'])
}

exec { "Install Docker Compose ${version}":
path => '/usr/bin/',
cwd => '/tmp',
Expand All @@ -112,20 +100,21 @@
file { $docker_compose_location_versioned:
owner => $file_owner,
mode => '0755',
require => Exec["Install Docker Compose ${version}"]
require => Exec["Install Docker Compose ${version}"],
}

file { $docker_compose_location:
ensure => 'link',
target => $docker_compose_location_versioned,
require => File[$docker_compose_location_versioned]
require => File[$docker_compose_location_versioned],
}
}
} else {
file { [
$docker_compose_location_versioned,
$docker_compose_location
]:
file { $docker_compose_location_versioned:
ensure => absent,
}

file { $docker_compose_location:
ensure => absent,
}
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# == Class: docker::config
# @summary
#
class docker::config {
if $::osfamily != 'windows' {
if $facts['os']['family'] != 'windows' {
docker::system_user { $docker::docker_users: }
} else {
docker::windows_account { $docker::docker_users: }
Expand Down
55 changes: 35 additions & 20 deletions manifests/exec.pp
Original file line number Diff line number Diff line change
@@ -1,54 +1,69 @@

# @summary
# A define which executes a command inside a container.
#
# A define which executes a command inside a container.
# @param detach
# @param interactive
# @param env
# @param tty
# @param container
# @param command
# @param unless
# @param sanitise_name
# @param refreshonly
# @param onlyif
#
define docker::exec(
Optional[Boolean] $detach = false,
Optional[Boolean] $interactive = false,
Optional[Array] $env = [],
Optional[Array] $env = [],
Optional[Boolean] $tty = false,
Optional[String] $container = undef,
Optional[String] $command = undef,
Optional[String] $unless = undef,
Optional[String] $container = undef,
Optional[String] $command = undef,
Optional[String] $unless = undef,
Optional[Boolean] $sanitise_name = true,
Optional[Boolean] $refreshonly = false,
Optional[String] $onlyif = undef,
Optional[String] $onlyif = undef,
) {
include docker::params

$docker_command = $docker::params::docker_command

if $::osfamily == 'windows' {
if $facts['os']['family'] == 'windows' {
$exec_environment = "PATH=${::docker_program_files_path}/Docker/"
$exec_timeout = 3000
$exec_path = ["${::docker_program_files_path}/Docker/"]
$exec_provider = 'powershell'
$exec_timeout = 3000
$exec_path = [ "${::docker_program_files_path}/Docker/", ]
$exec_provider = 'powershell'
} else {
$exec_environment = 'HOME=/root'
$exec_path = ['/bin', '/usr/bin']
$exec_timeout = 0
$exec_provider = undef
$exec_path = [ '/bin', '/usr/bin', ]
$exec_timeout = 0
$exec_provider = undef
}

$docker_exec_flags = docker_exec_flags({
detach => $detach,
interactive => $interactive,
tty => $tty,
env => any2array($env),
})
$docker_exec_flags = docker_exec_flags(
{
detach => $detach,
interactive => $interactive,
tty => $tty,
env => any2array($env),
}
)


if $sanitise_name {
$sanitised_container = regsubst($container, '[^0-9A-Za-z.\-_]', '-', 'G')
} else {
$sanitised_container = $container
}

$exec = "${docker_command} exec ${docker_exec_flags} ${sanitised_container} ${command}"

$unless_command = $unless ? {
undef => undef,
'' => undef,
default => "${docker_command} exec ${docker_exec_flags} ${sanitised_container} ${$unless}",
}

$onlyif_command = $onlyif ? {
undef => undef,
'' => undef,
Expand Down
Loading