Skip to content

Commit

Permalink
support for a custom apt source release
Browse files Browse the repository at this point in the history
Useful in cases where postgresql has archived support for the platform.
  • Loading branch information
h0tw1r3 committed Dec 23, 2023
1 parent 26011ea commit 29ef7ff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions data/os/Ubuntu/18.04.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
postgresql::repo::baseurl: https://apt-archive.postgresql.org/pub/repos/apt/
postgresql::repo::release: "%{facts.os.distro.codename}-pgdg-archive"
3 changes: 3 additions & 0 deletions manifests/globals.pp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#
# @param repo_baseurl Sets the baseurl for the PostgreSQL repository. Useful if you host your own mirror of the repository.
# @param yum_repo_commonurl Sets the url for the PostgreSQL common Yum repository. Useful if you host your own mirror of the YUM repository.
# @param apt_source_release Overrides the default release for the apt source.
#
# @param needs_initdb
# Explicitly calls the initdb operation after the server package is installed and before the PostgreSQL service is started.
Expand Down Expand Up @@ -150,6 +151,7 @@
Optional[String[1]] $repo_proxy = undef,
Optional[String[1]] $repo_baseurl = undef,
Optional[String[1]] $yum_repo_commonurl = undef,
Optional[String[1]] $apt_source_release = undef,

Optional[Boolean] $needs_initdb = undef,

Expand Down Expand Up @@ -271,6 +273,7 @@
proxy => $repo_proxy,
baseurl => $repo_baseurl,
commonurl => $yum_repo_commonurl,
release => $apt_source_release,
}
}

Expand Down
1 change: 1 addition & 0 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# @api private
class postgresql::repo (
Optional[String[1]] $version = undef,
Optional[String[1]] $release = undef,
Optional[String[1]] $proxy = undef,
Optional[String[1]] $baseurl = undef,
Optional[String[1]] $commonurl = undef,
Expand Down
6 changes: 4 additions & 2 deletions manifests/repo/apt_postgresql_org.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
# http://www.postgresql.org/download/linux/debian/
#
$default_baseurl = 'https://apt.postgresql.org/pub/repos/apt/'

$_baseurl = pick($postgresql::repo::baseurl, $default_baseurl)

$default_release = "${facts['os']['distro']['codename']}-pgdg"
$_release = pick($postgresql::repo::release, $default_release)

apt::pin { 'apt_postgresql_org':
originator => 'apt.postgresql.org',
priority => 500,
}
-> apt::source { 'apt.postgresql.org':
location => $_baseurl,
release => "${facts['os']['distro']['codename']}-pgdg",
release => $_release,
repos => 'main',
architecture => $facts['os']['architecture'],
key => {
Expand Down
23 changes: 23 additions & 0 deletions spec/classes/repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,28 @@
it 'instantiates apt_postgresql_org class' do
expect(subject).to contain_class('postgresql::repo::apt_postgresql_org')
end

it {
is_expected.to contain_apt__source('apt.postgresql.org')
.with_location('https://apt.postgresql.org/pub/repos/apt/')
.with_release("#{facts[:os]['distro']['codename']}-pgdg")
}

it { is_expected.to contain_apt__pin('apt_postgresql_org') }
end

describe 'with custom baseurl and release' do
let(:params) do
{
baseurl: 'https://apt-archive.postgresql.org/pub/repos/apt/',
release: 'bionic-pgdg-archive',
}
end

it {
is_expected.to contain_apt__source('apt.postgresql.org')
.with_location(params[:baseurl])
.with_release(params[:release])
}
end
end

0 comments on commit 29ef7ff

Please sign in to comment.