From c8cc29a1378a82106496d07be2ba9611fdaac3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Wed, 12 Jul 2023 11:42:00 -1000 Subject: [PATCH] Fix installation of a specific version 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. --- manifests/install.pp | 30 +++++++++++++++++++++++++----- spec/classes/init_spec.rb | 30 +++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index 2ba1582..2516c1c 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -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', @@ -46,4 +58,12 @@ group => $caddy::caddy_group, mode => '0755', } + + file { $bin_file: + ensure => file, + owner => 'root', + group => 'root', + mode => '0755', + source => $caddy_source, + } } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index ee4cf37..ba4ff46 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -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 @@ -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