Skip to content

Commit

Permalink
Merge pull request #1 from sonatype-nexus-community/proxy-poc
Browse files Browse the repository at this point in the history
Proxy POC
  • Loading branch information
Daniel Sauble authored Nov 2, 2018
2 parents d475e3f + bf2a8ca commit 4394283
Show file tree
Hide file tree
Showing 21 changed files with 1,681 additions and 10 deletions.
154 changes: 152 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,156 @@
-->

# Nexus Repository Puppet
# Nexus Repository Puppet Format

TBD
## Developing

### Requirements

* [Apache Maven 3.3.3+](https://maven.apache.org/install.html)
* [Java 8+](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
* Network access to https://repository.sonatype.org/content/groups/sonatype-public-grid

Also, there is a good amount of information available at [Bundle Development](https://help.sonatype.com/display/NXRM3/Bundle+Development)

### Building

To build the project and generate the bundle use Maven

mvn clean package

If everything checks out, the bundle for puppet should be available in the `target` folder

#### Build with Docker

`docker build -t nexus-repository-puppet:0.0.1 .`

#### Run as a Docker container

`docker run -d -p 8081:8081 --name nexus nexus-repository-puppet:0.0.1`

For further information like how to persist volumes check out [the GitHub repo for our official image](https://github.com/sonatype/docker-nexus3).

The application will now be available from your browser at http://localhost:8081

## Using Puppet With Nexus Repository Manager 3

[We have detailed instructions on how to get started here!](docs/PUPPET_USER_DOCUMENTATION.md)

## Compatibility with Nexus Repository Manager 3 Versions

The table below outlines what version of Nexus Repository the plugin was built against

| Plugin Version | Nexus Repository Version |
|----------------|--------------------------|
| v0.0.1 | 3.14.0-04 |

If a new version of Nexus Repository is released and the plugin needs changes, a new release will be made, and this
table will be updated to indicate which version of Nexus Repository it will function against. This is done on a time
available basis, as this is community supported. If you see a new version of Nexus Repository, go ahead and update the
plugin and send us a PR after testing it out!

All released versions can be found [here](https://github.com/sonatype-nexus-community/nexus-repository-puppet/releases).

## Features Implemented In This Plugin

| Feature | Implemented |
|---------|----------------------|
| Proxy | :heavy_check_mark: * |
| Hosted | |
| Group | |

`* tested primarily against the Puppet Forge, not guaranteed to work on the wide wild world of Puppet repositories.`

### Supported Puppet Commands

#### Proxy

| Plugin Version | Nexus Repository Version |
|------------------------------|--------------------------|
| `puppet module install` | :heavy_check_mark: |

`* these commands are not applicable to a proxy`

## Installing the plugin

There are a range of options for installing the puppet plugin. You'll need to build it first, and
then install the plugin with the options shown below:

### Temporary Install

Installations done via the Karaf console will be wiped out with every restart of Nexus Repository. This is a
good installation path if you are just testing or doing development on the plugin.

* Enable Nexus Repo console: edit `<nexus_dir>/bin/nexus.vmoptions` and change `karaf.startLocalConsole` to `true`.

More details here: [Bundle Development](https://help.sonatype.com/display/NXRM3/Bundle+Development+Overview)

* Run Nexus Repo console:
```
# sudo su - nexus
$ cd <nexus_dir>/bin
$ ./nexus run
> bundle:install file:///tmp/nexus-repository-puppet-0.0.1.jar
> bundle:list
```
(look for org.sonatype.nexus.plugins:nexus-repository-puppet ID, should be the last one)
```
> bundle:start <org.sonatype.nexus.plugins:nexus-repository-puppet ID>
```

### (more) Permanent Install

For more permanent installs of the nexus-repository-puppet plugin, follow these instructions:

* Copy the bundle (nexus-repository-puppet-0.0.1.jar) into <nexus_dir>/deploy

This will cause the plugin to be loaded with each restart of Nexus Repository. As well, this folder is monitored
by Nexus Repository and the plugin should load within 60 seconds of being copied there if Nexus Repository
is running. You will still need to start the bundle using the karaf commands mentioned in the temporary install.

### (most) Permanent Install

If you are trying to use the puppet plugin permanently, it likely makes more sense to do the following:

* Copy the bundle into `<nexus_dir>/system/org/sonatype/nexus/plugins/nexus-repository-puppet/0.0.1/nexus-repository-puppet-0.0.1.jar`
* Make the following additions marked with + to `<nexus_dir>/system/org/sonatype/nexus/assemblies/nexus-core-feature/3.x.y/nexus-core-feature-3.x.y-features.xml`

```
<feature prerequisite="false" dependency="false">nexus-repository-rubygems</feature>
+ <feature prerequisite="false" dependency="false">nexus-repository-puppet</feature>
<feature prerequisite="false" dependency="false">nexus-repository-gitlfs</feature>
</feature>
```
And
```
+ <feature name="nexus-repository-puppet" description="org.sonatype.nexus.plugins:nexus-repository-puppet" version="0.0.1">
+ <details>org.sonatype.nexus.plugins:nexus-repository-puppet</details>
+ <bundle>mvn:org.sonatype.nexus.plugins/nexus-repository-puppet/0.0.1</bundle>
+ </feature>
</features>
```
This will cause the plugin to be loaded and started with each startup of Nexus Repository.

## The Fine Print

It is worth noting that this is **NOT SUPPORTED** by Sonatype, and is a contribution of ours
to the open source community (read: you!)

Remember:

* Use this contribution at the risk tolerance that you have
* Do NOT file Sonatype support tickets related to puppet support in regard to this plugin
* DO file issues here on GitHub, so that the community can pitch in

Phew, that was easier than I thought. Last but not least of all:

Have fun creating and using this plugin and the Nexus platform, we are glad to have you here!

## Getting help

Looking to contribute to our code but need some help? There's a few ways to get information:

* Chat with us on [Gitter](https://gitter.im/sonatype/nexus-developers)
* Check out the [Nexus3](http://stackoverflow.com/questions/tagged/nexus3) tag on Stack Overflow
* Check out the [Nexus Repository User List](https://groups.google.com/a/glists.sonatype.com/forum/?hl=en#!forum/nexus-users)
58 changes: 58 additions & 0 deletions docs/PUPPET_USER_DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!--
Sonatype Nexus (TM) Open Source Version
Copyright (c) 2018-present 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.
-->
## Puppet Repositories

### Introduction

[Puppet](https://www.puppet.com/) is a application management format used to help automate and run an organizations
infrastructure, using Puppet Modules, which are effectively recipes for running an application.

### Proxying The Puppet Forge

You can set up a Puppet proxy repository to access a remote repository location, for example to proxy the stable Puppet
Modules at [the Puppet Forge](https://forge.puppet.com/)

To proxy a Puppet repository, you simply create a new 'puppet (proxy)' as documented in
[Repository Management](https://help.sonatype.com/repomanager3/configuration/repository-management) in
detail. Minimal configuration steps are:

- Define 'Name'
- Define URL for 'Remote storage' e.g. [https://forgeapi.puppet.com/](https://forgeapi.puppet.com/)
- Select a 'Blob store' for 'Storage'

### Configuring Puppet

There are relatively few steps for configuring Puppet to use Nexus Repository:

You'll need to have Puppet installed, for interaction with the Puppet Forge.

NOTE: These instructions are Linux/OS X specific.

Once you have Puppet up and running you'll want to run commands similar to the following:

You'll need to create a `puppet.conf` file at the following location if it does not exist:

`~/.puppet/puppet.conf`

In this file you'll need to add:

`module_repository = 'http://nexushostname:nexusport/repository/puppet-proxy-name'`

Once you've done this, you should be ready to install Puppet modules via `puppet install module`!

### Browsing Puppet Repository Packages

You can browse Puppet repositories in the user interface inspecting the components and assets and their details, as
described in [Browsing Repositories and Repository Groups](https://help.sonatype.com/display/NXRM3/Browsing+Repositories+and+Repository+Groups).
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2018-present 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.
*/
package org.sonatype.nexus.repository.puppet.internal;

import javax.annotation.Nonnull;

import org.sonatype.nexus.repository.cache.CacheControllerHolder.CacheType;

import static org.sonatype.nexus.repository.cache.CacheControllerHolder.*;

/**
* Asset kinds for Puppet
*
* Examples of all can be found at: https://forgeapi.puppetlabs.com/#interactive-demonstration
* @since 0.0.1
*/
public enum AssetKind
{
MODULE_RELEASES_BY_NAME(METADATA),
MODULE_RELEASE_BY_NAME_AND_VERSION(METADATA),
MODULE_DOWNLOAD(CONTENT);

private final CacheType cacheType;

AssetKind(final CacheType cacheType) {
this.cacheType = cacheType;
}

@Nonnull
public CacheType getCacheType() {
return cacheType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2018-present 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.
*/
package org.sonatype.nexus.repository.puppet.internal;

import java.io.IOException;
import java.io.InputStream;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.sonatype.goodies.common.ComponentSupport;
import org.sonatype.nexus.mime.MimeRulesSource;
import org.sonatype.nexus.repository.storage.ContentValidator;
import org.sonatype.nexus.repository.storage.DefaultContentValidator;

import com.google.common.base.Supplier;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* @since 0.0.1
*/
@Named(PuppetFormat.NAME)
@Singleton
public class PuppetContentValidator
extends ComponentSupport
implements ContentValidator
{
private final DefaultContentValidator defaultContentValidator;

@Inject
public PuppetContentValidator(final DefaultContentValidator defaultContentValidator) {
this.defaultContentValidator = checkNotNull(defaultContentValidator);
}

@Override
public String determineContentType(final boolean strictContentTypeValidation,
final Supplier<InputStream> contentSupplier,
final @Nullable MimeRulesSource mimeRulesSource,
final @Nullable String contentName,
final @Nullable String declaredContentType) throws IOException
{
if (contentName != null) {
if (!contentName.endsWith(".tar.gz")) {
// Note: Tika thinks the puppet json responses are text/plain since we aren't getting them as .json files
return defaultContentValidator.determineContentType(
false,
contentSupplier,
mimeRulesSource,
contentName + ".json",
declaredContentType);
}
}
return defaultContentValidator.determineContentType(
strictContentTypeValidation,
contentSupplier,
mimeRulesSource,
contentName,
declaredContentType
);
}
}
Loading

0 comments on commit 4394283

Please sign in to comment.