Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to install caddy from repos #114

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ fixtures:
archive: https://github.com/voxpupuli/puppet-archive.git
stdlib: https://github.com/puppetlabs/puppetlabs-stdlib.git
systemd: https://github.com/voxpupuli/puppet-systemd.git
apt: https://github.com/puppetlabs/puppetlabs-apt.git
yum: https://github.com/voxpupuli/puppet-yum.git
augeas_core: https://github.com/puppetlabs/puppetlabs-augeas_core.git # required by puppet-yum
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

1. [Description](#description)
1. [Setup - The basics of getting started with Caddy](#setup)
* [What Caddy affects](#what-Caddy-affects)
* [What Caddy affects](#what-caddy-affects)
* [Setup requirements](#setup-requirements)
* [Beginning with Caddy](#beginning-with-Caddy)
* [Beginning with Caddy](#beginning-with-caddy)
1. [Usage - Configuration options and additional functionality](#usage)
1. [Limitations - OS compatibility, etc.](#limitations)
1. [Development - Guide for contributing to the module](#development)
Expand All @@ -41,10 +41,14 @@ want to install Caddy 1.x, you should use version v2.0.0 of this module.

This module has the following dependencies:

* [camptocamp/systemd](https://github.com/camptocamp/puppet-systemd)
* [puppet/systemd](https://github.com/voxpupuli/puppet-systemd)
* [puppet/archive](https://github.com/voxpupuli/puppet-archive)
* [puppetlabs/stdlib](https://github.com/puppetlabs/puppetlabs-stdlib)
* [stm/file_capability](https://github.com/smoeding/puppet-file_capability)

When `install_method` is set to 'repo', this module implicitly requires either
[puppetlabs-apt](https://github.com/puppetlabs/puppetlabs-apt) module for
Debian distro family, or [puppet-yum](https://github.com/voxpupuli/puppet-yum)
module for RedHat distro family.

### Beginning with Caddy

Expand All @@ -56,7 +60,7 @@ include caddy

## Usage

Install customised version of Caddy
Install customized version of Caddy

```puppet
class { 'caddy':
Expand Down Expand Up @@ -97,10 +101,15 @@ The [reference][1] documentation of this module is generated using [puppetlabs/p

This module has been tested on:

* RedHat 7/8
* CentOS 7/8
* Debian 8/9/10
* Ubuntu 16.04/18.04
* AlmaLinux 8/9
* CentOS 9
* Debian 11/12
* OracleLinux 8/9
* RedHat 8/9
* Rocky 8/9
* Ubuntu 20.04/22.04/24.04

For the official list of all tested distributions, please take a look at the [metadata.json](https://github.com/voxpupuli/puppet-caddy/blob/master/metadata.json#L24)

## Development

Expand Down
52 changes: 46 additions & 6 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

* `caddy::config`: This class handles the Caddy config.
* `caddy::install`: This class handles the Caddy archive.
* `caddy::install::repo`: This class handles Caddy installation from a package repository
* `caddy::service`: This class handles the Caddy service.

### Defined types
Expand Down Expand Up @@ -82,6 +83,10 @@ The following parameters are available in the `caddy` class:
* [`service_name`](#-caddy--service_name)
* [`service_ensure`](#-caddy--service_ensure)
* [`service_enable`](#-caddy--service_enable)
* [`manage_repo`](#-caddy--manage_repo)
* [`repo_settings`](#-caddy--repo_settings)
* [`package_name`](#-caddy--package_name)
* [`package_ensure`](#-caddy--package_ensure)

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

Expand All @@ -93,17 +98,20 @@ Default value: `'2.0.0'`

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

Data type: `Optional[Enum['github']]`
Data type: `Optional[Enum['github','repo']]`

Which source is used.
Which source to use for the Caddy installation. See https://caddyserver.com/docs/install.
* `undef` (default) - download from the official Caddy site
* `github` - download from Github releases
* `repo` - install from an OS repository

Default value: `undef`

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

Data type: `Stdlib::Absolutepath`

Directory where the Caddy binary is stored.
Directory where the Caddy binary is stored. Not used when $install_method is 'repo'.

Default value: `'/opt/caddy'`

Expand Down Expand Up @@ -279,26 +287,58 @@ Default value: `true`

Data type: `String[1]`

Customise the name of the system service
Customise the name of the system service.

Default value: `'caddy'`

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

Data type: `Stdlib::Ensure::Service`

Whether the service should be running or stopped
Whether the service should be running or stopped.

Default value: `'running'`

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

Data type: `Boolean`

Whether the service should be enabled or disabled
Whether the service should be enabled or disabled.

Default value: `true`

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

Data type: `Boolean`

Whether the APT/YUM(COPR) repository should be installed. Only relevant when $install_method is 'repo'.

Default value: `true`

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

Data type: `Hash[String[1],Any]`

Distro-specific repository settings.

Default value: `{}`

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

Data type: `String[1]`

Name of the caddy package to use. Only relevant when $install_method is 'repo'.

Default value: `'caddy'`

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

Data type: `String[1]`

Whether to install or remove the caddy package. Only relevant when $install_method is 'repo'.

Default value: `$version`

## Defined types

### <a name="caddy--vhost"></a>`caddy::vhost`
Expand Down
9 changes: 9 additions & 0 deletions data/family/Debian.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
---
caddy::caddy_shell: '/usr/sbin/nologin'

caddy::repo_settings:
location: https://dl.cloudsmith.io/public/caddy/stable/deb/debian
release: any-version
repos: main
key:
name: caddy-archive-keyring.asc
source: https://dl.cloudsmith.io/public/caddy/stable/gpg.key
checksum_value: 5791c2fb6b6e82feb5a69834dd2131f4bcc30af0faec37783b2dc1c5c224a82a
3 changes: 3 additions & 0 deletions data/family/RedHat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
caddy::repo_settings:
copr_repo: '@caddy/caddy'
32 changes: 26 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
# Which version is used.
#
# @param install_method
# Which source is used.
# Which source to use for the Caddy installation. See https://caddyserver.com/docs/install.
# * `undef` (default) - download from the official Caddy site
# * `github` - download from Github releases
# * `repo` - install from an OS repository
#
# @param install_path
# Directory where the Caddy binary is stored.
# Directory where the Caddy binary is stored. Not used when $install_method is 'repo'.
#
# @param manage_user
# Whether or not the module should create the user.
Expand Down Expand Up @@ -88,17 +91,29 @@
# Whether or not the module should manage the service.
#
# @param service_name
# Customise the name of the system service
# Customise the name of the system service.
#
# @param service_ensure
# Whether the service should be running or stopped
# Whether the service should be running or stopped.
#
# @param service_enable
# Whether the service should be enabled or disabled
# Whether the service should be enabled or disabled.
#
# @param manage_repo
# Whether the APT/YUM(COPR) repository should be installed. Only relevant when $install_method is 'repo'.
#
# @param repo_settings
# Distro-specific repository settings.
#
# @param package_name
# Name of the caddy package to use. Only relevant when $install_method is 'repo'.
#
# @param package_ensure
# Whether to install or remove the caddy package. Only relevant when $install_method is 'repo'.
#
class caddy (
String[1] $version = '2.0.0',
Optional[Enum['github']] $install_method = undef,
Optional[Enum['github','repo']] $install_method = undef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we should remove the 'Optional' part and add something like 'upstream'. Some people use Hiera to change settings in modules, and the current way make it impossible to revert to upstream on one host if another level in the hierarchy set it to something else.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have that in my mind, but it'll be breaking change (potentially, if someone do class { 'caddy': install_method => undef }). So far I'm trying to keep backward compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, I'll change this, just in different PR.

Stdlib::Absolutepath $install_path = '/opt/caddy',
Boolean $manage_user = true,
String[1] $caddy_user = 'caddy',
Expand All @@ -124,10 +139,15 @@
String[1] $service_name = 'caddy',
Stdlib::Ensure::Service $service_ensure = 'running',
Boolean $service_enable = true,
Boolean $manage_repo = true,
Hash[String[1],Any] $repo_settings = {},
String[1] $package_name = 'caddy',
String[1] $package_ensure = $version,
) {
case $caddy_architecture {
'x86_64', 'amd64': { $arch = 'amd64' }
'x86' : { $arch = '386' }
'aarch64' : { $arch = 'arm64' }
default: {
$arch = $caddy_architecture
warning("arch ${arch} may not be supported.")
Expand Down
125 changes: 76 additions & 49 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,90 @@

$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 {
'repo': { contain caddy::install::repo }
'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',
creates => "${extract_path}/caddy",
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',
creates => "${extract_path}/caddy",
require => File[$extract_path],
before => File[$bin_file],
}

$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 = "/var/cache/caddy-${caddy::version}/caddy"

$caddy_source = '/var/cache/caddy-latest'
file { $caddy::install_path:
ensure => directory,
owner => $caddy::caddy_user,
group => $caddy::caddy_group,
mode => '0755',
}

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 { $bin_file:
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
source => $caddy_source,
}
}
}
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('&')

file { $caddy::install_path:
ensure => directory,
owner => $caddy::caddy_user,
group => $caddy::caddy_group,
mode => '0755',
}
$caddy_dl_url = "${caddy_url}?${query_params}"

file { $bin_file:
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
source => $caddy_source,
$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::install_path:
ensure => directory,
owner => $caddy::caddy_user,
group => $caddy::caddy_group,
mode => '0755',
}

file { $bin_file:
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
source => $caddy_source,
}
}
}
}
Loading
Loading