Vagrant Environment for a Nexus Repository OSS service
This is a Vagrant Environment for a Nexus Repository OSS service.
This will:
adhoc-package
repository.npm-group
, npm-hosted
and npmjs.org-proxy
repositories.chocolatey-group
, chocolatey-hosted
and chocolatey.org-proxy
repositories.powershell-group
, powershell-hosted
and powershellgallery.com-proxy
repositories.nuget-hosted
repository to accept pushing with an API key.maven-snapshots
repository.deployer
role.config_authentication='ldap'
is set inside the provision-nexus.sh
file).use-*
files).NB If you are new to Groovy, be sure to check the Groovy Learn X in Y minutes page.
Build and install the Ubuntu 22.04 Base Box.
Build and install the Windows 2022 Base Box.
Add the following entry to your /etc/hosts
file:
192.168.56.3 nexus.example.com
Install Vagrant 2.1+.
Run vagrant up --provider=virtualbox # or --provider=libvirt
to launch the environment.
Access the Nexus home page and login as the admin
user and password admin
.
You can also login with one of the example accounts, e.g. alice.doe
and password password
.
NB nginx is setup with a self-signed certificate that you have to trust before being able to access the local Nexus home page.
function nexus-component-exists {
[ \
"$(
http \
get \
https://nexus.example.com/service/rest/v1/search \
"repository==$1" \
"name==$2" \
"version==$3" \
| jq -r .items[].name)" == "$2" \
]
}
if nexus-component-exists npm-hosted hello-world 1.0.0; then
echo 'component exists'
else
echo 'component does not exists'
fi
With PowerShell:
function Test-NexusComponent {
param(
[string]$repository,
[string]$name,
[string]$version)
$items = (Invoke-RestMethod `
-Method Get `
-Uri https://nexus.example.com/service/rest/v1/search `
-Body @{
repository = $repository
name = $name
version = $version
}).items
$items.Count -and ($items.name -eq $name)
}
if (Test-NexusComponent npm-hosted hello-world 1.0.0) {
Write-Host 'component exists'
} else {
Write-Host 'component does not exists'
}
The logs are at /opt/nexus/log/nexus.log
.
You can also see them with journalctl -u nexus
.
Nexus uses OrientDB as its database. To directly use it from the console run:
sudo su -l # switch to the root user.
systemctl stop nexus # make sure nexus is not running while you use the database.
su -s /bin/bash nexus # switch to the nexus user.
nexus_home=/opt/nexus/nexus-3.58.1-02 # make sure you have the correct version here.
nexus_data=$nexus_home/../sonatype-work/nexus3
function orientdb-console {
java -jar $nexus_home/lib/support/nexus-orient-console.jar $*
}
cd $nexus_data
ls -laF db | grep ^d # list the databases
orientdb-console # start the console.
Then connect to one of the databases, e.g. to the security
database:
connect plocal:db/security admin admin
Then execute some commands and exit the orientdb console, e.g.:
help
config
list classes
exit
Exit the nexus user shell:
exit
And start nexus again:
systemctl start nexus
For more information about the console see Running the OrientDB Console.
Execute the commands from the OrientDB section to stop nexus, to enter the
nexus account and create the orientdb-console
function, then:
# check the databases.
# NB use CHECK DATABASE -v to see the verbose log.
orientdb-console 'CONNECT PLOCAL:db/component admin admin; CHECK DATABASE;'
#orientdb-console 'CONNECT PLOCAL:db/component admin admin; REPAIR DATABASE;'
orientdb-console 'CONNECT PLOCAL:db/config admin admin; CHECK DATABASE;'
orientdb-console 'CONNECT PLOCAL:db/security admin admin; CHECK DATABASE;'
#orientdb-console 'CONNECT PLOCAL:db/OSystem admin admin; CONFIG; LIST CLASSES;' # XXX fails to connect. see https://groups.google.com/a/glists.sonatype.com/forum/#!topic/nexus-users/7dVofIwC5HM
Then start nexus.