Skip to content

Commit

Permalink
Refactor caddy::install
Browse files Browse the repository at this point in the history
  • Loading branch information
jay7x committed Nov 30, 2024
1 parent 4c09b2a commit 5a4c4c6
Showing 1 changed file with 45 additions and 34 deletions.
79 changes: 45 additions & 34 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,58 @@

$bin_file = "${caddy::install_path}/caddy"

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 = "/var/cache/caddy_${caddy::version}_linux_${$caddy::arch}.tar.gz"
case $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 = "/var/cache/caddy_${caddy::version}_linux_${$caddy::arch}.tar.gz"

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

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

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

archive { $caddy_dl_dir:
ensure => present,
extract => true,
extract_path => $extract_path,
source => $caddy_dl_url,
username => $caddy::caddy_account_id,
password => $caddy::caddy_api_key,
user => 'root',
group => 'root',
require => File[$extract_path],
before => File[$bin_file],
$caddy_source = "/var/cache/caddy-${caddy::version}/caddy"
}
default: {
$caddy_url = 'https://caddyserver.com/api/download'
$query_params = {
os => 'linux',
arch => $caddy::arch,
plugins => $caddy::caddy_features,
license => $caddy::caddy_license,
telemetry => $caddy::caddy_telemetry,
}.map |$k, $v| { "${k}=${v}" }.join('&')

$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_dl_url = "${caddy_url}?${query_params}"

$caddy_source = '/var/cache/caddy-latest'
$caddy_source = '/var/cache/caddy-latest'

file { $caddy_source:
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
source => $caddy_dl_url,
replace => false, # Don't download the file on every run
file { $caddy_source:
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
source => $caddy_dl_url,
replace => false, # Don't download the file on every run
}
}
}

Expand Down

0 comments on commit 5a4c4c6

Please sign in to comment.