From c4b08b3e59745d6bc171b0e15024fb8e14ed4d68 Mon Sep 17 00:00:00 2001 From: Tim 'bastelfreak' Meusel Date: Tue, 5 Sep 2023 15:52:34 +0200 Subject: [PATCH] webhook-go: Implement repository support --- manifests/webhook/package.pp | 33 +++++++++++++++++++++++++-- spec/acceptance/r10k_webhook_spec.rb | 34 ++++++++++++++++++++++++++++ spec/spec_helper_acceptance.rb | 8 +++++-- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/manifests/webhook/package.pp b/manifests/webhook/package.pp index b25e68a0..cc9f1110 100644 --- a/manifests/webhook/package.pp +++ b/manifests/webhook/package.pp @@ -10,7 +10,7 @@ $pkg_file = '/tmp/webhook-go.rpm' $package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${r10k::webhook::version}/webhook-go_${r10k::webhook::version}_linux_amd64.rpm" } - 'Debian', 'Ubuntu': { + 'Debian': { $provider = 'dpkg' $pkg_file = '/tmp/webhook-go.deb' $package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${r10k::webhook::version}/webhook-go_${r10k::webhook::version}_linux_amd64.deb" @@ -33,7 +33,36 @@ } } 'repo': { - warning('webhook-go: configuring a repo is not implemented yet') + case $facts['os']['family'] { + 'RedHat': { + yumrepo { 'voxpupuli-webhook-go': + descr => 'A certifiably-awesome open-source package repository curated by Vox Pupuli, hosted by Cloudsmith.', + baseurl => "https://dl.cloudsmith.io/public/voxpupuli/webhook-go/rpm/${facts['os']['name']}/\$releasever/\$basearch", + gpgcheck => 1, + repo_gpgcheck => 1, + enabled => true, + gpgkey => 'https://dl.cloudsmith.io/public/voxpupuli/webhook-go/gpg.FD229D5D47E6F534.key', + } + } + 'Debian': { + include apt + apt::source { 'voxpupuli-webhook-go': + comment => 'A certifiably-awesome open-source package repository curated by Vox Pupuli, hosted by Cloudsmith.', + location => "https://dl.cloudsmith.io/public/voxpupuli/webhook-go/deb/${facts['os']['name']}", + repos => 'main', + key => { + 'id' => 'FD229D5D47E6F534', + 'source' => 'https://dl.cloudsmith.io/public/voxpupuli/webhook-go/gpg.FD229D5D47E6F534.key', + }, + } + } + default: { + fail("Operating system ${facts['os']['name']} not supported for packages") + } + } + package { 'webhook-go': + ensure => 'installed', + } } # none = people configure a repo on their own 'none': { diff --git a/spec/acceptance/r10k_webhook_spec.rb b/spec/acceptance/r10k_webhook_spec.rb index 905b5e04..25679fd4 100644 --- a/spec/acceptance/r10k_webhook_spec.rb +++ b/spec/acceptance/r10k_webhook_spec.rb @@ -35,4 +35,38 @@ class { 'r10k': } its(:stdout) { is_expected.to match(%r{webhook-go}) } end end + + context 'with external repo' do + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'r10k': } + -> class { 'r10k::webhook': + install_method => 'repo', + } + PUPPET + end + end + describe package('webhook-go') do + it { is_expected.to be_installed } + end + + describe file('/etc/voxpupuli/webhook.yml') do + it 'exists and has content' do + expect(subject).to exist + expect(subject).to be_owned_by 'root' + expect(subject).to be_grouped_into 'root' + expect(subject).to contain "---\nserver:\n protected: true\n user: puppet\n password: puppet\n" + end + end + + describe service('webhook-go') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + + describe command('systemctl cat webhook-go') do + its(:stdout) { is_expected.to match(%r{webhook-go}) } + end + end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 2681792e..c57af928 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -5,6 +5,10 @@ require 'voxpupuli/acceptance/spec_helper_acceptance' -configure_beaker(modules: :metadata) - +configure_beaker do |host| + case fact('os.family') + when 'Debian' + install_puppet_module_via_pmt_on(host, 'puppetlabs-apt') + end +end Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f }