008 - DevOps Fundamentals: Setting Up Cloud IaaS, Artifact Repositories using Nexus on Digital Ocean

Cloud Infrastructure as a Service
When setting up a server, you generally have two options. The first option is to manually set up your server machine and have a dedicated team to manage it continuously. The second, more popular option among DevOps engineers, is to use cloud infrastructure services, where you rent a server from a provider. This approach is known as Infrastructure as a Service (IaaS). There are several cloud service providers available, such as Amazon Web Services (AWS), Google Cloud Platform (GCP), and DigitalOcean. For this demonstration, we will use DigitalOcean.
To get started, create an account on DigitalOcean. Once your account is set up, you can create a "droplet," which is essentially a virtual server. During the droplet setup process, you can configure various settings, such as setting a password or using an SSH key for authentication. It is recommended to generate an SSH key pair using ssh-keygen
and add the public key to your droplet for secure access.
By default, all ports on your droplet are open. To enhance security, navigate to the networking section and create a firewall rule. Add an incoming rule for port 22, which is used for SSH access. You can allow access from any source or restrict it to your specific IP address. After configuring the firewall, apply it to your droplet to secure your server.
For demonstration purposes, you can clone a Java and React repository onto your local machine, as described in the Previous Article. Use Gradle gradle build
to build the project, which will generate an artifact file located at /build/libs/java-react-example.jar
. You can transfer this file to your server using the scp
command. For example:
scp /path/to/java-react-example.jar user@your-server-ip:/path/to/destination
On the server, install the Java Development Kit (JDK) using the following command:
sudo apt install openjdk-8-jre-headless
Once Java is installed, run your application with the command:
java -jar /path/to/java-react-example.jar
This will start your application on port 7071. To access the application, go back to the DigitalOcean firewall configuration and add an inbound rule for custom TCP port 7071, allowing access from all IP addresses. Finally, open your web browser and visit http://your-server-ip:7071
to view your application's user interface.
Artifact Repository
An artifact repository is a specialized type of repository used to store and manage build artifacts, such as JAR files, libraries, and other binary files. Artifact repository managers, like Nexus, provide the functionality to store, retrieve, and manage these artifacts efficiently. In this guide, we will demonstrate how to set up Nexus on a DigitalOcean server.
Setting Up Nexus on DigitalOcean
Download and Extract Nexus:
First, navigate to the
/opt
directory on your server:cd /opt
Download the Nexus package using
wget
:wget https://download.sonatype.com/nexus/3/nexus-3.79.1-04-linux-x86_64.tar.gz
Extract the downloaded package:
tar -zxvf nexus-3.79.1-04-linux-x86_64.tar.gz
This will create two main directories:
nexus
(containing the executable program) andsonatype-work
(containing storage and configuration files).
Create a Nexus User:
Create a new user to run Nexus:
adduser nexus
Change the ownership of the directories to the new user:
chown -R nexus:nexus nexus-3.79.1-04 chown -R nexus:nexus sonatype-work
Configure Nexus to Run as the Nexus User:
Edit the Nexus startup script to run as the
nexus
user:vim nexus-3.79.1-04/bin/nexus
Find the
run as user
setting and change it tonexus
.
Start Nexus:
Switch to the
nexus
user and start Nexus:su - nexus /opt/nexus-3.79.1-04/bin/nexus start
Check the running port using:
netstat -lnpt
By default, Nexus runs on port 8081. Ensure this port is open in your firewall settings.
Access Nexus:
Access Nexus via
http://your-server-ip:8081
.Log in using the default admin credentials. The username is
admin
, and the password can be found in the file:cat /opt/sonatype-work/nexus3/admin.password
Configure Nexus:
In the Nexus dashboard, add a role for
maven-snapshot
and enable permissions to view allmaven-snapshot
repositories.Create a new user and assign this role to them.
Using Nexus for Artifact Management
Maven Project Configuration
Update
pom.xml
:Add the Maven Deploy Plugin:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>3.1.1</version> </plugin>
Add the distribution management section:
<distributionManagement> <snapshotRepository> <id>nexus-snapshots</id> <url>http://{server-ip}:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
Configure Maven Settings:
Edit the
settings.xml
file located for windows atC:\Users\{name}\.m2\settings.xml
:<settings> <servers> <server> <id>nexus-snapshots</id> <username>your-nexus-username</username> <password>your-nexus-password</password> </server> </servers> </settings>
Build and Deploy:
Build your project:
mvn package
Deploy the artifact:
mvn deploy
Gradle Project Configuration
Update
build.gradle
:Add the Maven Publish Plugin:
apply plugin: 'maven-publish' publishing { publications { maven(MavenPublication) { artifact("build/libs/my-app-$version.jar") { extension 'jar' } } } repositories { maven { name 'nexus' url "http://{server-ip}:8081/repository/maven-snapshots/" allowInsecureProtocol = true credentials { username project.repoUser password project.repoPassword } } } }
Configure Gradle Properties:
Create a
gradle.properties
file in the root directory:repoUser = your-nexus-username repoPassword = your-nexus-password
Build and Publish:
Build your project:
gradle build
Publish the artifact:
gradle publish
Additional Nexus Configurations
Blob Storage: Configure blob storage to manage where artifacts are stored.
Cleanup Policies: Create cleanup policies to manage disk space and automatically remove old artifacts.
By following these steps, you can effectively set up and use Nexus as an artifact repository manager on a DigitalOcean server, enabling efficient management of your build artifacts.
I hope this article helps you understand Cloud IaaS, Artifact Repositories, and management. Feel free to contact me if you have any questions.
Summary
This article explains how to set up a cloud server using Infrastructure as a Service (IaaS) with DigitalOcean and manage build artifacts using Nexus, an artifact repository manager. It covers creating a DigitalOcean account, configuring a virtual server, enhancing security with firewall rules, and deploying a Java and React application. Additionally, it provides a detailed guide on installing and configuring Nexus on a DigitalOcean server for efficient artifact management with Maven and Gradle projects, and highlights additional Nexus configurations like blob storage and cleanup policies.
Subscribe to my newsletter
Read articles from Hamza Iqbal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Hamza Iqbal
Hamza Iqbal
Hi, Hamza Iqbal here. I'm a MERN Stack developer with 3+ years of experience. I'm a tech enthusiast who love to learn new skills and read tech related news. Currently, I'm learning DevOps.