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 |
|
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.
Before you begin, make sure:
- Git is installed
- Clone this repository to your local machine:
git clone [email protected]:kabanero-io/guide-nexus-repository-integration.git
- This guide will reference this code. All references to this repository are under the
guide-nexus-repository-integration/code/
directory.
- This guide will reference this code. All references to this repository are under the
- Have Nexus Repository Manager 3 installed
- Your Maven proxy has been setup on Nexus Repository Manager 3
- Appsody has been installed
- Codewind has been installed on either VS Code or Eclipse
- Docker is installed
- Maven is installed
- The
settings.xml
file with the server credentials is passed to the various Maven calls. However, on the final application stack image, thesettings.xml
file is removed after all the Maven calls are made to ensure the credentials are not shared outside of development.
- The
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 ishttp://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 passwordadmin123
. - 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.
Follow these steps:
-
Create a new Application Stack by running
appsody stack create my-java-microprofile --copy incubator/java-microprofile
on your operating system terminal. -
Ensure you have your
settings.xml
file in your Maven home directory (e.g.~/.m2
). An examplesettings.xml
can be found in the cloned repo undercode/my-java-microprofile/image/project/settings.xml
. -
Go to the generated
my-java-microprofile
directory. -
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
, andcode/my-java-microprofile/image/templates/default/pom.xml
. -
For any mention of
mvn
ormvnw
, thesettings.xml
needs to be passed in to ensure the propersettings.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 toio.takari:maven:0.6.1:wrapper
due to an authentication issue with the latest wrapper (takari/maven-wrapper/issues/142)
-
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 -
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
-
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: -
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
-
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.
- Copy your displayName and description from
-
Upload your files as a release onto GitHub. For example:
https://github.com/sghung/appsodystacks/releases/tag/0.1.0
-
Open Codewind and go to Manage Template Sources.
-
Add your JSON file. For example:
https://github.com/sghung/appsodystacks/releases/download/0.1.0/sghung-index.json
-
Create a new Codewind project and you should see your repo and
my-java-microprofile
. -
Choose it and a directory of your choosing to install the files into.
-
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.
Before you begin, ensure that:
- Nexus Repository Manager 3 has been installed
- NPM proxy has been set up on Nexus Repository Manager 3
- Appsody has been installed
- Codewind has been installed on either VS Code or Eclipse
- Docker is installed
- NPM is installed
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 passwordadmin123
- 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.
Follow these steps:
-
Create a new Application Stack by running
appsody stack create my-nodejs-express --copy incubator/nodejs-express
on your operating system terminal. -
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 iscode/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. -
Search for "npm audit" and remove all mentions of it. The removal is required due to this NEXUS-16954 issue.
-
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.
-
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]. -
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. -
Upload your files as a release onto GitHub. For example:
https://github.com/sghung/appsodystacks/releases/tag/0.1.1
-
Open Codewind and go to Manage Template Sources.
-
Add your JSON file. For example:
https://github.com/sghung/appsodystacks/releases/download/0.1.1/sghung2-index.json
-
Create a new Codewind project and you should see your repo and my-nodejs-express.
-
Choose it and a directory of your choosing to install the files into.
-
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 ascode/my-nodejs-express/image/project/sampleCredentials
The application should go into a running state and can be used for development.
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%.