Artifact Repository Manager with Nexus

1. Intro to Artifact Repository Manager

What is an Artifact Repository?

What is an Artifact Repository Manager?

Nexus

There are also public repository managers (e.g. MVNrepository, npm). There you can make your own project publically available.

Features of Repository Manager

2. Install and Run Nexus on a Cloud Server

DigitalOcean droplet to be used:

Commands to be ran as root user:

# log as root user
cd /opt

# grab the link for download here: https://help.sonatype.com/repomanager3/download
wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz

# unpack
tar xvzf latest-unix.tar.gz

# 2 directories:
ls

When upgrading the application, the binaries go in the nexus-*/ directory and the configs are kept in sonatype-work/.

Starting Nexus

# create a new user
adduser nexus

# change the ownership of the directories:
chown -R nexus:nexus /opt/nexus-*
chown -R nexus:nexus /opt/sonatype-work

# set the user who will run nexus
vim /opt/nexus-*/bin/nexus.rc
# remove the comment and set:
# run_as_user="nexus"

# switch user
su -u nexus

# start the service:
/opt/nexus-*/bin/nexus start

# check the process:
ps aux | grep nexus

# check the port nexus is listening to
netstat -lnpt

# open the 8081 port on your host and check the connection with a browser


# if you need the admin password:
cat /opt/sonatype-work/nexus3/admin.password

3. Introduction to Nexus

Just showing the UI.

4. Repository Types

5. Publish Artifact to Repository

Create Nexus User & Role

NOTE: When doing the exercise, you'll need to go to Admin > Security > Realms. And then activate npm Bearer Token Realm.

Gradle Project - Configure with Nexus

Edit the build.gradle.

Gradle Project - Jar Upload

# inside projects directory
./gradlew build

# check `build/libs/my-app*.jar`

# upload the artifact
./gradlew publish

Go to the Nexus web interface and check if the artifact is there (Browse > maven-snapshots).

Maven Project - Configure with Nexus

Edit the pom.xml. (16:35)

Create the ~/.m2/settings.xml

vim ~/.m2/settings.xml
<settings>
  <servers>
    <server>
      <id>nexus-snapshots</id>
      <username>nana</username>
      <password>xxxxx</password>
    </server>
  </servers>
</settings>

Maven Project - Jar Upload

# in projects directory
mvn package

# upload the artifact to nexus
mvn deploy

Go to the Nexus web interface and check if the artifact is there (Browse > maven-snapshots).

6. Nexus REST API

How to access the REST endpoint

# list the repositories available for 'user'
curl -u user:password -X GET "http://${ip}:${port}/service/rest/v1/repositories"

# list all repositories (using admin credentials)
curl -u admin:password -X GET "http://${ip}:${port}/service/rest/v1/repositories"

# listing components
curl -u user:password -X GET "http://${ip}:${port}/service/rest/v1/components?repository=maven-snapshots"

# displaying one specific component
curl -u user:password -X GET "http://${ip}:${port}/service/rest/v1/components/${component_id}"

7. Blob Store

Configs are placed at /opt/sonatype-work/nexus3/blobs.

Blob Store - Type

NOTE: when creating a new blob store, the Path field is the absolute path to the desired file system location. It needs to be fully accessible by the nexus user account.

Some things to consider

8. Component vs. Asset

In the Nexus' web interface, Browse link in the sidebar, you see the components and their assets.

9. Cleanup Policies and Scheduled Tasks

Admin > Cleanup Policies > Create Cleanup Policy

After creating a cleanup policy, you still need to associate it to a repository.

Admin > Repositories > choose a repo > Cleanup Policies > Save

When will the cleanup happen?

Admin > System > Tasks

A task is created as soon as you create a Cleanup Policy

Create a Task to compact blob store

You can also run the tasks manually by clicking in the [Run] button.