criteo-cookbooks / nexus3

Chef cookbook to install and configure Sonatype Nexus 3 Repository Manager
http://www.sonatype.com/download-oss-sonatype
MIT License
17 stars 17 forks source link

Nexus3 Cookbook

Cookbook Version Build Status

This cookbook installs and configures Sonatype Nexus 3 Repository Manager OSS according to https://books.sonatype.com/nexus-book/reference3/install.html

Usage

Use the nexus3 resource to download and install the latest Nexus 3 Repository Manager OSS.

Use the nexus3_api resource to configure Nexus 3 Repository Manager via its REST API.

Use the nexus3_repo resource to configure Nexus 3 repositories.

Use the nexus3_group resource to configure Nexus 3 repository groups.

Use the nexus3_user resource to configure Nexus 3 users.

Use the nexus3_realm resource to handle realm activation.

Use the nexus3_routing_rule resource to configure Nexus 3 routing rules.

Use the nexus3_component resource to create a component / upload an asset.

Requirements

Platforms

Recipes

default

Downloads and installs the latest Nexus 3 Repository Manager OSS.

Attributes

Examples

Changing the HTTP Port and/or Context Path

The default value for the HTTP port used to access the repository manager user interface and resources is 8081. To change HTTP Port to 8443, Context Path to /components/ and serve HTTPS directly set the properties_variables hash with the updated settings:

include_recipe 'java_se'

node.default['nexus3']['properties_variables'] = { port: '8443', args: '${jetty.etc}/jetty.xml,${jetty.etc}/jetty-https.xml,${jetty.etc}/jetty-requestlog.xml', context_path: '/components/' }
include_recipe 'nexus3'

Updating Memory Allocation and other JVM Paramaters

The default and maximum heap sizes for the repository manager are a value of 1200 MB, suitable for most usage patterns. To install latest nexus3 with 1500 MB initial memory and 2 GB max memory, set it in the vmoptions_variables:

include_recipe 'java_se'

node.default['nexus3']['vmoptions_variables'] = { Xms1500M: nil, Xmx2G: nil }
include_recipe 'nexus3'

The vmoptions_variables attributes are mapped to JVM options -<key>=<value> if a value is defined. If <value> is nil, the option becomes -<key>.

Configure outbound HTTP/HTTPS proxy

node.default['nexus3']['outbound_proxy'] = {
  'http' => {
    'host' => 'proxy.example.com',
    'port' => 80,
    'auth' => {
      'username' => 'example',
      'password' => 'secret',
      'host' => 'NTLM host',
      'domain' => 'NTLM domain',
    },
  },
  'https' => {
    'host' => 'proxy.example.com',
    'port' => 80,
    'auth' => {
      'username' => 'example',
      'password' => 'secret',
      'host' => 'NTLM host',
      'domain' => 'NTLM domain',
    },
  },
  'non_proxy_hosts' => ['rubygems.org', '*.chef.io'],
}

http is mandatory, it is a prerequisite to configure the outbound proxy, you cannot just configure https for example, it would not be valid.

auth can be ommited if you do not want to configure authentication. Only set username and password for basic authentication, else it will be NTLM.

Resources

Properties common to all resources using the Nexus3 API

api_client - A ::Nexus3::Api instance. Default is configured using following nexus3.api attributes: endpoint, username & password

nexus3

Downloads and installs the latest Nexus Repository Manager OSS v3.

Actions

Since the installation is resource-based, you can install different Nexus3 instances on the same node. Make sure to specify different home and data directories, as well as different port numbers.

Attributes

Examples

Changing the HTTP Port and/or Context Path and/or HTTP vs HTTPS

The default value for the HTTP port used to access the repository manager user interface and resources is 8081. To change HTTP Port to 8443, Context Path to /components/ and serve HTTPS directly, set the properties_variables hash with the updated settings:

include_recipe 'java_se'

nexus3 'nexus' do
  properties_variables(
    host: '0.0.0.0',
    port: '8443',
    args: '${jetty.etc}/jetty.xml,${jetty.etc}/jetty-https.xml,${jetty.etc}/jetty-requestlog.xml',
    context_path: '/components/'
  )
  action :install
end

Updating Memory Allocation and other JVM Paramaters

The default and maximum heap sizes for the repository manager are a value of 1200M, suitable for most usage patterns. To install latest nexus3 with 1500M initial memory and 2G max memory, set it in the vmoptions_variable:

include_recipe 'java_se'

nexus3 'nexus' do
  vmoptions_variables(
    Xms: '1500M',
    Xmx: '2G'
  )
  action :install
end

nexus3_api

Configures Nexus 3 Repository Manager via Script API. Low-level resource, usually used within other resources.

Actions

Properties

Examples

See api_examples for more examples of using nexus3_api resource to configure Nexus Repository Manager. Pull Requests improving or adding additional API Examples are welcome and encouraged.

Simple repository creation script

Creates or updates private script on Nexus 3 Repository Manager, then runs the script.

nexus3_api 'private' do
  content "repository.createMavenHosted('private')"
  action :run
end

nexus3_repo

Configures Nexus 3 repositories via API. This works by calling a Groovy script which will trigger the creation, update or deletion of a given repository. For ease of reading the source code, scripts are stored under files/default with the help of libraries/scripts_helper.rb.

Actions

Properties

nexus3_task

Configures scheduled tasks via API.

Actions

Properties

nexus3_realm

Handle realm activation via API.

Actions

Properties

nexus3_routing_rule

Configures Nexus 3 routing rules via the REST API. Routing rules are used to restrict certain paths on proxy repositories.

Actions

Properties

nexus3_group

Configures Nexus 3 repository groups via API. This works wrapping the nexus3_repo resource with names of member repositories added as an attribute.

Actions

Properties

nexus3_user

Configures users for use with Nexus3. Users can be assigned roles and privileges, which are seen in the nexus3_role resource.

Actions

Properties

nexus3_role

Configures roles to use with Nexus3, so you can assign users to these roles later. Roles are associated with a list of privileges defined by Nexus3 and can be nested.

Actions

Properties

nexus3_cleanup_policy

Configures Cleanup Policy to use with Nexus3 repositories, so you can configure rentention limit. Policies are per repository format and relative to either the artifact's publish_date or its last download date.

Actions

Properties

Criteria rules

Supported criteria may vary depending on the repository format, but the 2 main ones are:

NB: criteria is the number of seconds as String.

Example

nexus3_cleanup_policy 'example' do
  format 'raw'
  notes  'Cleanup all artifacts uploaded more 7 days ago AND last downloaded more than 3 days ago.'
  criteria lastBlobUpdated: '604800', lastDownloaded: '259200'
end

nexus3_component

Create a component / upload an asset to a given repository. Currently supports Maven2, Raw and Rubygems repositories.

Actions

Properties

When uploading a maven2 asset:

When uploading a raw asset:

Getting Help

Contributing

Please refer to CONTRIBUTING.

License and Authors

Authors: Denis Hoer (dennis.hoer@gmail.com)

License: MIT - see the accompanying LICENSE file for details.