Skip to content

Commit

Permalink
Do not cache files in /tmp
Browse files Browse the repository at this point in the history
The "intermediate" downloaded files needed to unbreak version change are
intended to be preserved between reboots.  Drop the
`caddy::caddy_tmp_dir` parameter and store cached downloads in
`/var/cache` instead of the temporary directory.
  • Loading branch information
smortex committed Jul 12, 2023
1 parent c8cc29a commit adeb011
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
9 changes: 0 additions & 9 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ The following parameters are available in the `caddy` class:
* [`caddy_group`](#-caddy--caddy_group)
* [`caddy_shell`](#-caddy--caddy_shell)
* [`caddy_log_dir`](#-caddy--caddy_log_dir)
* [`caddy_tmp_dir`](#-caddy--caddy_tmp_dir)
* [`caddy_home`](#-caddy--caddy_home)
* [`caddy_ssl_dir`](#-caddy--caddy_ssl_dir)
* [`caddy_license`](#-caddy--caddy_license)
Expand Down Expand Up @@ -133,14 +132,6 @@ Directory where the log files are stored.

Default value: `'/var/log/caddy'`

##### <a name="-caddy--caddy_tmp_dir"></a>`caddy_tmp_dir`

Data type: `Stdlib::Absolutepath`

Directory where the Caddy archive is stored.

Default value: `'/tmp'`

##### <a name="-caddy--caddy_home"></a>`caddy_home`

Data type: `Stdlib::Absolutepath`
Expand Down
4 changes: 0 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
# @param caddy_log_dir
# Directory where the log files are stored.
#
# @param caddy_tmp_dir
# Directory where the Caddy archive is stored.
#
# @param caddy_home
# Directory where the Caddy data is stored.
#
Expand Down Expand Up @@ -86,7 +83,6 @@
String[1] $caddy_group = 'caddy',
Stdlib::Absolutepath $caddy_shell = '/sbin/nologin',
Stdlib::Absolutepath $caddy_log_dir = '/var/log/caddy',
Stdlib::Absolutepath $caddy_tmp_dir = '/tmp',
Stdlib::Absolutepath $caddy_home = '/var/lib/caddy',
Stdlib::Absolutepath $caddy_ssl_dir = '/etc/ssl/caddy',
Enum['personal', 'commercial'] $caddy_license = 'personal',
Expand Down
8 changes: 4 additions & 4 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
if $caddy::install_method == 'github' {
$caddy_url = 'https://github.com/caddyserver/caddy/releases/download'
$caddy_dl_url = "${caddy_url}/v${caddy::version}/caddy_${caddy::version}_linux_${caddy::arch}.tar.gz"
$caddy_dl_dir = "${caddy::caddy_tmp_dir}/caddy_${caddy::version}_linux_${$caddy::arch}.tar.gz"
$caddy_dl_dir = "/var/cache/caddy_${caddy::version}_linux_${$caddy::arch}.tar.gz"

$extract_path = "${caddy::caddy_tmp_dir}/caddy-${caddy::version}"
$extract_path = "/var/cache/caddy-${caddy::version}"

file { $extract_path:
ensure => directory,
Expand All @@ -35,12 +35,12 @@
before => File[$bin_file],
}

$caddy_source = "${caddy::caddy_tmp_dir}/caddy-${caddy::version}/caddy"
$caddy_source = "/var/cache/caddy-${caddy::version}/caddy"
} else {
$caddy_url = 'https://caddyserver.com/api/download'
$caddy_dl_url = "${caddy_url}?os=linux&arch=${caddy::arch}&plugins=${caddy::caddy_features}&license=${caddy::caddy_license}&telemetry=${caddy::caddy_telemetry}"

$caddy_source = "${caddy::caddy_tmp_dir}/caddy-latest"
$caddy_source = '/var/cache/caddy-latest'

file { $caddy_source:
ensure => file,
Expand Down
10 changes: 5 additions & 5 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
end

it do
expect(subject).to contain_file('/tmp/caddy-latest').
expect(subject).to contain_file('/var/cache/caddy-latest').
with_ensure('file').
with_owner('root').
with_group('root').
Expand All @@ -65,7 +65,7 @@
with_owner('root').
with_group('root').
with_mode('0755').
with_source('/tmp/caddy-latest').
with_source('/var/cache/caddy-latest').
that_requires('File[/opt/caddy]')
end

Expand Down Expand Up @@ -150,10 +150,10 @@
end

it do
expect(subject).to contain_archive('/tmp/caddy_2.0.0_linux_amd64.tar.gz').with(
expect(subject).to contain_archive('/var/cache/caddy_2.0.0_linux_amd64.tar.gz').with(
'ensure' => 'present',
'extract' => 'true',
'extract_path' => '/tmp/caddy-2.0.0',
'extract_path' => '/var/cache/caddy-2.0.0',
'source' => 'https://github.com/caddyserver/caddy/releases/download/v2.0.0/caddy_2.0.0_linux_amd64.tar.gz',
'user' => 'root',
'group' => 'root'
Expand All @@ -166,7 +166,7 @@
with_owner('root').
with_group('root').
with_mode('0755').
with_source('/tmp/caddy-2.0.0/caddy').
with_source('/var/cache/caddy-2.0.0/caddy').
that_requires('File[/opt/caddy]')
end
end
Expand Down

0 comments on commit adeb011

Please sign in to comment.