nexus 以非交互方式配置初始存储库

nexus configure initial repositories non-interactively

我想为我们的 nexus 实例创建一个 docker,其中已经创建了正确的存储库、代理等。

灵感来自 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

现在我的问题是:是否有另一种非交互式配置存储库的方法?

对于jenkins,可以在/usr/share/jenkins/ref中放置一些默认配置,然后仅在第一次启动时使用;给你一个初始配置。我想知道 nexus 是否存在类似的东西?或者其他我不知道的方式?

我使用 python 来做类似的事情:

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'

我 post 的确切脚本(这里比所有那些转义引号更具可读性):

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)

我的案例中缺少的部分是 repositoryManager.update()。如票上所述:

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)