From 0a229bca9f173ea0a384447fbb1129d369b9fbda Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Mon, 11 Apr 2022 13:19:03 +0200 Subject: [PATCH] repo: add support for Debian repository Supports Debian and Ubuntu. Signed-off-by: Frank Lichtenheld --- manifests/init.pp | 5 ++++- manifests/repo.pp | 21 +++++++++++++++++++ manifests/repo/debian.pp | 33 +++++++++++++++++++++++++++++ manifests/{ => repo}/yum.pp | 6 ++---- metadata.json | 14 +++++++++++++ spec/classes/artifactory_spec.rb | 36 +++++++++++++++++++++----------- 6 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 manifests/repo.pp create mode 100644 manifests/repo/debian.pp rename manifests/{ => repo}/yum.pp (80%) diff --git a/manifests/init.pp b/manifests/init.pp index 92ac5ba..4322486 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -9,6 +9,9 @@ String $yum_name = 'bintray-jfrog-artifactory-rpms', String $yum_baseurl = 'https://jfrog.bintray.com/artifactory-rpms', String $yum_baseurl_pro = 'https://jfrog.bintray.com/artifactory-pro-rpms', + String $deb_baseurl = 'https://releases.jfrog.io/artifactory/artifactory-debs', + String $deb_baseurl_pro = 'https://releases.jfrog.io/artifactory/artifactory-pro-debs', + String $deb_baseurl_key = 'https://releases.jfrog.io/artifactory/api/gpg/key/public', String $package_name = 'jfrog-artifactory-oss', String $package_name_pro = 'jfrog-artifactory-pro', String $package_version = 'present', @@ -35,7 +38,7 @@ $service_name = 'artifactory' - Class{'::artifactory::yum': } + Class{'::artifactory::repo': } -> class{'::artifactory::install': } -> class{'::artifactory::config': } -> class{'::artifactory::service': } diff --git a/manifests/repo.pp b/manifests/repo.pp new file mode 100644 index 0000000..f0ebb97 --- /dev/null +++ b/manifests/repo.pp @@ -0,0 +1,21 @@ +# @summary Pull in the platform specific repo classes +# @api private +class artifactory::repo () { + assert_private() + + if $::artifactory::manage_repo { + case $facts['os']['family'] { + 'RedHat', 'Linux': { + contain artifactory::repo::yum + } + + 'Debian': { + contain artifactory::repo::debian + } + + default: { + fail( "Unsupported OS family: ${facts['os']['family']}" ) + } + } + } +} diff --git a/manifests/repo/debian.pp b/manifests/repo/debian.pp new file mode 100644 index 0000000..b14d01b --- /dev/null +++ b/manifests/repo/debian.pp @@ -0,0 +1,33 @@ +# == Class artifactory::repo::debian +# +# @summary Set up the apt repo on Debian-based distros +# @api private +class artifactory::repo::debian ( + String $gpg_key_id = 'A3D085F542F740BBD7E3A2846B219DCCD7639232', +) { + assert_private() + + include apt + + case $artifactory::edition { + 'enterprise', 'pro' : { + $_url = $artifactory::deb_baseurl_pro + } + default : { + $_url = $artifactory::deb_baseurl + } + } + + apt::source { 'artifactory': + location => $_url, + release => $facts['os']['distro']['codename'], + repos => 'main', + include => { + 'src' => false, + }, + key => { + 'id' => $gpg_key_id, + 'source' => $artifactory::deb_baseurl_key, + }, + } +} diff --git a/manifests/yum.pp b/manifests/repo/yum.pp similarity index 80% rename from manifests/yum.pp rename to manifests/repo/yum.pp index 4a4d71e..de947ed 100644 --- a/manifests/yum.pp +++ b/manifests/repo/yum.pp @@ -1,8 +1,6 @@ -# == Class artifactory::install +# == Class artifactory::repo::yum # -# This class is called from artifactory for install. -# -class artifactory::yum { +class artifactory::repo::yum { if $::artifactory::manage_repo { case $artifactory::edition { 'enterprise', 'pro' : { diff --git a/metadata.json b/metadata.json index c0f9a8e..548c0cb 100644 --- a/metadata.json +++ b/metadata.json @@ -37,6 +37,20 @@ "7", "8" ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "18.04", + "20.04" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "10", + "11" + ] } ], "requirements": [ diff --git a/spec/classes/artifactory_spec.rb b/spec/classes/artifactory_spec.rb index 3226de1..d6a359d 100644 --- a/spec/classes/artifactory_spec.rb +++ b/spec/classes/artifactory_spec.rb @@ -2,9 +2,9 @@ describe 'artifactory' do context 'supported operating systems' do - on_supported_os.each do |os, facts| + on_supported_os.each do |os, os_facts| context "on #{os}" do - let(:facts) { facts.merge('root_home' => '/root') } + let(:facts) { os_facts.merge('root_home' => '/root') } context 'artifactory class without any parameters' do it { is_expected.to compile.with_all_deps } @@ -16,17 +16,29 @@ it { is_expected.to contain_service('artifactory') } it { is_expected.to contain_package('jfrog-artifactory-oss').with_ensure('present') } - it { is_expected.to contain_class('artifactory::yum') } it { is_expected.to contain_class('artifactory') } - it { - is_expected.to contain_yumrepo('bintray-jfrog-artifactory-rpms').with( - 'baseurl' => 'https://jfrog.bintray.com/artifactory-rpms', - 'descr' => 'bintray-jfrog-artifactory-rpms', - 'gpgcheck' => '1', - 'enabled' => '1', - 'gpgkey' => 'https://jfrog.bintray.com/artifactory-rpms/repodata/repomd.xml.key', - ) - } + case os_facts[:os]['family'] + when 'Debian' + it { is_expected.to contain_class('artifactory::repo::debian') } + it { + is_expected.to contain_apt__source('artifactory').with( + 'location' => 'https://releases.jfrog.io/artifactory/artifactory-debs', + 'release' => os_facts[:os]['distro']['codename'], + 'repos' => 'main' + ) + } + else + it { is_expected.to contain_class('artifactory::repo::yum') } + it { + is_expected.to contain_yumrepo('bintray-jfrog-artifactory-rpms').with( + 'baseurl' => 'https://jfrog.bintray.com/artifactory-rpms', + 'descr' => 'bintray-jfrog-artifactory-rpms', + 'gpgcheck' => '1', + 'enabled' => '1', + 'gpgkey' => 'https://jfrog.bintray.com/artifactory-rpms/repodata/repomd.xml.key', + ) + } + end end context 'artifactory class with master_key parameter' do