Check out what's in the latest release of Kabanero Learn More

Nexus Repository Integration

duration 40 minutes

What you will learn

Nexus Repository is a popular repository manager that provides a single source of truth for all of the software components used by the applications in an enterprise. It provides a single access and control point for Maven (Java), npm (Node JS) and other software dependencies. It can also be used to manage or govern dependencies, or reduce the build dependencies on multiple external repositories and internet access.

With an Application Stack, the owner of each stack can provide a default repository manager, force the use of a specific repository manager instance, or block the use of a repository manager. The current Java Microprofile and Node JS Express stacks restrict repository access, so if you want to use Nexus Repository you’ll need to create your own stack. You can start by copying and customizing an existing stack rather than starting from scratch.

The remainder of this guide will walk you through the steps required to configure a Nexus Repository for both a Java and Node JS stack. If you are not familiar with customizing stacks and collections, there is a Working with Collections guide that provides some background and walks you through all of the required steps. If you’re already familiar with customizing stacks and have your own, you may want to skip to steps 4 & 5 (for Maven) and steps 2-5 (for NPM) to focus just on the Nexus Repository configuration. Following these steps will create an application stack that uses Nexus Repository management for both development and build time of your applications.

Creating an Application Stack that pulls from a Maven proxy

Prerequisites

What to expect in this example

  • We will assume the IP address of your Nexus Repository Manager is at http://9.108.127.66:8081 and your Maven public proxy URL is http://9.108.127.66:8081/repository/maven-public/. Do not use localhost as some Maven commands are run in a Docker container and localhost will not resolve correctly

  • Your Nexus Repository Manager is using the default credentials with user name admin and password admin123

  • You are creating a Maven project based on Appsody’s java-microprofile stack

  • The complete example can be found in this cloned repository under code/my-java-microprofile/stack.yaml. If you have not already cloned the repository, please view the Prerequisites section above.

Steps

  1. Create a new Application Stack by running appsody stack create my-java-microprofile --copy incubator/java-microprofile on your operating system terminal

  2. Ensure you have your settings.xml file in your Maven home directory (e.g. ~/.m2). An example settings.xml can be found in the cloned repo under code/my-java-microprofile/image/project/settings.xml

  3. Go to the generated my-java-microprofile directory

  4. For every pom.xml, the Maven proxy needs to be added as a <repository>. Three files will need to be updated. You can view the updates needed in this guides cloned repository from these files: code/my-java-microprofile/image/project/pom.xml, code/my-java-microprofile/image/project/pom-dev.xml, and code/my-java-microprofile/image/templates/default/pom.xml.

  5. For any mention of mvn or mvnw, the settings.xml needs to be passed in to ensure the proper settings.xml configuration needs to be used.  Note: .appsody-init.bat and .appsody-init-sh calls from your operating system, so it references ~/.m2/settings.xml, not /.m2/settings.xml. See the following files for all the changes:

    • code/my-java-microprofile/image/project/.appsody-init.bat

    • code/my-java-microprofile/image/project/.appsody-init.sh

    • code/my-java-microprofile/image/project/Dockerfile

    • code/my-java-microprofile/image/project/install-dev-deps.sh

    • code/my-java-microprofile/image/project/validate.sh

    • code/my-java-microprofile/image/Dockerfile-stack

      • io.takari:maven:wrapper is changed to io.takari:maven:0.6.1:wrapper due to an authentication issue with the latest wrapper (takari/maven-wrapper/issues/142)

  6. Go to the root directory of your stack and run appsody stack package.  For the purpose of this example, the publishing is done into the local dev.local and the images are not pushed to Docker hub. To push to Docker hub, follow the Appsody publishing documentation

  7. The Appsody command line will output logs. Ensure you only see your proxy being used and not the official Maven repository (https://repo1.maven.org/maven2). For example, we want to see logs like: [Docker] [INFO] Downloading from nexus: http://9.108.127.66:8081/repository/maven-public/org/apache/maven/maven-model/3.2.3/maven-model-3.2.3.jar

  8. Run appsody stack add-to-repo sghung --release-url https://github.com/sghung/appsodystacks/releases/latest/download/ in your Appsody stack root directory. Replace the repository with your own Github repository

  9. Go to ~/.appsody/stacks/dev.local. By default, Appsody home is ~/.appsody. Your generated files will be located here. The important files are:

    • my-java-microprofile.v0.2.21.templates.default.tar.gz

    • sghung-index.yaml

  10. For Codewind to pickup the stacks, a sghung-index.json needs to be generated. The format of the JSON format is of the form: code/sghung-index.json

    • Copy your displayName and description from sghung-index.yaml

    • Update the language to Java

    • Ensure the location will be where you upload the stack on GitHub

    • The link can be left as is. It is required by Codewind but will not be used

  11. Upload your files as a release onto GitHub. For example: https://github.com/sghung/appsodystacks/releases/tag/0.1.0

  12. Open Codewind and go to Manage Template Sources

  13. Add your JSON file. For example: https://github.com/sghung/appsodystacks/releases/download/0.1.0/sghung-index.json

  14. Create a new Codewind project and you should see your repo and my-java-microprofile

  15. Choose it and a directory of your choosing to install the files into

  16. View the project logs to ensure it is downloading from your Maven proxy

  17. The application should go into a running state and can be used for development

Creating an Application Stack that pulls from a NPM proxy

What to expect in this example

  • We will assume the IP address of your Nexus Repository Manager is at http://9.108.127.66:8081 and your NPM public proxy URL is http://9.108.127.66:8081/repository/npm-all/. Do not use localhost as some Maven commands are run in a Docker container and localhost will not resolve correctly

  • Your Nexus Repository Manager is using the default credentials with user name admin and password admin123

  • You are creating a Maven project based on Appsody’s nodejs-express stack

  • The complete example can be found in the cloned repository under code/my-nodejs-express

  • For the NPM proxy, the logs do not show logs that it is pulling from the NPM proxy. Instead, browse the NPN proxy to ensure it is being populated

  • The sampleCredentials file included in this example should not be checked into a repository. This file is just for this guide to show the format

Steps

  1. Create a new Application Stack by running appsody stack create my-nodejs-express --copy incubator/nodejs-express on your operating system terminal

  2. From following the NPM proxy information in the prerequisites, you should have an encrypted authentication. For the default password of admin123, the value is _auth=YWRtaW46YWRtaW4xMjM=. Create a credentials file in image/project and add the server credentials for the registry. An example of the final file can be found via code/my-nodejs-express/image/project/sampleCredentials. Make sure this file does not get checked into your repository to avoid the credentials being stored inappropriately

  3. Search for "npm audit" and remove all mentions of it. The removal is required due to this NEXUS-16954 issue.

  4. Modify the Dockerfile-stack and Dockerfile to use .npmrc before calling any npm install commands

    • code/my-nodejs-express/image/Dockerfile-stack

    • code/my-nodejs-express/image/project/Dockerfile

    • For both these files, the .npmrc is removed after npm install is called to avoid having the credentials show up in the Docker image

  5. Go to the root directory of your stack and run appsody stack package.  For the purpose of this example, the publishing is done into the local dev.local and the images are not pushed to Docker hub. To push to Docker hub, follow the Appsody publishing documentation.

  6. Run appsody stack add-to-repo sghung2 --release-url https://github.com/sghung/appsodystacks/releases/latest/download/ in your Appsody stack root directory. Replace the repository with your own GitHub repository

  7. Upload your files as a release onto GitHub. For example: https://github.com/sghung/appsodystacks/releases/tag/0.1.1

  8. Open Codewind and go to Manage Template Sources

  9. Add your JSON file. For example: https://github.com/sghung/appsodystacks/releases/download/0.1.1/sghung2-index.json

  10. Create a new Codewind project and you should see your repo and my-nodejs-express

  11. Choose it and a directory of your choosing to install the files into

  12. The application developer must put the .npmrc file into the root directory of the project. It should not be packaged up into the stack’s template or be checked into the repository. The stack architect needs to inform the application developer that credentials are needed and securely share the credentials with the application developer. The contents of the .npmrc file will be the same as code/my-nodejs-express/image/project/sampleCredentials

  13. The application should go into a running state and can be used for development

Way to go! What's next?

What could make this guide better?

Raise an issue to share feedback

Create a pull request to contribute to this guide

Need help?

Ask a question on Stack Overflow

Where to next?