1

I would like to create a docker for our nexus instance with the correct repositories, proxies etc already created.

Inspired by this question I started using the script API to configure my repositories. The repositories configured through this API don't work like the ones configured manually though (how sad; especially if you imagine the trouble I went through to get the configuration done with the non-documented script API...). I have already filed a bug therefore if you really want to know the details: https://issues.sonatype.org/browse/NEXUS-19891

Now my question: is there another way to configure the repositories non-interactively?

For jenkins it is possible to put some default configuration in /usr/share/jenkins/ref which will then be used only at the first startup; to give you an initial configuration. I was wondering if something similar exists for nexus? Or some other way that I don't know about?

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • Regarding nexus, you can register groovy scripts that you will later call to do the work you expect. I maintain an ansible role which installs and provisions nexus where we use this feature (i.e. "self made API"). [See this example](https://github.com/ansible-ThoTeam/nexus3-oss/blob/master/files/groovy/create_repos_from_list.groovy). The expected data structure is `[{name: reponame, type: repotype, format: repoformat, blob_store: blobstorename, ...}, {...}]` See the script for more info on possible params if you are interested (and the role's doc at project root). Note: you issue is private – Zeitounator May 10 '19 at 16:03
  • @Zeitounator you are right; the issue was private; I didn't notice that. I pasted the whole content here in my question. – Chris Maes May 11 '19 at 19:44

1 Answers1

0

I use python to do something similar to this:

curl -X POST -u admin:admin123 --header 'Content-Type: application/json' http://localhost:8081/service/rest/v1/script -d '{"name":"test","type":"groovy","content":"repository.createYumProxy('\''test'\'', '\''http://repository:8080/'\'')"}'
curl -X POST -u admin:admin123 --header "Content-Type: text/plain" 'http://127.0.0.1:8081/service/rest/v1/script/test/run'

the exact script that I post (more readable here than with all those escaped quotes):

repository.createYumProxy('{name}', '{url}');
configuration = repository.repositoryManager.get('{name}').configuration.copy();
configuration.attributes['proxy'] = [
    remoteUrl : "{url}",
    contentMaxAge : 0,
    metadataMaxAge : 0
]
configuration.attributes['negativeCache'] = [
    timeToLive : 1.0
]
repository.repositoryManager.update(configuration)

The part that was missing in my case was the repositoryManager.update(). As quoted on the ticket:

I think the important item(s) missing from your script is that you are not updating the repositoryManager with the new (copied) configuration (which causes the repository to stop/start and therefore reload config)

Chris Maes
  • 35,025
  • 12
  • 111
  • 136