Skip to content

Commit

Permalink
Fix installation of a specific version
Browse files Browse the repository at this point in the history
The module previously never touched caddy once it had been installed.
While we legitimately do not want to update the binary when we fetch the
latest version form the internet, we want to see an acutal change when
we update the catalog configuration to change the installation method or
the specific version we want to install.
  • Loading branch information
smortex committed Jul 12, 2023
1 parent 7def4c9 commit c8cc29a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
30 changes: 25 additions & 5 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,36 @@
$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"

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

file { $extract_path:
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}

archive { $caddy_dl_dir:
ensure => present,
extract => true,
extract_path => $caddy::install_path,
extract_path => $extract_path,
source => $caddy_dl_url,
username => $caddy::caddy_account_id,
password => $caddy::caddy_api_key,
user => 'root',
group => 'root',
creates => $bin_file,
cleanup => true,
require => File[$caddy::install_path],
require => File[$extract_path],
before => File[$bin_file],
}

$caddy_source = "${caddy::caddy_tmp_dir}/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}"

file { $bin_file:
$caddy_source = "${caddy::caddy_tmp_dir}/caddy-latest"

file { $caddy_source:
ensure => file,
owner => 'root',
group => 'root',
Expand All @@ -46,4 +58,12 @@
group => $caddy::caddy_group,
mode => '0755',
}

file { $bin_file:
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
source => $caddy_source,
}
}
30 changes: 23 additions & 7 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@
end

it do
expect(subject).to contain_file('/opt/caddy/caddy').
expect(subject).to contain_file('/tmp/caddy-latest').
with_ensure('file').
with_owner('root').
with_group('root').
with_mode('0755').
with_source('https://caddyserver.com/api/download?os=linux&arch=amd64&plugins=http.git,http.filter,http.ipfilter&license=personal&telemetry=off').
with_replace(false).
with_replace(false)
end

it do
expect(subject).to contain_file('/opt/caddy/caddy').
with_ensure('file').
with_owner('root').
with_group('root').
with_mode('0755').
with_source('/tmp/caddy-latest').
that_requires('File[/opt/caddy]')
end

Expand Down Expand Up @@ -144,13 +153,20 @@
expect(subject).to contain_archive('/tmp/caddy_2.0.0_linux_amd64.tar.gz').with(
'ensure' => 'present',
'extract' => 'true',
'extract_path' => '/opt/caddy',
'extract_path' => '/tmp/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',
'creates' => '/opt/caddy/caddy',
'cleanup' => 'true'
).
'group' => 'root'
)
end

it do
expect(subject).to contain_file('/opt/caddy/caddy').
with_ensure('file').
with_owner('root').
with_group('root').
with_mode('0755').
with_source('/tmp/caddy-2.0.0/caddy').
that_requires('File[/opt/caddy]')
end
end
Expand Down

0 comments on commit c8cc29a

Please sign in to comment.