Skip to content

Commit

Permalink
Merge pull request #944 from puppetlabs/CAT-1143-erb_to_epp_docker
Browse files Browse the repository at this point in the history
(CAT-1143)-Conversion_of_erb_templates_to_epp
  • Loading branch information
Ramesh7 authored Aug 10, 2023
2 parents efe8f3c + 3e101cb commit a61afc2
Show file tree
Hide file tree
Showing 49 changed files with 778 additions and 584 deletions.
8 changes: 7 additions & 1 deletion manifests/compose.pp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@
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

$parameters = {
'proxy' => $proxy,
'docker_compose_url' => $docker_compose_url,
'docker_compose_location_versioned' => $docker_compose_location_versioned,
}

exec { "Install Docker Compose ${version}":
command => template('docker/windows/download_docker_compose.ps1.erb'),
command => epp('docker/windows/download_docker_compose.ps1.epp', $parameters),
provider => powershell,
creates => $docker_compose_location_versioned,
}
Expand Down
9 changes: 6 additions & 3 deletions manifests/image.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
$docker_command = $docker::params::docker_command

if $facts['os']['family'] == 'windows' {
$update_docker_image_template = 'docker/windows/update_docker_image.ps1.erb'
$update_docker_image_template = 'docker/windows/update_docker_image.ps1.epp'
$update_docker_image_path = "${facts['docker_user_temp_path']}/update_docker_image.ps1"
$exec_environment = "PATH=${facts['docker_program_files_path']}/Docker/"
$exec_timeout = 3000
$update_docker_image_owner = undef
$exec_path = ["${facts['docker_program_files_path']}/Docker/",]
$exec_provider = 'powershell'
} else {
$update_docker_image_template = 'docker/update_docker_image.sh.erb'
$update_docker_image_template = 'docker/update_docker_image.sh.epp'
$update_docker_image_path = '/usr/local/bin/update_docker_image.sh'
$update_docker_image_owner = 'root'
$exec_environment = 'HOME=/root'
Expand All @@ -57,14 +57,17 @@
$exec_provider = undef
}

$parameters = {
'docker_command' => $docker_command,
}
# Wrapper used to ensure images are up to date
ensure_resource('file', $update_docker_image_path,
{
ensure => $docker::params::ensure,
owner => $update_docker_image_owner,
group => $update_docker_image_owner,
mode => '0555',
content => template($update_docker_image_template),
content => epp($update_docker_image_template, $parameters),
}
)

Expand Down
38 changes: 32 additions & 6 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,52 @@
}
} else {
if $ensure == 'absent' {
$remove_docker_parameters = {
'docker_ee_package_name' => $docker_ee_package_name,
'version' => $version,
}
$check_docker_parameters = {
'docker_ee_package_name' => $docker_ee_package_name,
}
exec { 'remove-docker-package':
command => template('docker/windows/remove_docker.ps1.erb'),
command => epp('docker/windows/remove_docker.ps1.epp', $remove_docker_parameters),
provider => powershell,
unless => template('docker/windows/check_docker.ps1.erb'),
unless => epp('docker/windows/check_docker.ps1.epp', $check_docker_parameters),
logoutput => true,
}
} else {
if $docker::package_location {
$download_docker_parameters = {
'docker_download_url' => $docker_download_url,
}
$check_docker_url_parameters = {
'docker_download_url' => $docker_download_url,
}
exec { 'install-docker-package':
command => template('docker/windows/download_docker.ps1.erb'),
command => epp('docker/windows/download_docker.ps1.epp', $download_docker_parameters),
provider => powershell,
unless => template('docker/windows/check_docker_url.ps1.erb'),
unless => epp('docker/windows/check_docker_url.ps1.epp', $check_docker_url_parameters),
logoutput => true,
notify => Exec['service-restart-on-failure'],
}
} else {
$install_powershell_provider_parameters = {
'nuget_package_provider_version' => $nuget_package_provider_version,
'docker_msft_provider_version' => $docker_msft_provider_version,
'version' => $version,
}

$check_powershell_provider_parameters = {
'nuget_package_provider_version' => $nuget_package_provider_version,
'docker_msft_provider_version' => $docker_msft_provider_version,
'docker_ee_package_name' => $docker_ee_package_name,
'version' => $version,
}

exec { 'install-docker-package':
command => template('docker/windows/install_powershell_provider.ps1.erb'),
command => epp('docker/windows/install_powershell_provider.ps1.epp', $install_powershell_provider_parameters),
provider => powershell,
unless => template('docker/windows/check_powershell_provider.ps1.erb'),
unless => epp('docker/windows/check_powershell_provider.ps1.epp', $check_powershell_provider_parameters),
logoutput => true,
timeout => 1800,
notify => Exec['service-restart-on-failure'],
Expand Down
8 changes: 7 additions & 1 deletion manifests/machine.pp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@
if $facts['os']['family'] == 'windows' {
$docker_download_command = "if (Invoke-WebRequest ${docker_machine_url} ${proxy_opt} -UseBasicParsing -OutFile \"${docker_machine_location_versioned}\") { exit 0 } else { exit 1}" # lint:ignore:140chars

$parameters = {
'proxy' => $proxy,
'docker_machine_url' => $docker_machine_url,
'docker_machine_location_versioned' => $docker_machine_location_versioned,
}

exec { "Install Docker Machine ${version}":
command => template('docker/windows/download_docker_machine.ps1.erb'),
command => epp('docker/windows/download_docker_machine.ps1.epp', $parameters),
provider => powershell,
creates => $docker_machine_location_versioned,
}
Expand Down
24 changes: 12 additions & 12 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
$storage_auto_extend_pool = undef
$storage_pool_autoextend_threshold = undef
$storage_pool_autoextend_percent = undef
$storage_config_template = 'docker/etc/sysconfig/docker-storage.erb'
$storage_config_template = 'docker/etc/sysconfig/docker-storage.epp'
$registry_mirror = undef
$curl_ensure = true
$os_lc = downcase($facts['os']['name'])
Expand Down Expand Up @@ -115,17 +115,17 @@

if (versioncmp($facts['os']['release']['full'], '15.04') >= 0) {
$service_after_override = undef
$service_config_template = 'docker/etc/sysconfig/docker.systemd.erb'
$service_config_template = 'docker/etc/sysconfig/docker.systemd.epp'
$service_hasrestart = true
$service_hasstatus = true
$service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb'
$service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-debian.conf.epp'
$service_provider = 'systemd'
$socket_override = false
$socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.erb'
$socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.epp'
$storage_config = '/etc/default/docker-storage'
include docker::systemd_reload
} else {
$service_config_template = 'docker/etc/default/docker.erb'
$service_config_template = 'docker/etc/default/docker.epp'
$service_overrides_template = undef
$socket_overrides_template = undef
$socket_override = false
Expand All @@ -144,9 +144,9 @@
}
$service_provider = 'systemd'
$storage_config = '/etc/default/docker-storage'
$service_config_template = 'docker/etc/sysconfig/docker.systemd.erb'
$service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb'
$socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.erb'
$service_config_template = 'docker/etc/sysconfig/docker.systemd.epp'
$service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-debian.conf.epp'
$socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.epp'
$socket_override = false
$service_after_override = undef
$service_hasstatus = true
Expand Down Expand Up @@ -198,13 +198,13 @@
'RedHat' : {
$service_after_override = undef
$service_config = '/etc/sysconfig/docker'
$service_config_template = 'docker/etc/sysconfig/docker.systemd.erb'
$service_config_template = 'docker/etc/sysconfig/docker.systemd.epp'
$service_hasrestart = true
$service_hasstatus = true
$service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-rhel.conf.erb'
$service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-rhel.conf.epp'
$service_provider = 'systemd'
$socket_override = false
$socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.erb'
$socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.epp'
$storage_config = '/etc/sysconfig/docker-storage'
$storage_setup_file = '/etc/sysconfig/docker-storage-setup'
$use_upstream_package_source = true
Expand Down Expand Up @@ -242,7 +242,7 @@
$msft_nuget_package_provider_version = $nuget_package_provider_version
$msft_provider_version = $docker_msft_provider_version
$msft_package_version = $version
$service_config_template = 'docker/windows/config/daemon.json.erb'
$service_config_template = 'docker/windows/config/daemon.json.epp'
$service_config = "${facts['docker_program_data_path']}/docker/config/daemon.json"
$docker_group = 'docker'
$package_ce_source_location = undef
Expand Down
67 changes: 62 additions & 5 deletions manifests/run.pp
Original file line number Diff line number Diff line change
Expand Up @@ -475,22 +475,50 @@
}
}
} else {
$docker_run_inline_start = template('docker/docker-run-start.erb')
$docker_run_inline_stop = template('docker/docker-run-stop.erb')
$run_start_parameters = {
'before_start' => $before_start,
'remove_container_on_start' => $remove_container_on_start,
'docker_command' => $docker_command,
'remove_volume_on_start' => $remove_volume_on_start,
'sanitised_title' => $sanitised_title,
'pull_on_start' => $pull_on_start,
'image' => $image,
'verify_digest' => $verify_digest,
'docker_run_flags' => $docker_run_flags,
'command' => $command,
'after_create' => $after_create,
'net' => $net,
'valid_detach' => $valid_detach,
'after_start' => $after_start,
}

$docker_run_inline_start = epp('docker/docker-run-start.epp', $run_start_parameters)

$run_stop_parameters = {
'before_stop' => $before_stop,
'docker_command' => $docker_command,
'stop_wait_time' => $stop_wait_time,
'sanitised_title' => $sanitised_title,
'remove_container_on_stop' => $remove_container_on_stop,
'remove_volume_on_stop' => $remove_volume_on_stop,
'after_stop' => $after_stop,
}

$docker_run_inline_stop = epp('docker/docker-run-stop.epp', $run_stop_parameters)

case $service_provider_real {
'systemd': {
$initscript = "/etc/systemd/system/${service_prefix}${sanitised_title}.service"
$startscript = "/usr/local/bin/docker-run-${sanitised_title}-start.sh"
$stopscript = "/usr/local/bin/docker-run-${sanitised_title}-stop.sh"
$startstop_template = 'docker/usr/local/bin/docker-run.sh.epp'
$init_template = 'docker/etc/systemd/system/docker-run.erb'
$init_template = 'docker/etc/systemd/system/docker-run.epp'
$mode = '0644'
$hasstatus = true
}
'upstart': {
$initscript = "/etc/init.d/${service_prefix}${sanitised_title}"
$init_template = 'docker/etc/init.d/docker-run.erb'
$init_template = 'docker/etc/init.d/docker-run.epp'
$mode = '0750'
$startscript = undef
$stopscript = undef
Expand Down Expand Up @@ -589,9 +617,38 @@
}
}

if $service_provider_real == 'systemd' {
$init_template_parameters = {
'depend_services_array' => $depend_services_array,
'sanitised_after_array' => $sanitised_after_array,
'service_prefix' => $service_prefix,
'sanitised_depends_array' => $sanitised_depends_array,
'title' => $title,
'have_systemd_v230' => $docker::params::have_systemd_v230,
'extra_systemd_parameters' => $extra_systemd_parameters,
'systemd_restart' => $systemd_restart,
'_syslog_identifier' => $_syslog_identifier,
'syslog_facility' => $syslog_facility,
'sanitised_title' => $sanitised_title,
'remain_after_exit' => $remain_after_exit,
'service_name' => $service_name,
}
} elsif $service_provider_real == 'upstart' {
$init_template_parameters = {
'sanitised_after_array' => $sanitised_after_array,
'service_prefix' => $service_prefix,
'sanitised_depends_array' => $sanitised_depends_array,
'depend_services_array' => $depend_services_array,
'docker_command' => $docker_command,
'sanitised_title' => $sanitised_title,
'docker_run_inline_start' => $docker_run_inline_start,
'docker_run_inline_stop' => $docker_run_inline_stop,
}
}

file { $initscript:
ensure => file,
content => template($init_template),
content => epp($init_template, $init_template_parameters),
seltype => 'container_unit_file_t',
owner => 'root',
group => $docker_group,
Expand Down
Loading

0 comments on commit a61afc2

Please sign in to comment.