Skip to content

Commit

Permalink
Support plugins installation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-clerc committed Jan 26, 2024
1 parent 118c82c commit df554c8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Downloads and installs the latest Nexus 3 Repository Manager OSS.
documentation on newer releases.
- `node['nexus3']['outbound_proxy']` - Configure outbound HTTP/HTTPS proxy. See example
'Configure outbound HTTP/HTTPS proxy for all the attributes.'
- `node['nexus3']['plugins']` - Install external plugins, takes a hash of `{ 'plugin-name' : { "name": "name override", "source": "..", "checksum": "..", "action": "remote file action"}}`. Plugins should be bundled in KAR format, and will be written on disk as `<plugin-name>-bundle.kar`

### Examples

Expand Down
14 changes: 13 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
default['nexus3']['group'] = 'nexus'
end
# Download URL is defined in the resource but you can override it with the default['nexus3']['url'] attribute
default['nexus3']['version'] = '3.27.0-03'
default['nexus3']['version'] = '3.64.0-04'
default['nexus3']['url'] = nil # optional
default['nexus3']['checksum'] = nil # optional
default['nexus3']['home'] = "#{node['nexus3']['path']}/nexus3"
Expand Down Expand Up @@ -50,3 +50,15 @@
default['nexus3']['vmoptions_variables']['Dkaraf.startLocalConsole'] = false
default['nexus3']['vmoptions_variables']['Djava.net.preferIPv4Stack'] = true
default['nexus3']['vmoptions_variables']['Djava.endorsed.dirs'] = 'lib/endorsed'

# Plugins bundles in KAR format to install
#
# default['nexus3']['plugins']['nexus-repository-chef'] = {
# "name": "force_another_name",
# "source": "https://on.the.internet/nexus-repository-chef-0.0.10-bundle.kar",
# "checksum": "8e6494bd8edbf3beb6b7054d599561e698dcf3f666c2114b7126c246804484a9",
# "action": "create" # https://docs.chef.io/resources/remote_file/#actions
# }
#
# https://help.sonatype.com/en/installing-bundles.html
default['nexus3']['plugins'] = {}
14 changes: 14 additions & 0 deletions resources/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
property :properties_variables, Hash, default: lazy { node['nexus3']['properties_variables'] }
property :vmoptions_variables, Hash, default: lazy { node['nexus3']['vmoptions_variables'] }
property :outbound_proxy, [Hash, NilClass], sensitive: true, default: lazy { node['nexus3']['outbound_proxy'] }
property :plugins, Hash, default: lazy { node['nexus3']['plugins'] }

action :install do
install_dir = ::File.join(new_resource.path, "nexus-#{new_resource.version}")
Expand Down Expand Up @@ -96,6 +97,19 @@
notifies :run, "ruby_block[#{blocker}]", :delayed
end

# Install plugins
new_resource.plugins.each do |name, config|
plugin_file_path = ::File.join(install_dir, 'deploy', "#{config['name'] || name}-bundle.kar")
remote_file plugin_file_path do
source config['source']
checksum config['checksum']
owner new_resource.nexus3_user
action((config['action'] || :create).to_sym)
notifies :restart, "nexus3_service[#{new_resource.service_name}]", :delayed
notifies :run, "ruby_block[#{blocker}]", :delayed
end
end

link new_resource.nexus3_home do
to install_dir
owner new_resource.nexus3_user
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'chefspec/policyfile'
require 'webmock/rspec'

VER = '3.27.0-03'.freeze
VER = '3.64.0-04'.freeze
CACHE = Chef::Config[:file_cache_path]
CENTOS_VERSION = '7.8.2003'.freeze

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/cookbooks/nexus3_test/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@

default['java']['install_flavor'] = 'openjdk'
default['java']['jdk_version'] = '8'

default['nexus3']['plugins']['repository_chef']['plugin_name'] = 'nexus-repository-chef'
default['nexus3']['plugins']['repository_chef']['plugin_action'] = 'create'
default['nexus3']['plugins']['repository_chef']['artifact_url'] = "https://github.com/criteo-forks/nexus-repository-chef/releases/download/v0.0.10_#{node['nexus3']['version']}/nexus-repository-chef-0.0.10-bundle.kar"
default['nexus3']['plugins']['repository_chef']['artifact_checksum'] = '8e6494bd8edbf3beb6b7054d599561e698dcf3f666c2114b7126c246804484a9'
5 changes: 5 additions & 0 deletions test/integration/default/inspec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
its('content') { should match(%r{nexus-context-path=/}) }
end

describe file('/opt/nexus3/lib/endorsed/nexus-repository-chef-bundle.kar') do
it { should be_file }
it { should be_owned_by 'nexus' }
end

describe user('nexusbar') do
it { should exist }
its('uid') { should eq 1234 }
Expand Down

0 comments on commit df554c8

Please sign in to comment.