Skip to content

Commit

Permalink
Add Repo-package install option (#30)
Browse files Browse the repository at this point in the history
* Add Repo-package install option
  • Loading branch information
zipkid authored Dec 7, 2023
1 parent e06d616 commit 8f6dc81
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 58 deletions.
4 changes: 4 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
nexus::version: null
nexus::download_folder: /opt/sonatype
nexus::download_proxy: null
nexus::download_site: https://download.sonatype.com/nexus/3
Expand All @@ -14,3 +15,6 @@ nexus::purge_installations: true
nexus::purge_default_repositories: false
nexus::user: nexus
nexus::work_dir: "%{lookup('nexus::install_root')}/sonatype-work/nexus3"
nexus::package_type: 'src'
nexus::package_name: 'nexus'
nexus::package_ensure: 'installed'
12 changes: 11 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@
# Set this option if you want old installations of nexus repository manager to get automatically deleted.
# @param purge_default_repositories
# Set this option if you want to remove the default created maven and nuget repositories.
# @param package_type
# Select 'src' for Source download & install. 'pkg' will fetch te specified package and version
# from repos you must provide.
# @param package_name
# The name of the package to install. Default 'nexus'
# @param package_ensure
# The version to install. See https://puppet.com/docs/puppet/7/types/package.html#package-attribute-ensure
#
# @example
# class{ 'nexus':
# version => '3.37.3-02',
# }
#
class nexus (
Pattern[/3.\d+.\d+-\d+/] $version,
Optional[Pattern[/3.\d+.\d+-\d+/]] $version,
Stdlib::Absolutepath $download_folder,
Stdlib::HTTPUrl $download_site,
Optional[Stdlib::HTTPUrl] $download_proxy,
Expand All @@ -58,6 +65,9 @@
Boolean $manage_work_dir,
Boolean $purge_installations,
Boolean $purge_default_repositories,
Enum['src', 'pkg'] $package_type,
Optional[String] $package_name,
String $package_ensure,
) {
include stdlib

Expand Down
126 changes: 71 additions & 55 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,83 @@
class nexus::package {
assert_private()

$nexus_archive = "nexus-${nexus::version}-unix.tar.gz"
$download_url = "${nexus::download_site}/${nexus_archive}"
$dl_file = "${nexus::download_folder}/${nexus_archive}"
$install_dir = "${nexus::install_root}/nexus-${nexus::version}"
case $nexus::package_type {
'src': {
if !$nexus::version {
fail('nexus::version must be set when using package_type => src')
}
$nexus_archive = "nexus-${nexus::version}-unix.tar.gz"
$download_url = "${nexus::download_site}/${nexus_archive}"
$dl_file = "${nexus::download_folder}/${nexus_archive}"
$install_dir = "${nexus::install_root}/nexus-${nexus::version}"

extlib::mkdir_p($nexus::install_root)
extlib::mkdir_p($nexus::install_root)

archive { $dl_file:
source => $download_url,
extract => true,
extract_path => $nexus::install_root,
checksum_url => "${download_url}.sha1",
checksum_type => 'sha1',
proxy_server => $nexus::download_proxy,
creates => $install_dir,
user => 'root',
group => 'root',
}
archive { $dl_file:
source => $download_url,
extract => true,
extract_path => $nexus::install_root,
checksum_url => "${download_url}.sha1",
checksum_type => 'sha1',
proxy_server => $nexus::download_proxy,
creates => $install_dir,
user => 'root',
group => 'root',
}

# Prevent "Couldn't flush user prefs" error - https://issues.sonatype.org/browse/NEXUS-3671
file { ["${nexus::install_root}/.java", "${nexus::install_root}/.java/.userPrefs"]:
ensure => directory,
owner => $nexus::user,
group => $nexus::group,
mode => '0700',
}
# Prevent "Couldn't flush user prefs" error - https://issues.sonatype.org/browse/NEXUS-3671
file { ["${nexus::install_root}/.java", "${nexus::install_root}/.java/.userPrefs"]:
ensure => directory,
owner => $nexus::user,
group => $nexus::group,
mode => '0700',
}

if $nexus::purge_installations {
File <| title == $nexus::install_root |> {
ensure => 'directory',
backup => false,
force => true,
purge => true,
recurse => true,
ignore => [
"nexus-${nexus::version}",
'sonatype-work',
],
require => [
Archive[$dl_file],
],
before => [
Class['nexus::service'],
],
}
}
if $nexus::purge_installations {
File <| title == $nexus::install_root |> {
ensure => 'directory',
backup => false,
force => true,
purge => true,
recurse => true,
ignore => [
"nexus-${nexus::version}",
'sonatype-work',
],
require => [
Archive[$dl_file],
],
before => [
Class['nexus::service'],
],
}
}

if $nexus::manage_work_dir {
$directories = [
$nexus::work_dir,
"${nexus::work_dir}/etc",
"${nexus::work_dir}/log",
"${nexus::work_dir}/orient",
"${nexus::work_dir}/tmp",
]
if $nexus::manage_work_dir {
$directories = [
$nexus::work_dir,
"${nexus::work_dir}/etc",
"${nexus::work_dir}/log",
"${nexus::work_dir}/orient",
"${nexus::work_dir}/tmp",
]

file { $directories:
ensure => directory,
owner => $nexus::user,
group => $nexus::group,
require => Archive[$dl_file],
file { $directories:
ensure => directory,
owner => $nexus::user,
group => $nexus::group,
require => Archive[$dl_file],
}
}
}
'pkg': {
$install_dir = "${nexus::install_root}/nexus"
package { $nexus::package_name:
ensure => $nexus::package_ensure,
}
}
default: {
fail("Unknown value for nexus::package_type: ${nexus::package_type}")
}
}
}
19 changes: 17 additions & 2 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

it 'fails if no version configured' do
expect { is_expected.to compile }.to raise_error(RSpec::Expectations::ExpectationNotMetError,
%r{expects a value for parameter 'version'})
%r{nexus::version must be set when using package_type => src})
end
end

Expand All @@ -25,7 +25,7 @@

it 'fails if no version configured' do
expect { is_expected.to compile }.to raise_error(RSpec::Expectations::ExpectationNotMetError,
%r{parameter 'version' expects a match for Pattern})
%r{parameter 'version' expects an undef value or a match for Pattern})
end
end

Expand Down Expand Up @@ -182,6 +182,21 @@
is_expected.not_to contain_user('nexus')
end
end

context 'using pkg package type' do
let(:params) do
{
'package_type' => 'pkg',
}
end

it { is_expected.to compile }
it {
is_expected.to contain_package('nexus').with(
'ensure' => 'installed',
)
}
end
end
end
end
Expand Down

0 comments on commit 8f6dc81

Please sign in to comment.