A plugin for Sonatype Nexus 1.9.2.x or 2.X which recognizes RPMs in Nexus Maven repositories and generates Yum metadata, so that RedHat-compatible system can use Nexus as software repository.
The Nexus Yum Plugin is for all guys, who are deploying Java application for RedHat-compatible (RHEL, Centos, Fedora) servers and deploy via RPM.
See Deploy Java Web Application via RPM.
Sonatype Nexus is a common repository manager for Maven, used by many companies to manage their Java artifacts like JAR, WAR, pom.xml files. At ImmobilienScout24 the DevOps-guys started to deploy their configurations and java applications via RPMs and wanted to have a repository manager for their application RPMs. Why don't extend Sonatype Nexus to host RPMs as well?
- Use a Maven repository, hosted in Nexus, containing RPMs as if it is a Yum repository. This leverages the virtual repository mechanism in Nexus which allows you to use Maven tooling to deploy RPMs into a Maven repository but still allow Yum clients to interact with the repository using the protocol it understands.
- Yum repositories are automatically updated if you upload/deploy/delete a new RPM into Nexus.
- Full group support so that you can logically group a set of Yum repositories behind a single URL.
- Have versioned views on repositories:
http://your.nexus/nexus/service/local/yum/repos/releases/1.2.3/
gives you a Yum repository with all packages in version 1.2.3 in repository releases. - You can define aliases for specific versions eg. production=1.2 and testing=2.0 and access them via the alias:
http://your.nexus/nexus/service/local/yum/repos/releases/testing/
andhttp://your.nexus/nexus/service/local/yum/repos/releases/production/
to get constant repository URLs for your servers. A new release is then applied to the server via setting the alias to a new version. - Create Yum createrepo tasks manually via web interface.
- Multiple createrepo tasks on the same repository get merged.
- Use Yum group repositories as target of staging repositories (Nexus Pro)
Ask for help at our Google Group or create a new issue.
- Install Sonatype Nexus
- Download latest nexus-yum-plugin-bundle.zip from our downloads page
- Unzip the bundle to $NEXUS_WORK_DIR/plugin-repository/. The default for $NEXUS_WORK_DIR is ~/sonatype-work/nexus/. For example: unzip nexus-yum-plugin-1.13-bundle-zip -d $NEXUS_WORK_DIR/plugin-repository/
- Install createrepo using your update manager (yum, apt-get, etc.) eg. sudo yum install createrepo
- Make sure that in Nexus Adminstration --> Settings --> Application Server Settings (optional) --> Base URL is set to a vaild URL like : http://your.nexus.domain:8081/nexus
- Sometimes Force Base URL is nessessary, too, see ISSUE 4 . Otherwise the plugin can't determine the server URL and you got RPM locations like null/content/repositories/... in primary.xml.
- Configure Nexus Yum Plugin via yum.xml. See Configuration.
- Restart Nexus. Eg. sudo service nexus stop sudo service nexus start
Now the plugin should be installed.
Here, you'll find everything about configuring Nexus Yum Plugin.
The configuration of the Nexus Yum Plugin can be found in yum.xml in the same directory as nexus.xml : $NEXUS_WORK_DIR/conf/yum.xml Default: ~/sonatype-work/nexus/conf/yum.xml
Example yum.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- timeout for requests for a filtered (versionized) repository -->
<repositoryCreationTimeout>150</repositoryCreationTimeout><!-- in seconds -->
<!-- enables or disables the creation of a repository of repositories -->
<repositoryOfRepositoryVersionsActive>true</repositoryOfRepositoryVersionsActive>
<!-- enables or disables of delete rpm events via nexus -->
<deleteProcessing>true</deleteProcessing>
<!-- delay after which the rebuild of a repository is triggered in which one or more rpms got deleted -->
<delayAfterDeletion>10</delayAfterDeletion><!-- in seconds -->
<!-- configured aliases -->
<aliasMappings>
<aliasMapping>
<repoId>releases</repoId>
<alias>trunk</alias>
<version>5.1.15-2</version>
</aliasMapping>
<aliasMapping>
<repoId>releases</repoId>
<alias>production</alias>
<version>5.1.15-1</version>
</aliasMapping>
</aliasMappings>
</configuration>
Here we provide some typical scenarios in which the nexus-yum-plugin is used.
Assume you have a standard Java web application build with Maven. To build a RPM of your WAR file you could use the rpm-maven-plugin by Codehaus. Its goal attached-rpm automatically attaches the RPM file as Maven build artifact so that the RPM is uploaded to Nexus in the deploy phase. A minimal pom.xml would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.nexus.yum.its</groupId>
<artifactId>war-rpm-test</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<build>
<plugins>
<!-- use rpm-maven-plugin to package the war into an rpm -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1-alpha-2</version>
<executions>
<execution>
<id>build-rpm</id>
<goals>
<!-- this goal automatically adds the rpm as Maven build artifact -->
<goal>attached-rpm</goal>
</goals>
</execution>
</executions>
<configuration>
<group>Applications/Internet</group>
<copyright>EPL</copyright>
<!-- require tomcat6 as webapp container -->
<requires>
<require>tomcat6</require>
</requires>
<mappings>
<mapping>
<!-- put webapp files to standard tomcat6 webapps directory -->
<directory>/var/lib/tomcat6/webapps/${project.build.finalName}</directory>
<sources>
<source>
<location>${project.build.directory}/${project.build.finalName}</location>
</source>
</sources>
</mapping>
</mappings>
</configuration>
</plugin>
</plugins>
</build>
<!-- deploy build artifacts (pom,war,rpm) to Nexus -->
<distributionManagement>
<repository>
<id>releases</id>
<name>Releases Repository</name>
<url>http://your.nexus.domain/nexus/content/repositories/releases</url>
</repository>
</distributionManagement>
</project>
If you have the nexus-yum-plugin installed and deploy your application via
mvn deploy
to Nexus, the RPM is uploaded and on Nexus side the yum metatdata is generated asynchronously. You can browse the yum metadata here:
http://your.nexus.domain/nexus/content/repositories/releases/repodata
Your RPM was built and is stored in a Nexus yum repository (if nexus_yum_plugin is installed, each Maven repository gets a yum repository after uploading an RPM). The next step is to install the RPM on your RHEL-compatible server.
First of all, we need to introduce our new yum repository to the server. Therefore, we create a new yum repository file called nexus-releases.repo. The default location for such yum repository file is /etc/yum.repos.d, but may differ depending on your distribution and configuration.:
sudo vi /etc/yum.repos.d/nexus-releases.repo
Insert the following content:
[nexus-releases]
name=Nexus Releases Repository
baseurl=http://your.nexus.domain/nexus/content/repositories/releases
enabled=1
protect=0
gpgcheck=0
metadata_expire=30s
autorefresh=1
type=rpm-md
and save the file. Now, the server will ask Nexus for new software packages and updates. After that just install your web application and all its dependencies (Tomcat, Java, etc.) via:
sudo yum install war-rpm-test
and start tomcat:
sudo service tomcat start
That's it.
To update the web application on your server just call:
sudo service tomcat stop
sudo yum update
sudo service tomcat start
The tomcat restart is optional depending on your webapp and configuration, but always a good choice.
The nexus-yum-plugin makes deploying Java application to real RHEL-compatible servers really easy and works as a relyable platform for your deployments.
The build process is based on Apache Maven 3. You must have createrepo installed in order to execute all the integration tests. Just do a
mvn package
to run all tests and create a plugin bundle.