ezjenkins / nexus-yum-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nexus Yum Plugin

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.

Content

  1. Audience
  2. History
  3. Features
  4. Requirements
  5. Installation
  6. Configuration
  7. Getting Started
    1. Deploy Java Web Application via RPM
    2. Staging RPMs in Nexus Professional
    3. Staging RPMs in Nexus OSS
  8. Help & Issues
  9. How to Build

Audience

The Nexus Yum Plugin is for anyone who is deploying Java applications to RedHat-compatible (RHEL, Centos, Fedora) servers via RPM.

Default use case

CLD at IS24 See Deploy Java Web Application via RPM.

History

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?

Features

  • 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/
    and
    http://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)

Requirements

The Nexus Yum Plugin uses the command line "createrepo" utility to build yum repository metadata. This utility must be on the path of the system that is running Nexus.

If your Centos/Redhat/Fedora system does not have this command you can install it by running "yum install createrepo" as root.

Installation

From Nexus version 2.3 on the plugin is bundled together with Nexus OSS and Nexus Pro.

Configuration

Since Nexus 2.3 you can configure Yum metadata capabilities for dedicated repositories. Click on Configure-Capabilities to open the capabilities configuration tab.

Configure Hosted Yum Repositories

Next step is creating a new Yum: Generate Metadata capability for one of your hosted repositories. Click Add and create one for the 3rd party repository for example: Configure-3rd-Party-Repo As you see we also configured some optional aliases to provide separate versioned repository for different stages (see Staging RPMs in Nexus OSS). After saving the settings each uploaded RPM to the 3rd party repository (see Getting Started) causes Nexus to rebuild the yum metadata immediately.

Configure Group Repositories

Similar to single repositories Nexus group repositories can be configured to merge the yum metadata of their member repositories. Click Add and create a new Yum: Merge Metadata capability for one group repository: Config-GroupRepository

Location

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

but shouldn't be edited directly.

Getting Started

Here we provide some typical scenarios in which the nexus-yum-plugin is used.

Deploy Java Web Application via RPM

Prepare the pom.xml

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"?>
<!--

    Sonatype Nexus (TM) Open Source Version
    Copyright (c) 2007-2013 Sonatype, Inc.
    All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.

    This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
    which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.

    Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
    of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
    Eclipse Foundation. All other trademarks are the property of their respective owners.

-->
<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>

Deploy RPM to Nexus

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

Install RPM on Server

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.

Update RPM

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.

Summary

The nexus-yum-plugin makes deploying Java application to real RHEL-compatible servers really easy and works as a relyable platform for your deployments.

Staging RPMs in Nexus Professional

The Staging Suite in Nexus Professional improves a stage-based release process a lot. The Nexus Yum Plugin supports this staging configuration, but requires some fine tuning to use the full feature list.

Image you want to configure a one-stage release process as described in the Nexus book. Follow the tutorial but use Maven2Yum as Template for target repositories, staging profiles and group repositories. The advantage is that Maven2Yum group repository really merges their member yum repositories by using mergerepo. This allows you to use these group repositories with their constant url for *.repo files on the server.

Staging RPMs in Nexus OSS

The open source verion of Nexus doesn't contain such a nice Staging Suite, but you can stage your RPMs (without the jar, war, etc. files) anyway.

Image you have 3 stages for your RPMs:

  1. development
  2. test & verification
  3. production

and already a RPM package in version 1.0 in your repository called releases.

Create aliases

First of all you create version aliases for each stage. These aliases allow you to have a canonical repository url for each stage. You can use curl for the initial creation:

curl -d "1.0" --header "Content-Type: text/plain" http://your.nexus.domain/nexus/service/local/yum/alias/releases/development/
curl -d "1.0" --header "Content-Type: text/plain" http://your.nexus.domain/nexus/service/local/yum/alias/releases/verification/
curl -d "1.0" --header "Content-Type: text/plain" http://your.nexus.domain/nexus/service/local/yum/alias/releases/production/   

Prepare servers

Now, you are able to add these alias repositories to your server. On your development machine create a file named /etc/yum.repos.d/nexus-dev.repo and the following content:

[nexus-dev]
name=Nexus Dev Repository
baseurl=http://your.nexus.domain/nexus/service/local/yum/repos/releases/development/
enabled=1
protect=0
gpgcheck=0
metadata_expire=30s
autorefresh=1
type=rpm-md

On your verification machine create a file named /etc/yum.repos.d/nexus-verification.repo and the following content:

[nexus-verification]
name=Nexus Verification Repository
baseurl=http://your.nexus.domain/nexus/service/local/yum/repos/releases/verification/
enabled=1
protect=0
gpgcheck=0
metadata_expire=30s
autorefresh=1
type=rpm-md

On your production machine create a file named /etc/yum.repos.d/nexus-production.repo and the following content:

[nexus-production]
name=Nexus Production Repository
baseurl=http://your.nexus.domain/nexus/service/local/yum/repos/releases/production/
enabled=1
protect=0
gpgcheck=0
metadata_expire=30s
autorefresh=1
type=rpm-md

Promote RPM through Stages

Now, it's time to deploy version 2.0 of your software RPM to the releases repository. To install this RPM on your development machine, update your version alias first:

curl -d "2.0" --header "Content-Type: text/plain" http://your.nexus.domain/nexus/service/local/yum/alias/releases/development/

Afterwards, login to your machine and update your software RPM via

sudo yum update

After your integration or whatever tests verified the development machine, you can promote the RPM to verification stage:

curl -d "2.0" --header "Content-Type: text/plain" http://your.nexus.domain/nexus/service/local/yum/alias/releases/verification/

Run again sudo yum update on the verification machine and test your software RPM in that environment. Finally, if everything is green, you can stage this RPM to production.

curl -d "2.0" --header "Content-Type: text/plain" http://your.nexus.domain/nexus/service/local/yum/alias/releases/production/

and run sudo yum update on your production machine.

Summary

Version aliases let you create versionized views on your Maven RPM repositories, which is useful your RPM staging, but don't let you stage your whole bunch of artifacts like RPMs, JARs, WARs, Docs, etc. together. For this you need Nexus Professional.

Help & Issues

Ask for help at our Google Group or create a new issue.

How to build

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.

About


Languages

Language:Java 100.0%