Hi all!
First post here. I’m a big fan of Nexus. I’m running the sonatype/nexus3:latest docker image with great success. I love the splash screen! I love most things about it to be honest. I just wish there was a dark mode but I digress…
Last night I was inspired to script the creation of my nexus instance because of how heavily I rely on it. I’d like to be able to easily recreate my setup if ever needed. Here’s an example of what I’ve accomplished so far:
First, I used the Administration > System > API tab to gather the required JSON structure for each repo type, and subbed in my values.
Next, I wrote a simple Bash script to execute the POSTs via curl.
#!/bin/bash
# Nexus Instance & Credentials
IP="192.168.1.10"
PORT="8081"
USERNAME="admin"
PASSWORD="WebGUIPasswordHere"
# APT Repo Proxies
curl -u ${USERNAME}:${PASSWORD} -X POST "http://${IP}:${PORT}/service/rest/v1/repositories/apt/proxy" -H "Content-Type: application/json" -d @apt/proxy/apt-repo.json
curl -u ${USERNAME}:${PASSWORD} -X POST "http://${IP}:${PORT}/service/rest/v1/repositories/apt/proxy" -H "Content-Type: application/json" -d @apt/proxy/apt-salt.json
# Docker Hub Proxy
curl -u ${USERNAME}:${PASSWORD} -X POST "http://${IP}:${PORT}/service/rest/v1/repositories/docker/proxy" -H "Content-Type: application/json" -d @docker/proxy/docker.json
# Raw HTTP filesystems
curl -u ${USERNAME}:${PASSWORD} -X POST "http://${IP}:${PORT}/service/rest/v1/repositories/raw/hosted" -H "Content-Type: application/json" -d @raw/hosted/cloud-init.json
curl -u ${USERNAME}:${PASSWORD} -X POST "http://${IP}:${PORT}/service/rest/v1/repositories/raw/hosted" -H "Content-Type: application/json" -d @raw/hosted/vagrant.json
# Proxy of Saltstack Raw HTTP filesystem
curl -u ${USERNAME}:${PASSWORD} -X POST "http://${IP}:${PORT}/service/rest/v1/repositories/raw/proxy" -H "Content-Type: application/json" -d @raw/proxy/saltstack.json
# YUM/DNF Repo Proxies
curl -u ${USERNAME}:${PASSWORD} -X POST "http://${IP}:${PORT}/service/rest/v1/repositories/yum/proxy" -H "Content-Type: application/json" -d @yum/proxy/yum-repo.json
curl -u ${USERNAME}:${PASSWORD} -X POST "http://${IP}:${PORT}/service/rest/v1/repositories/yum/proxy" -H "Content-Type: application/json" -d @yum/proxy/yum-epel.json
curl -u ${USERNAME}:${PASSWORD} -X POST "http://${IP}:${PORT}/service/rest/v1/repositories/yum/proxy" -H "Content-Type: application/json" -d @yum/proxy/yum-salt.json
The above works great, with one caveat. Using the above apt-repo proxy repository as the example, all of the settings that would happily be blank if configured in the Web GUI (e.g. HTTP authentication) have “string” entered for username, password, etc. I tried “” but it complained that they cannot be blank.
Can someone point me in the right direction for how to use the JSON / POST to have these set up in a similar way to how they are when I point-and-click?
Many thanks, and keep up the great work.
-static