Skip to content

Commit

Permalink
Merge pull request #1 from l3ender/initial
Browse files Browse the repository at this point in the history
Basic Ansible Galaxy proxy support (collections) - 0.1.0
  • Loading branch information
l3ender authored Jan 2, 2021
2 parents 11d6688 + 71963e8 commit 6a07d30
Show file tree
Hide file tree
Showing 24 changed files with 664 additions and 260 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@
-->
<!-- generated with nexus-format-archetype version 1.0.48 on Dec 27, 2020 -->
# Nexus Repository AnsibleGalaxy Format
# Nexus Repository Ansible Galaxy Format

[![Maven Central](https://img.shields.io/maven-central/v/org.sonatype.nexus.plugins/nexus-repository-ansiblegalaxy.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22org.sonatype.nexus.plugins%22%20AND%20a:%22nexus-repository-ansiblegalaxy%22) [![CircleCI](https://circleci.com/gh/sonatype-nexus-community/nexus-repository-ansiblegalaxy.svg?style=shield)](https://circleci.com/gh/sonatype-nexus-community/nexus-repository-ansiblegalaxy) [![Join the chat at https://gitter.im/sonatype/nexus-developers](https://badges.gitter.im/sonatype/nexus-developers.svg)](https://gitter.im/sonatype/nexus-developers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![DepShield Badge](https://depshield.sonatype.org/badges/sonatype-nexus-community/nexus-repository-ansiblegalaxy/depshield.svg)](https://depshield.github.io)

# Table Of Contents

* [Developing](#developing)
* [Requirements](#requirements)
* [Download](#download)
* [Building](#building)
* [Using AnsibleGalaxy with Nexus Repository Manager 3](#using-ansiblegalaxy-with-nexus-repository-manager-3)
* [Using Ansible Galaxy with Nexus Repository Manager 3](#using-ansiblegalaxy-with-nexus-repository-manager-3)
* [Compatibility with Nexus Repository Manager 3 Versions](#compatibility-with-nexus-repository-manager-3-versions)
* [Features Implemented In This Plugin](#features-implemented-in-this-plugin)
* [Supported AnsibleGalaxy Commands](#supported-ansiblegalaxy-commands)
* [Supported Ansible Galaxy Commands](#supported-ansible-galaxy-commands)
* [Installing the plugin](#installing-the-plugin)
* [Easiest Install](#easiest-install)
* [Temporary Install](#temporary-install)
Expand All @@ -50,7 +49,7 @@ You may also find it helpful to configure your IDE to use the [Sonatype Code sty

### Download

Find pre-compiled files [here](https://search.maven.org/search?q=g:%22org.sonatype.nexus.plugins%22%20AND%20a:%22nexus-repository-ansiblegalaxy%22).
Pre-compiled plugin files can be found on the [releases page](https://github.com/l3ender/nexus-repository-ansiblegalaxy/releases).

### Building

Expand Down Expand Up @@ -78,7 +77,7 @@ To read the generated admin password for your first login to the web UI, you can

For simplicity, you should check `Enable anonymous access` in the prompts following your first login.

## Using AnsibleGalaxy With Nexus Repository Manager 3
## Using Ansible Galaxy With Nexus Repository Manager 3

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

Expand All @@ -95,7 +94,7 @@ table will be updated to indicate which version of Nexus Repository it will func
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-ansiblegalaxy/releases).
All released versions can be found on [the releases page](https://github.com/l3ender/nexus-repository-ansiblegalaxy/releases).

## Features Implemented In This Plugin

Expand All @@ -105,13 +104,16 @@ All released versions can be found [here](https://github.com/sonatype-nexus-comm
| Hosted | |
| Group | |

### Supported AnsibleGalaxy Commands
### Supported `ansible-galaxy` Commands

#### Proxy

| Plugin Version | Nexus Repository Version |
|------------------------------|--------------------------|
| `ansiblegalaxy client command` | :heavy_check_mark: |
| `ansible-galaxy collection install` | :heavy_check_mark: |

Be sure to [configure the `ansible-galaxy` client](docs/ansiblegalaxy_user_documentation.md#configuring-the-ansible-galaxy-client).


## Installing the plugin

Expand All @@ -123,7 +125,7 @@ then install the plugin with the options shown below:
Thanks to some upstream work in Nexus Repository, it's become a LOT easier to install a plugin. To install the `ansiblegalaxy` plugin, follow these steps:

* Build the plugin with `mvn clean package -PbuildKar`
* Copy the `nexus-repository-ansiblegalaxy-0.0.1-bundle.kar` file from your `target` folder to the `deploy` folder for your Nexus Repository installation.
* Copy the `nexus-repository-ansiblegalaxy-*-bundle.kar` file from your `target` folder to the `deploy` folder for your Nexus Repository installation.

Once you've done this, go ahead and either restart Nexus Repo, or go ahead and start it if it wasn't running to begin with.

Expand Down Expand Up @@ -197,7 +199,7 @@ by the Sonatype Support team to remove the community item in order to determine
Remember:

* Use this contribution at the risk tolerance that you have
* Do NOT file Sonatype support tickets related to AnsibleGalaxy support in regard to this plugin
* Do NOT file Sonatype support tickets related to Ansible Galaxy 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:
Expand Down
44 changes: 30 additions & 14 deletions docs/ansiblegalaxy_user_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,46 @@
-->

### Overview

[AnsibleGalaxy](https://add_URL_To_Format_Info_Here/) provides Add_Format_Description_Here.
[Ansible Galaxy](https://galaxy.ansible.com/) provides a way to install community collections and roles for Ansible.

Full documentation on installing `ansible-galaxy` can be found on [the Ansible Galaxy project website](https://docs.ansible.com/ansible/latest/galaxy/user_guide.html).

Full documentation on installing `ansiblegalaxy` can be found on [the AnsibleGalaxy project website](https://add_Format_Install_Info_URL/).
You can create a proxy repository in Nexus Repository Manager (NXRM) that will cache packages from a remote Ansible Galaxy repository, like
[https://galaxy.ansible.com/](https://galaxy.ansible.com/). Then, you can make the `ansible-galaxy` client use your Nexus Repository Proxy
instead of the remote repository.

### Installation

You can create a proxy repository in Nexus Repository Manager (NXRM) that will cache packages from a remote AnsibleGalaxy repository, like
[Add_Format_Repo_Name](https://add_format_repo_url/). Then, you can make the `ansiblegalaxy` client use your Nexus Repository Proxy
instead of the remote repository.
See [installing the plugin](../README.md#installing-the-plugin).

### Repository configuration

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

- Define 'Name' - e.g. `ansiblegalaxy-proxy`
- Define URL for 'Remote storage' - e.g. [https://add_format_repo_url/](https://add_format_repo_url/)
- Define URL for 'Remote storage' - e.g. [https://galaxy.ansible.com/](https://galaxy.ansible.com/)
- Select a `Blob store` for `Storage`

Using the `ansiblegalaxy` client, you can now download packages from your NXRM AnsibleGalaxy proxy like so:
### Configuring the `ansible-galaxy` client

You must set the Galaxy API endpoint/server when using the client, either by:
* provide the `-s API_SERVER` or `--server API_SERVER` argument for each installation command.
* configure `GALAXY_SERVER` configuration value or `ANSIBLE_GALAXY_SERVER` environment variable.

See the following resources for additional detail:
* [Ansible documentation on configuring the `ansible-galaxy` client](https://docs.ansible.com/ansible/latest/galaxy/user_guide.html#configuring-the-ansible-galaxy-client).
* [Ansible configuration documentation](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#galaxy-server)).

### Usage

Using the `ansible-galaxy` client, you can now download packages from your NXRM Ansible Galaxy proxy:

```bash
ansible-galaxy collection install azure.azcollection -s http://localhost:8081/repository/ansible/
```

$ add client command line example here

The command above tells ansiblegalaxy to fetch (and install) packages from your NXRM AnsibleGalaxy proxy. The NXRM AnsibleGalaxy proxy will
download any missing packages from the remote AnsibleGalaxy repository, and cache the packages on the NXRM AnsibleGalaxy proxy.
The next time any client requests the same package from your NXRM AnsibleGalaxy proxy, the already cached package will
be returned to the client.
The command above tells ansible-galaxy to fetch (and install) packages from your NXRM Ansible Galaxy proxy. The NXRM Ansible Galaxy proxy will download any missing packages from the remote Ansible Galaxy repository, and cache the packages on the NXRM Ansible Galaxy proxy. The next time any client requests the same package from your NXRM Ansible Galaxy proxy, the already cached package will be returned to the client.
2 changes: 1 addition & 1 deletion nexus-repository-ansiblegalaxy-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.sonatype.nexus.plugins</groupId>
<artifactId>nexus-repository-ansiblegalaxy-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.1.0</version>
</parent>

<artifactId>nexus-repository-ansiblegalaxy-it</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
public class AnsibleGalaxyClient
extends FormatClientSupport
{
public AnsibleGalaxyClient(final CloseableHttpClient httpClient,
final HttpClientContext httpClientContext,
final URI repositoryBaseUri)
public AnsibleGalaxyClient(
final CloseableHttpClient httpClient,
final HttpClientContext httpClientContext,
final URI repositoryBaseUri)
{
super(httpClient, httpClientContext, repositoryBaseUri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ protected AnsibleGalaxyClient ansiblegalaxyClient(final Repository repository) t
}

protected AnsibleGalaxyClient ansiblegalaxyClient(final URL repositoryUrl) throws Exception {
return new AnsibleGalaxyClient(
clientBuilder(repositoryUrl).build(),
clientContext(),
repositoryUrl.toURI()
);
return new AnsibleGalaxyClient(clientBuilder(repositoryUrl).build(), clientContext(), repositoryUrl.toURI());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,26 @@
import static org.hamcrest.Matchers.is;
import static org.sonatype.goodies.httpfixture.server.fluent.Behaviours.content;
import static org.sonatype.goodies.httpfixture.server.fluent.Behaviours.error;
import static org.sonatype.nexus.plugins.ansiblegalaxy.internal.util.AnsibleGalaxyPathUtils.PACKAGE_FILENAME;
import static org.sonatype.nexus.testsuite.testsupport.FormatClientSupport.status;

public class AnsibleGalaxyProxyIT
extends AnsibleGalaxyITSupport
{
// @todo Change test path for your format
private static final String TEST_PATH = "some/valid/path/for/your/remote/" + PACKAGE_FILENAME;
private static final String TEST_PATH = "api/v2/collections/azure/azcollection/versions/";

private AnsibleGalaxyClient proxyClient;

private Repository proxyRepo;

@Configuration
public static Option[] configureNexus() {
return NexusPaxExamSupport.options(
NexusITSupport.configureNexusBase(),
nexusFeature("org.sonatype.nexus.plugins", "nexus-repository-ansiblegalaxy")
);
return NexusPaxExamSupport.options(NexusITSupport.configureNexusBase(),
nexusFeature("org.sonatype.nexus.plugins", "nexus-repository-ansiblegalaxy"));
}

@Test
public void unresponsiveRemoteProduces404() throws Exception {
Server server = Server.withPort(0).serve("/*")
.withBehaviours(error(HttpStatus.NOT_FOUND))
.start();
Server server = Server.withPort(0).serve("/*").withBehaviours(error(HttpStatus.NOT_FOUND)).start();
try {
proxyRepo = repos.createAnsibleGalaxyProxy("ansiblegalaxy-test-proxy-notfound", server.getUrl().toExternalForm());
proxyClient = ansiblegalaxyClient(proxyRepo);
Expand All @@ -66,9 +60,7 @@ public void unresponsiveRemoteProduces404() throws Exception {

@Test
public void retrieveAnsibleGalaxyWhenRemoteOffline() throws Exception {
Server server = Server.withPort(0).serve("/*")
.withBehaviours(content("Response"))
.start();
Server server = Server.withPort(0).serve("/*").withBehaviours(content("Response")).start();
try {
proxyRepo = repos.createAnsibleGalaxyProxy("ansiblegalaxy-test-proxy-offline", server.getUrl().toExternalForm());
proxyClient = ansiblegalaxyClient(proxyRepo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ import groovy.transform.CompileStatic
*/
@CompileStatic
trait AnsibleGalaxyRepoRecipes
extends ConfigurationRecipes
{
extends ConfigurationRecipes {
@Nonnull
Repository createAnsibleGalaxyProxy(final String name, final String remoteUrl)
{
Repository createAnsibleGalaxyProxy(final String name, final String remoteUrl) {
createRepository(createProxy(name, 'ansiblegalaxy-proxy', remoteUrl))
}

@Nonnull
Repository createRHosted(final String name)
{
Repository createAnsibleGalaxyHosted(final String name) {
createRepository(createHosted(name, 'ansiblegalaxy-hosted'))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import org.sonatype.nexus.repository.manager.RepositoryManager
import org.sonatype.nexus.testsuite.testsupport.fixtures.RepositoryRule

class RepositoryRuleAnsibleGalaxy
extends RepositoryRule
implements AnsibleGalaxyRepoRecipes
{
extends RepositoryRule
implements AnsibleGalaxyRepoRecipes {
RepositoryRuleAnsibleGalaxy(final Provider<RepositoryManager> repositoryManagerProvider) {
super(repositoryManagerProvider)
}
Expand Down
2 changes: 1 addition & 1 deletion nexus-repository-ansiblegalaxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.sonatype.nexus.plugins</groupId>
<artifactId>nexus-repository-ansiblegalaxy-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.1.0</version>
</parent>

<artifactId>nexus-repository-ansiblegalaxy</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.plugins.ansiblegalaxy.internal;
package org.sonatype.nexus.plugins.ansiblegalaxy;

import javax.inject.Named;
import javax.inject.Singleton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.plugins.ansiblegalaxy.internal;
package org.sonatype.nexus.plugins.ansiblegalaxy;

import javax.annotation.Nonnull;

Expand All @@ -24,9 +24,10 @@
*/
public enum AssetKind
{
// @todo Change these enums as needed for this format
PACKAGES(METADATA),
ARCHIVE(CONTENT);
API_INTERNALS(METADATA),
VERSION_LIST(METADATA),
VERSION(METADATA),
ARTIFACT(CONTENT);

private final CacheType cacheType;

Expand Down
Loading

0 comments on commit 6a07d30

Please sign in to comment.