Skip to content

Commit

Permalink
Merge pull request #5 from h0tw1r3/custom-url-install
Browse files Browse the repository at this point in the history
support installing from url
  • Loading branch information
h0tw1r3 authored Feb 23, 2024
2 parents 50d0368 + ab45df8 commit 775aab0
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 13 deletions.
13 changes: 11 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ class { 'gitea':
}
```

##### Install compatible build from URL

```puppet
class { 'gitea':
ensure => 'https://codeberg.org/forgejo/forgejo/releases/download/v1.21.6-0/forgejo-1.21.6-0-linux-amd64',
checksum => 'e86f446236a287b9ba2c65f8ff7b0a9ea4f451a5ffc3134f416f751e1eecf97c',
}
```

#### Parameters

The following parameters are available in the `gitea` class:
Expand Down Expand Up @@ -158,9 +167,9 @@ Download base URL

##### <a name="-gitea--ensure"></a>`ensure`

Data type: `Variant[Pattern[/\d+\.\d+\.\d+/],Enum['latest','installed']]`
Data type: `Variant[Pattern[/\d+\.\d+\.\d+/],Enum['latest','installed'],Stdlib::HTTPUrl]`

Version of gitea to install, 'installed', or 'latest'
Version of gitea to install, 'installed', 'latest', or URL a to release binary

##### <a name="-gitea--checksum"></a>`checksum`

Expand Down
14 changes: 10 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
# checksum => 'bc4a8e1f5d5f64d4be2e50c387de08d07c062aecdba2f742c2f61c20accfcc46',
# }
#
# @example Install compatible build from URL
# class { 'gitea':
# ensure => 'https://codeberg.org/forgejo/forgejo/releases/download/v1.21.6-0/forgejo-1.21.6-0-linux-amd64',
# checksum => 'e86f446236a287b9ba2c65f8ff7b0a9ea4f451a5ffc3134f416f751e1eecf97c',
# }
#
# @see https://gitea.io
#
# @param manage_user
Expand Down Expand Up @@ -56,11 +62,11 @@
# @param base_url
# Download base URL
#
# @param ensure
# Version of gitea to install, 'installed', or 'latest'
# @param ensure
# Version of gitea to install, 'installed', 'latest', or URL a to release binary
#
# @param checksum
# Checksum for the release binary
# Checksum for the release binary
#
# @param work_path
# Target directory for the gitea installation
Expand Down Expand Up @@ -101,7 +107,7 @@

Optional[String] $proxy,
String $base_url,
Variant[Pattern[/\d+\.\d+\.\d+/],Enum['latest','installed']] $ensure,
Variant[Pattern[/\d+\.\d+\.\d+/],Enum['latest','installed'],Stdlib::HTTPUrl] $ensure,
String $work_path,

Hash $custom_configuration,
Expand Down
14 changes: 13 additions & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

file { [
$gitea::work_path,
"${$gitea::work_path}/log",
$gitea::configuration['server']['APP_DATA_PATH'],
$gitea::configuration['repository']['ROOT'],
"${gitea::configuration['server']['APP_DATA_PATH']}/sessions",
Expand All @@ -28,7 +29,18 @@
group => $gitea::group,
}

$vars = Deferred('gitea::archive_resource', [$bin_path, $gitea::base_url, $checksums, $gitea::ensure, $gitea::checksum])
if $gitea::ensure =~ Stdlib::HTTPurl {
if $gitea::checksum !~ String[64] {
fail('gitea::checksum parameter requires sha256 checksum')
}
$vars = {
source => $gitea::ensure,
checksum => $gitea::checksum,
checksum_type => 'sha256',
}
} else {
$vars = Deferred('gitea::archive_resource', [$bin_path, $gitea::base_url, $checksums, $gitea::ensure, $gitea::checksum])
}

archive { 'gitea':
path => "${bin_path}.stage",
Expand Down
22 changes: 18 additions & 4 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,23 @@ class { 'gitea': }
it { is_expected.to be_enabled }
end

# FIXME: not working on rhel litmusimages (no ss command?)
# describe port(3000) do
# it { is_expected.to be_listening }
# end
describe port(3000) do
it { is_expected.to be_listening }
end
end

context 'install custom version' do
let(:pp) do
<<-MANIFEST
class { 'gitea':
ensure => 'https://codeberg.org/forgejo/forgejo/releases/download/v1.21.6-0/forgejo-1.21.6-0-linux-amd64',
checksum => 'e86f446236a287b9ba2c65f8ff7b0a9ea4f451a5ffc3134f416f751e1eecf97c',
}
MANIFEST
end

it 'behaves idempotently' do
idempotent_apply(pp)
end
end
end
23 changes: 21 additions & 2 deletions spec/classes/gitea_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
let(:facts) { os_facts }

# gitea
it { is_expected.to compile.with_all_deps }

it { is_expected.to contain_class('gitea') }
it { is_expected.to contain_class('gitea::service::user').that_comes_before('Class[gitea::install]') }
it { is_expected.to contain_class('gitea::install').that_comes_before('Class[gitea::config]') }
Expand All @@ -39,6 +37,7 @@

[
'/opt/gitea',
'/opt/gitea/log',
'/opt/gitea/data',
'/opt/gitea/data/gitea-repositories',
'/opt/gitea/data/sessions',
Expand Down Expand Up @@ -179,4 +178,24 @@
.with_managehome(true)
.with_system(true)
}

context 'ensure with url' do
let(:params) do
{
ensure: 'https://codeberg.org/forgejo/forgejo/releases/download/v1.21.6-0/forgejo-1.21.6-0-linux-amd64',
}
end

context 'without checksum' do
it { is_expected.to compile.and_raise_error(%r{checksum}) }
end

context 'with checksum' do
let(:params) do
super().merge({ checksum: 'e86f446236a287b9ba2c65f8ff7b0a9ea4f451a5ffc3134f416f751e1eecf97c' })
end

it { is_expected.to compile.with_all_deps }
end
end
end

0 comments on commit 775aab0

Please sign in to comment.