1. Nexus Repository OSS

Is a free tool used to store warehouse, can be used to store JAR, Docker, NPM and other software packages, can also store other file formats, does not rely on mysql, etc., download packages can be directly run. The supported list is shown in the following figure

2. Download & Run (take Docker as an example)

2.1 Pulling the Nexus3 Image

#Operation instruction
docker pull sonatype/nexus3
Copy the code

2.2 Establishing Volume Persistent Data

#Operation instruction
docker volume create --name nexus-data
Copy the code

2.3 Running a Container

#Operation instruction
docker run --privileged=true -d -p 8801:8081 --name nexus -v nexus-data:/nexus-data sonatype/nexus3 
Copy the code

You can see that the container is already running on port 8801

Tip: -id create a daemon container –privileged=true Grant root permission (must be true to mount multiple directories, otherwise the container has insufficient access to the host) –name= name Give your container a name -p Host port: container port mapping -v Host directory: Container directory Directory mount

3 Login & Create Host (private) proxy group(open) repository

3.1 Obtaining the Login Password

Open/var/lib/docker/volumes/nexus – data / _data while forming under the admin password, copy the password, and then reset your password after login

3.2 Creating a Host (private) Proxy group(open) repository

3.2.1 NPM – host

3.2.2 NPM – proxy

3.2.3 NPM – group

4 Adding a Role

You need to log in first to publish the NPM package, but we just want to publish the package to our own private server.

4.1. Add permission authentication

Set permissions, Realms menu, and add NPM Bearer Token Realm to the right

4.2. Create the NX-deploy role

Grant the role the following permissions/nx-repository--* nx-repository-admin-npm-npm-group-* nx-repository-admin-npm-npm-proxy-* nx-repository-admin-npm-npm-host-*

4.3. Create a role and set the role to nx-deploy

5. Create the first NPM package

5.1 Creating a. NPMRC Configuration for a Client (Created in a directory File)

The purpose of this file is to avoid having to log in every time NPM Publish

# configuration registry = http://10.7.4.11:8801/repository/npm-group/ [email protected] always - auth = true # _auth for your account: your password The base64 encoding _auth = "TWljaGFlbEpvcmRhbjoxMjM0NTY ="Copy the code

5.2 Initialize the NPM project and add the configuration of PublishConfig. registry

# Run the command NPM initCopy the code
# configuration {" name ":" GDPG - utils ", "version" : "1.0.1", "description" : ""," main ":" index. Js ", "scripts" : {" test ": "echo \"Error: no test specified\" && exit 1" }, "publishConfig": { "registry": "Http://10.7.4.11:8801/repository/npm-host/"}, "author" : ""," license ":" ISC ", "dependencies" : {" GDPG - utils ": "Http://10.7.4.11:8801/repository/npm-host/gdpg-utils/-/gdpg-utils-1.0.1.tgz"}}Copy the code

5.3 Create index.js and upload the NPM package through NPM Publish

5.4 Test the project by referring to the GDPG-utils package published in nexus

For more information on how to reference NPM packages, see the following article: NPM Dependency Management

# configuration "dependencies" : {" GDPG - utils ":" http://10.7.4.11:8801/repository/npm-host/gdpg-utils/-/gdpg-utils-1.0.1.tgz "}Copy the code
# Run the command NPM installCopy the code

You can see that you have successfully downloaded the NPM package that you just uploaded to your private server

5.5 Using the caching effect of npm-proxy to cache the downloaded NPM packages, ensuring that when the NPM package of the same version is loaded the second time, the NPM package cache in nexus is directly loaded

# set the project warehouse address NPM config set registry at http://10.7.4.11:8801/repository/npm-group/Copy the code
NPM install axiosCopy the code

6 Reference Documents

Build nexus 3.x private server in Linux

Use Nexus3 Repository Manager to build a private NPM server

7 summary

NPM private server setup is only the first step, how to manage the NPM version number? How does an NPM package manage multiple dependencies? How do I solve the problem of different NPM package versions in different systems? How to efficiently develop NPM components in a development environment? These problems need to be thought about when NPM private server management landed.