What is Artifact ?
In DevOps artifact is a by-product produced during the software development process. It may consist of the project source code, dependencies, binaries or resources, and could be represented in different layout depending on the technology.
In simple words it's a compress form of your project include all the dependencies in it and ready to deploy on a server.
How to build Artifacts ?
We have different build automation tools or package managers for different programming languages like for
- Java : Gradle | Maven
- Python : pip
- JS : npm | yarn | webpack
- C/C++ : conan
- C# : NuGet
- Golang : dep
- Ruby : RubyGems
Build Artifact for Java Gradle Project
NOTE : Java JDK should be install on your system
Open your terminal and change directory to your Java Gradle Project. Use below snippet to build artifact
./gradlew build
This will create a build directory in your project and check your /build/libs/ directory . There you will find file (*.jar) of your project in compressed format
For Maven Project
mvn install
Run application from (*.jar) file
java -jar <name_of_jar_file>
This will directly run application from jar file
Build Tools and Docker
So far we know that for different programming language we have different build tools. But it create a complete mess if our project build on top of multiple languages, cuz for each language we have to build separate artifact and which is not a good practice. That's why we use Docker images. And here are following reasons why we use Docker over build tools :
- No need to build and move different artifact types (e.g. Jar, War, Zip) ( Just one artifact type : Docker image & we build those Docker images from the applications)
- No need for a repository for each file type ( 1 docker image)
- No need to install dependencies on the server. (Execute install command inside Docker Image )
- Docker Image is an artifact and makes it easier.
- Docker Image is an alternative for all other artifact types and you don't need to install npm or java on the server , just execute everything in the image.
What is an Artifact Repository?
- Artifact Repository is a storage of build artifacts produced by continuous integration and makes them available for automated deployment to different deployment environments.
- Provides a central location for all your artifact type.
The most popular Artifact Repository Manager is NEXUS
- Nexus can store many different artifact types and which is great, because as a company you often produce different types of artifacts.
- Instead of having different repositories for each artifact type, just 1 repository for managing all your different artifact types.
About Nexus
- Nexus has open source and commercial version, you can host own repositories , can have proxy repositories (intermediary to another repository).
- That means , Fetch everything from 1 place (Nexus): Company internal and public artifacts.
- You can have multiple repositories for different formats or different teams in your company.
Install and Run Nexus on your cloud server
- The java-jdk version 8 should be install on your server
apt install openjdk-8-jre-headless
- Change directory to opt directory
cd /opt
- Download the Nexus tar file
wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
- Decompress the file or untar the package
tar -zxvf latest-unix.tar.gz
- You will get the 2 directory after untar. (nexus and sonatype-work ). Nexus folder contains runtime and application of Nexus and sonatype-work contains your config for Nexus, data, IP address , logs and files/metadata.
Starting Nexus
- Services should not run with Root User Permissions.
- Best practices: create own user for Service (e.g. Nexus)
Create a user for Nexus
adduser nexus
- Change the permission for nexus user ( Executable permission for Nexus folder and Read/Write permission for sonatype-work folder)
- For nexus-3.28.1-01 folder
chown -R nexus:nexus nexus-3.28.1-01
- For sonatype-work
chown -R nexus:nexus sonatype-work
Set nexus configuration to run it as nexus user (in nexus.rc file)
Add username(nexus) in the filevim nexus-3.28.1-01/bin/nexus.rc
run_as_user="nexus"
Run the Nexus as nexus user
Switch to nexus user
Start the nexussu - nexus
Above command will spit an output saying " Starting nexus "/opt/nexus-3.28.1-01/bin/nexus start
Check if it's running using "ps aux" command
ps aux | grep nexus
Note the port number in which service is running and open that port in your server if you want to access it from browser.
netstat -lnpt
Nexus is running of port 8081 in my localhost. Open your browser and type the ip address(localhost or server ip address) and port for nexus:
<ip address>: <port no.>
and you will get UI interface like this: