fbpixel

Nexus 3 Npm Registry

Davide Conti}
Davide Conti
Share:

Deploy a Nexus 3 Npm Registry!

Part of our mission at HakunaCloud is to help companies embracing the DevOps methodology. Cloud Computing and containers simplify the adoption of the so called Full CI/CD pipeline, and Nexus 3 is useful as a private repository for npm packages.

In this post, we’re going to deploy Nexus 3 and configure an npm registry on it.

How to Deploy Nexus 3

Beekube is a managed container platform, that run on top of the cloud computing power provided by AWS and Google Cloud. Basically, it is docker in the clouds :). For this tutorial we’ll deploy the Nexus 3 image available on docker-hub.

Create a network

A network isolate containers. Containers within the same network can connect each other using a service discovery system based on their names.

beekube network create nexus3

Create a persistent volume

Nexus 3 persist all its data and configuration in the /nexus-data folder. We want that folder to be persisted - we don’t want to loose the configuration if the container is restarted!

Create a persistent volume of 20 gb with this command:

beekube volume create nexus-data --size 20

Run Nexus 3!

Now we can run the service. We need to:

  • expose it to the internet: -p 80:8081
  • mount the volume: -v nexus-data:/nexus-data
  • give to it a name and the network: --name nexus3 --network nexus3
  • give 4 CPUs to the container (nexus recommendation): -c 4

So that’s the run command:

beekube run --name nexus3 --network nexus3 -p 80:8081 -c 4 -v nexus-data:/nexus-data sonatype/nexus3

Nexus 3 Setup

Now we can use the Nexus 3 web ui. Beekube automatically maps a FQDN fur us, that we can retrieve with beekube ps:

name     image           status   publishs
-------  --------------  -------  ----------------------------------------------------------------------------------
nexus3  sonatype/nexus3  running  nexus3.eu-central-1.<ns>.v1.beekube.cloud:80 -> 8081

Let’s open a browser to http://nexus3.eu-central-1.<ns>.v1.beekube.cloud

Nexus 3 creates a one-time password for the first admin login. We must retrieve it from the volume, we can access it using an additional container running an ssh server that shares the same volume:

beekube run --name nexus-ssh --network nexus3 -p 22:22 -v nexus-data:/nexus-data rastasheep/ubuntu-sshd

Now, retrieve the FQDN using beekube ps and connect to the container using ssh to retrieve the admin’s password:

ssh root@nexus-ssh.eu-central-1.<ns>.v1.beekube.cloud   # The psw is "root"
cat /nexus-data/admin.password; echo    # Execute this inside the ssh session

Click sign-in and follow the wizard to set a new password.

That’s it! We can now proceed with the npm registry configuration!

Npm Registry

To quickly create an npm register open the administration panel on Nexus 3 and follow those steps:

  • Go to repositories list and create an npm-hosted repository
  • Active npm Bearer Token Realm from the Realms panel (npm needs it to login!)
  • From the Roles panel create a role and give it permissions to admin and view the repository
  • From the Users panel create the users allowed to use the repository, of course be sure to assign them the role created above.

Lastly, configure npm to use the private registry with the following commands:

npm config set registry <repo-url> # Get this from the repositories list
npm login --registry=<repo-url> 

If you need to manage multiple registry, check out the npm docs.

Junior Cloud Developer @ BeeKube

Computer Engineer, one year experience as full stack web developer. Currently involved in cloud computing area.

"K.I.S.S."