From 02426896a3ae9dc8e85555d94cea1605ba5f74f5 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Mon, 9 Dec 2024 08:40:47 +0000 Subject: [PATCH] use the nexus api to create the chocolatey nuget repositories --- README.md | 2 +- provision/provision-nexus.sh | 86 +++++++++++++++++++ .../src/main/groovy/provision.groovy | 11 --- 3 files changed, 87 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index bb9dccc..e7e8b4a 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ This will: * Create the `apt-hosted` repository. * Create the `npm-group`, `npm-hosted` and `npmjs.org-proxy` repositories. * Create the `powershell-group`, `powershell-hosted` and `powershellgallery.com-proxy` repositories. + * Create the `chocolatey-group`, `chocolatey-hosted` and `chocolatey.org-proxy` repositories. * Configure the NuGet `nuget-hosted` repository to accept pushing with an API key. * Configure Nexus through Groovy scripts. - * Create the `chocolatey-group`, `chocolatey-hosted` and `chocolatey.org-proxy` repositories. * Schedule a task to remove the old snapshots from the `maven-snapshots` repository. * Create users and a custom `deployer` role. * Setup an Active Directory LDAP user authentication source (when `config_authentication='ldap'` is set inside the `provision-nexus.sh` file). diff --git a/provision/provision-nexus.sh b/provision/provision-nexus.sh index 2cebec5..0baf97b 100644 --- a/provision/provision-nexus.sh +++ b/provision/provision-nexus.sh @@ -406,6 +406,92 @@ http \ } } EOF + + +# create the chocolatey-hosted nuget hosted repository. +# see https://help.sonatype.com/en/nuget-repositories.html +http \ + --check-status \ + --auth "$api_auth" \ + POST \ + https://$nexus_domain/service/rest/v1/repositories/nuget/hosted \ + <<'EOF' +{ + "name": "chocolatey-hosted", + "online": true, + "storage": { + "blobStoreName": "default", + "strictContentTypeValidation": true, + "writePolicy": "allow_once" + }, + "component": { + "proprietaryComponents": true + } +} +EOF + + +# create a chocolatey.org-proxy nuget proxy repository. +# see https://help.sonatype.com/en/nuget-repositories.html +http \ + --check-status \ + --auth "$api_auth" \ + POST \ + https://$nexus_domain/service/rest/v1/repositories/nuget/proxy \ + <<'EOF' +{ + "name": "chocolatey.org-proxy", + "online": true, + "storage": { + "blobStoreName": "default", + "strictContentTypeValidation": true + }, + "proxy": { + "remoteUrl": "https://chocolatey.org/api/v2/", + "contentMaxAge": 1440, + "metadataMaxAge": 1440 + }, + "nugetProxy": { + "queryCacheItemMaxAge": 3600, + "nugetVersion": "V2" + }, + "negativeCache": { + "enabled": true, + "timeToLive": 1440 + }, + "httpClient": { + "blocked": false, + "autoBlock": true + } +} +EOF + + +# create the chocolatey-group nuget group repository. +# see https://help.sonatype.com/en/nuget-repositories.html +http \ + --check-status \ + --auth "$api_auth" \ + POST \ + https://$nexus_domain/service/rest/v1/repositories/nuget/group \ + <<'EOF' +{ + "name": "chocolatey-group", + "online": true, + "storage": { + "blobStoreName": "default", + "strictContentTypeValidation": true + }, + "group": { + "memberNames": [ + "chocolatey-hosted", + "chocolatey.org-proxy" + ] + } +} +EOF + + # configure nexus ldap with a groovy script. if [ "$config_authentication" = 'ldap' ]; then bash /vagrant/provision/execute-provision-ldap.groovy-script.sh diff --git a/provision/provision-nexus/src/main/groovy/provision.groovy b/provision/provision-nexus/src/main/groovy/provision.groovy index 7997a01..fe2f608 100644 --- a/provision/provision-nexus/src/main/groovy/provision.groovy +++ b/provision/provision-nexus/src/main/groovy/provision.groovy @@ -26,17 +26,6 @@ capabilityRegistry.all.findAll {it.context().type().toString().startsWith("Outre //]) -// create a chocolatey repository backed by the default blob store. -repository.createNugetHosted("chocolatey-hosted", "default", true, WritePolicy.ALLOW_ONCE) -// create a chocolatey proxy repository backed by the default blob store. -// see https://help.sonatype.com/repomanager3/formats/nuget-repositories -config = repository.createNugetProxy("chocolatey.org-proxy", "https://chocolatey.org/api/v2/", "default").configuration.copy() -config.attributes.nugetProxy.nugetVersion = "V2" -repository.repositoryManager.update(config) -// create a chocolatey group repository that merges the chocolatey-host and chocolatey.org-proxy together. -repository.createNugetGroup("chocolatey-group", ["chocolatey-hosted", "chocolatey.org-proxy"], "default") - - // create a docker registry repository backed by the default blob store. repository.createDockerHosted("docker-hosted", 6003, null, "default", true, true, WritePolicy.ALLOW, true) // create a docker proxy repository backed by the default blob store.