Skip to content

explicit-logic/artifact-module-6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Module 6 - Artifact Repository Manager with Nexus

This repository contains a demo project created as part of my DevOps studies in the TechWorld with Nana – DevOps Bootcamp.

https://www.techworld-with-nana.com/devops-bootcamp

Demo Project: Run Nexus on Droplet and Publish Artifact to Nexus

Technologies used: Nexus, DigitalOcean, Linux, Java, Gradle, Maven

Project Description:

  • Install and configure Nexus from scratch on a cloud server
  • Create new User on Nexus with relevant permissions
  • Java Gradle Project: Build Jar & Upload to Nexus
  • Java Maven Project: Build Jar & Upload to Nexus

Setup & Configuration

1. Create an Ubuntu Droplet

Recommended configuration:

  • 8 GB RAM
  • 4 CPUs

Droplet

2. Configure firewall & install dependencies

ssh root@<DROPLET_IP>
apt install openjdk-17-jre-headless net-tools -y

3. Download and extract Nexus

cd /opt
wget https://download.sonatype.com/nexus/3/nexus-3.88.0-08-linux-x86_64.tar.gz
tar -zxvf nexus-3.88.0-08-linux-x86_64.tar.gz

4. Create a dedicated nexus user (security best practice)

adduser nexus
chown -R nexus:nexus nexus-3.88.0-08
chown -R nexus:nexus sonatype-work
ls -l # to check if permissions applied

Edit the Nexus startup script:

vim nexus-3.88.0-08/bin/nexus

Set:

run_as_user="nexus"

5. Start Nexus

su - nexus
/opt/nexus-3.88.0-08/bin/nexus start
ps aux | grep nexus
netstat -lpnt

Nexus Port

6. Access Nexus UI

  • Open firewall port 8081
  • Navigate to:
http://<DROPLET_IP>:8081

Retrieve the initial admin password:

cat /opt/sonatype-work/nexus3/admin.password

Nexus Login

Enable anonymous access during initial setup.

7. Create a nexus user and nexus role

  • Create Nexus Role and User

  • Type: Nexus role

  • Role ID: nx-java

  • Role Name: nx-java

  • Privileges: nx-repository-view-maven2-*-*

Create Nexus user

Nexus User

  • Assign the nx-java role

Java Gradle Application

1. Clone and configure the project

git clone https://gitlab.com/twn-devops-bootcamp/latest/06-nexus/java-app

Create gradle.properties:

repoUser = dev
repoPassword = xxxxx

Update build.gradle:

plugins {
    id 'java'
    id 'maven-publish'
}

group = "com.example"
version = "1.0-SNAPSHOT"

publishing {
    publications {
        maven(MavenPublication) {
            from components.java
        }
    }

    repositories {
        maven {
            name = "nexus"
            url = uri("http://<DROPLET_IP>:8081/repository/maven-snapshots/")
            allowInsecureProtocol = true
            credentials {
                username = project.findProperty("repoUser")
                password = project.findProperty("repoPassword")
            }
        }
    }
}

Edit settings.gradle

rootProject.name = 'my-app'

2. Build and Publish with Gradle

gradle build
gradle publish --warning-mode all

Gradle browse repository

Java Maven Application

1. Clone the project

git clone https://gitlab.com/twn-devops-bootcamp/latest/06-nexus/java-maven-app

2. Configure Maven publishing

Update pom.xml under build > plugins:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>3.1.4</version>
  </plugin>

Add below the build section:

<distributionManagement>
  <snapshotRepository>
    <id>nexus-snapshots</id>
    <url>http://<DROPLET_IP>:8081/repository/maven-snapshots</url>
  </snapshotRepository>
</distributionManagement>

Create ~/.m2/settings.xml:

<settings>
  <servers>
    <server>
      <id>nexus-snapshots</id>
      <username>dev</username>
      <password>xxxxx</password>
    </server>
  </servers>
</settings>

3. Build and deploy with Maven

mvn package
mvn deploy

Maven deploy

Maven browse repository

About

Run Nexus on Droplet and Publish Artifact to Nexus

Topics

Resources

Stars

Watchers

Forks

Contributors