Sona type Nexus • Understanding a Package and package management • Repository Manager Concepts • What is Sonatype Nexus • Installing Sonatype Nexus • Introduction of User Interface Sonatype Nexus • Configuration of Sonatype Nexus • Users and Roles of Sonatype Nexus • Creating Maven Hosted/Proxy/Group type repository • How to upload/download an artifacts using Maven from Sonatype Nexus • How to download a artifacts using Maven from Sonatype Nexus • Setting up Docker repository using Sonatype Nexus • Docker Image push/pull using Sonatype Nexus repository • Setting up npm repository using Sonatype Nexus • npm using Sonatype Nexus repository • Yum Repositories using Sonatype Nexus • Ruby, RubyGems and Gem Repositories using Sonatype Nexus • Sonatype Nexus Upgrading • Sonatype Nexus Backup and Restore • Sonatype Nexus Cleanup Policies • Sonatype Nexus REST and Integration API • Sonatype Nexus Webhooks • Sonatype Nexus .NET Package Repositories with NuGet
Sona type Nexus
Packaging Concepts
Packaging concepts Packages Packages are archives of files containing a computer program or a piece of software (such as an application, shared libraries, development code...) and, eventually, instructions on the way to make them work . Package metadata : A package also contains further information, commonly referred to as Metadata, it include package description, package version, license details etc. Package dependencies: Pre-requisites and other related packages that need to be installed beforehand.
Package concepts Package formats Package formats are the type of distributions of softwares or archived files . e.g. rpm, deb, tgz … Package Manager: A package manager deals with packages, distributions of software and data in archive files. Package repositories: Package repositories are storage location from which software packages may be retrieved and installed on a computer.
Package Management System
Installing Sona type Nexus
Repository Management Concepts
Repository Management Concepts Repository: A repository is a storage location where components such as packages, libraries, binaries, or containers are retrieved so they can be installed or used. Repository Manager: A repository manager is a dedicated server application used to manage all the repositories your development teams use throughout the course of development . For Example - Central repository for maven (Maven Central) NuGet Gallery RubyGems.org
Repository Management Concepts
Components Components : In Nexus Repository Manager terminology, the term components describe the items such as packages, libraries, binaries, containers or any other resource produced or used by your software application. In other different tool chains, components can be called by artifacts, bundles, archives etc. The typical components are archived files composed of Java .jar, .war, .ear file extensions. plain .zip or .tar.gz file extensions. package formats like nupkg , RPM, and gem. executable formats like .exe, . sh files.
Formats Formats : A repository format is a communication protocol for storing, retrieving, and indexing components and the metadata about those components. The typical formats being supported by Nexus Repository Manager 3 are Brower Docker Maven 2 npm NuGet PyPI RubyGems Yum
Core functions of Repository Manager Proxies remote repositories and caches contents. Hosts internal repositories. Groups repositories into a single repository.
Advantages of Repository Manager Manage components. Manage software releases with rules and add automated notifications . Integration with external security systems like LDAP. Control access by authenticating and authorizing specific sets or groups of users . View and manage component metadata . Host internal customized items not available in remote repositories.
Apache Maven
Introduction Maven “ Maven is a software management and comprehension tool based on the concept of Project Object Model (POM) which can manage project build, reporting, and documentation from a central piece of information ”. POM (Project Object Model): “ As a fundamental unit of work in Maven, POM is an XML file that contains information about project and configuration details used by Maven to build the project ”.
Objectives and Characteristics of Maven Maven is more than just Build Tool Maven was built considering certain objectives Maven Provides: Easy Build Process Uniform Build System Quality Project Information Guidelines for Best Practices Development Achieved Characteristics: Visibility Reusability Maintainability
Comparison with ANT One level above ANT Higher level of reusability between builds Faster turn around time to set up a powerful build Project website generation Less maintenance Repository management ANT MAVEN Target build.xml Goal pom.xml
Main features of Maven Build-Tool Dependency Management Tool Documentation Tool
Contents of the created project POM source tree for your application's sources source tree for your test sources
Standard directory layout created project src/main/java Application/Library sources src/main/resources Application/Library resources src/main/filters Resource filter files src/main/assembly Assembly descriptors src/main/ config Configuration files src/main/scripts Application/Library scripts src/main/webapp Web application sources src/test/java Test sources src/test/resources Test resources src/test/filters Test resource filter files src/site Site LICENSE.txt Project's license NOTICE.txt Notices and attributions required by libraries that the project depends on README.txt Project's readme
Components of POM file Metadata: Location of Directories, Developers/Contributors, Dependencies, Repositories Dependencies (Transitive Dependencies), Inheritance, and Aggregation Key Elements Project Model Version Group ID Packaging Artifact ID Version Name URL Description
Structure of BUILD file in ANT <project default = "compile"> <property name = " classesdir = " " value = "..."/> <property name = " libdir " value = "..."/> <target name = "compile"> < mkdir dir = "${ classesdir }"/> < javac destdir = "${ classesdir }"> < src > < pathelement location = " src /main/java"/> </ src > < classpath > < fileset dir = "${ libdir }"> <include name = "*.jar"/> </ fileset > </ classpath > </ javac > </target> </project>
Nexus User Interface
Installing and Configuring Maven sudo mkdir maven cd maven sudo wget http://mirrors.estointernet.in/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz sudo tar xavf apache-maven-3.6.0-bin.tar.gz export PATH=$PATH:/home/vagrant/maven/apache-maven-3.6.0/bin / m vn --version
Configuring Maven Nexus Repository Manager Maven Configuration To use repository manager with Apache Maven, you need to first configure Maven to check the repository manager instead of the default, built-in connection to the Central Repository. To do this, add a mirror configuration and override the default configuration for the central repository in your settings.xml at ~/maven/apache-maven-3.6.0/conf . < mirrorOf >*</ mirrorOf > < url >http://localhost:8081/repository/maven-proxy-test/</url > settings.xml
Configuring Maven Make a maven project Create a Maven project also known as a Project Object Model or POM . We’ll use this POM later to cache new components from Maven Central to your proxy repository . Navigate to your user directory and then create directory “maven-test”. Open your new directory by changing to maven-test. Create a POM file (pom.xml) with given contents. p om.xml <project> < modelVersion >4.0.0</ modelVersion > < groupId > com.example </ groupId > < artifactId >nexus-proxy</ artifactId > <version>1.0-SNAPSHOT</version> <dependencies> <dependency> < groupId > junit </ groupId > < artifactId > junit </ artifactId > <version>4.10</version> </dependency> </dependencies> </project>
Maven Repositories
Maven Proxy Repository Maven Proxy repository A proxy repository is a repository that is linked to a remote repository, such as the Central Repository to cache to components. When you search for component for first time, it is retrieved from Central and cached in the repository manager. If you search for that same component again, it will be found in local storage. This eliminates the need to go to the Central Repository and reduces bandwidth and time needed to retrieve the components you need. C reate a new Maven proxy in the Nexus Repository Manager UI by following below steps. Open the Nexus Repository Manager user interface. Click Administration in the top navigation menu, and then select Repositories . Click Create repository , and then choose the maven2 (proxy) recipe from the list. Add the following text in the required fields: Name: maven-proxy-test Remote storage URL: https://repo1.maven.org/maven2 Click Create repository to complete the form . The repository manager is now configured to proxy Maven Central.
Maven Proxy Repository Cache New Components from Maven Central to the Proxy In your terminal, navigate to the POM file you created, and run the command mvn package . Your build is ready when you get a “BUILD SUCCESS” message. In Nexus Repository Manager, click Browse in the main toolbar and then select Browse from the left-side menu . Now n avigate to maven-proxy-test . You'll see the test components you proxied for the Maven format during the previous steps . Click on a component name to review its details.
Maven Hosted Repository Maven Hosted repository A hosted repository is a repository that act as the authoritative location for your in-house components and store the components not necessarily available at central repository. Now add following steps to your settings.xml and pom.xml settings.xml pom.xml <project> ... < distributionManagement > <repository> <id>nexus</id> <name>maven-releases</name> < url >http://localhost:8081/repository/maven-releases/</url> </repository> < snapshotRepository > <id>nexus</id> <name>maven-snapshots</name> < url >http://localhost:8081/repository/maven-snapshots/</url> </ snapshotRepository > </ distributionManagement > <servers> <server> <id>nexus</id> <username>admin</username> < password>*******</ password> </server> </servers>
Maven Hosted Repository Run Snapshot builds In your terminal, navigate to your POM, and run the build with mvn clean deploy . Your build is ready when you see a “BUILD SUCCESS” message . In Nexus Repository Manager, click Browse in the main toolbar and then select Browse from the left-side menu . Of your repositories, choose maven-snapshots . You'll see the test components from your Maven Snapshots build . Click on a component name to review its details
Maven Hosted Repository Run Release builds From your POM file, release “SNAPSHOT” from the version tag as shown. Navigate to your POM, and run the build with mvn clean deploy . Your build is ready when you see a “BUILD SUCCESS” message. In Nexus Repository Manager, click Browse in the main toolbar and then select Browse from the left-side menu. Now choose maven-releases . You'll see the test components from your Maven Releases build. 5. Click on a component name to review its details:
Maven Group Repository Maven Group repository A proxy repository is a one-stop location where developers can collaborate on a project with all available components assigned to it. If you’re an administrator you can dynamically add repositories without updating developer settings. If you’re a developer you can access the contents of the group by sending requests directly to the repository manager . NOTE: It’s important to note that a group doesn’t store components. You cannot publish or deploy components directly to it. Groups just aggregate content from other repositories. If you want to modify components in a group repository, publish those changes to a hosted repository included in the group . C reate a new Maven group in the Nexus Repository Manager UI by following below steps. Select Repositories , then Create repository . Choose the maven2 (group) recipe. Fill out the form, using maven-all as the Name . Drag and drop the Available proxy and hosted repositories you created in the previous lesson to the Member field Click Save to complete the form . Make a note of the this group URL from the Repositories screen. The repository URL for this example is: http://localhost:8081/repository/maven-all .
Maven Group Repository Customize your Settings for Group Access Customize your seetings.xml for group repository access in the Nexus Repository Manager UI by following below steps. Copy the group URL from nexus repository and paste the same in settings.xml in into the mirror config section similar to the sample settings file below: < mirrorOf >*</ mirrorOf > < url >http://localhost:8081/repository/maven-all/</url> Run the maven build for maven-test project using “ mvn install ”. To locate all grouped components go to the Browse from Administration and select maven-all option.
Setting up npm using Nexus repository
Setting up ruby gems using Nexus repository
Setting up yum and .NET package repositories using NuGet
Nexus cleanup policies and REST API
Nexus Upgrading
Nexus Backup and Restore
Restore from Backup Follow the below steps to restore data from backup. Stop Nexus Repository Manager Remove the following directories from $data- dir / db accesslog analytics audit component config security Go to the location where you stored the exported databases Copy the corresponding . bak files to $data- dir /restore-from-backup for restoration ( Note : For version 3.10.0 or earlier use $data- dir /backup as the restore location) Restart Nexus Repository Manager You can verify the restoration is complete by viewing the fully-restored databases previously removed from $data- dir /nexus3/db.