Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Do not update this repo: moved to guides repo. This repo will be archived soon.

Notifications You must be signed in to change notification settings

kabanero-io/guide-nexus-repository-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 

Repository files navigation

permalink layout title duration releasedate description tags guide-category
/guides/nexus-repository-integration-with-appsody/
guide-markdown
Nexus Repository Integration
40 minutes
2020-02-21
Learn how to use Nexus Repository in Codewind
Codewind
Java
Nodejs

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(tm)), 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, there is a Working with Stacks 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

Before you begin, make sure:

What to expect in this example

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 the user name admin and password admin123.
  • You are creating a Maven project based on the 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, see the Prerequisites section.

Steps

Follow these 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, add the Maven proxy as a <repository>. You must update three files. You can view the needed updates in this guide's cloned repository: 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 is 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)
  1. 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, see the Appsody publishing documentation

  2. The development environment 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

  3. 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:

  4. 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
  5. 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.
  6. Upload your files as a release onto GitHub. For example: https://github.com/sghung/appsodystacks/releases/tag/0.1.0

  7. Open Codewind and go to Manage Template Sources.

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

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

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

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

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

Creating an Application Stack that pulls from a NPM proxy

Prerequisites

Before you begin, ensure that:

What to expect in this example

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 the nodejs-express application 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

Follow these 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 is code/my-nodejs-express/image/project/sampleCredentials. Make sure your credentials 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.
  1. 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 link:https://appsody.dev/docs/stacks/publish[Appsody publishing documentation].

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

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

  4. Open Codewind and go to Manage Template Sources.

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

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

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

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

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

Performance

In some environments using a a Nexus Repository can improve the speed of application build times. This is because the dependencies to download will be closer to where the application is being built.

For example, building a microprofie application with the java-openliberty appsody stack with IBM Cloud Pak for Applications on Openshift Container Platform using Nexus improved build times by 35%.

About

Do not update this repo: moved to guides repo. This repo will be archived soon.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published